{"id":314,"date":"2018-11-01T04:35:52","date_gmt":"2018-11-01T04:35:52","guid":{"rendered":"https:\/\/spectdata.com\/?p=314"},"modified":"2020-12-15T22:22:42","modified_gmt":"2020-12-15T11:22:42","slug":"using-empath-to-analyze-movie-reviews","status":"publish","type":"post","link":"https:\/\/spectdata.com\/index.php\/2018\/11\/01\/using-empath-to-analyze-movie-reviews\/","title":{"rendered":"Using empath to analyze movie reviews"},"content":{"rendered":"<p>More and more businesses are now leveraging on their knowledge of what the customers want through feedback and reviews to improve their business processes. Thus, the ability to capture and understand the customers fast is now the real game among enterprises. A lot of tools were already being used by large companies to acquire and monitor customer sentiments.<\/p>\n<p>In this post, we will try to understand how Natural Language Processing (NLP) can be used to analyze languages, specifically on movie reviews, and how businesses can use it to analyze the change in behavior of consumer preferences. We would be using an open-source tool called Empath.<\/p>\n<p>Empath is a tool to analyze text across lexical categories similar to Linguistic Inquiry and Word count (LIWC) &#8211; commonly used by researchers. It &#8220;analyzes text across 200 built-in, pre-validated categories generated from common topics in the web&#8221; [1].&nbsp; It provides a numerical representation for each category as analyzed by content. It addresses the limitation of LIWC which only analyzes text across only 40 topics.<\/p>\n<p>We have managed to acquire compiled data of movie reviews from [2] which was first used by Pang and Lee in [3]. These are numerous film reviews from known film critic and personalities such as Dennis Schwartz, James Berardinelli, etc. that are pre-processed and stored in a .txt file format.<\/p>\n<p><strong>Prepare Data<\/strong><\/p>\n<p>We first load necessary libraries we need for our analysis and set up the list in which we will do the analysis on.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist93013671\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-data_prep-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"data_prep.py content, created by mfmakahiya on 05:23AM on November 14, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"data_prep.py\">\n        <tr>\n          <td id=\"file-data_prep-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-data_prep-py-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Load libraries<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-data_prep-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">import os<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-data_prep-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">import logging<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-data_prep-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">from empath import Empath<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-data_prep-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">import pandas as pd<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-data_prep-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-data_prep-py-LC7\" class=\"blob-code blob-code-inner js-file-line\"># Set up folder locations<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-data_prep-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">source_folder_path_list = []<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-data_prep-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">source_folder_path = &quot;C:\/Users\/Marriane\/Documents\/GitHub\/empath-on-movie-reviews\/data\/scale_whole_review.tar (with text)\/scale_whole_review\/scale_whole_review\/&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-data_prep-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">folder_list = [&quot;Dennis+Schwartz\/txt.parag&quot;, &quot;James+Berardinelli\/txt.parag&quot;, &quot;Scott+Renshaw\/txt.parag&quot;, &quot;Steve+Rhodes\/txt.parag&quot;]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-data_prep-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">for folder in folder_list:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-data_prep-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    folder_loc = source_folder_path + folder<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-data_prep-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">    source_folder_path_list.append(folder_loc)    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-data_prep-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">print(source_folder_path_list)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/32049bcd31d4df8b4140823944df2f39\/raw\/4f11bff2d66ef5106e27a6333a8fa9aefe88cffb\/data_prep.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/32049bcd31d4df8b4140823944df2f39#file-data_prep-py\" class=\"Link--inTextBlock\">\n          data_prep.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p><strong>Main Analysis<\/strong><\/p>\n<p>Then, we perform the operation on a for loop to analyze all the .txt files in one execution. Lastly, we store our data frame in a .csv file.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist93013714\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-perform-empath-on-text-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"perform empath on text.py content, created by mfmakahiya on 05:28AM on November 14, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"perform empath on text.py\">\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">if __name__ == &quot;__main__&quot;:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    lexicon = Empath()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    result = lexicon.analyze(&quot;the quick brown fox jumps over the lazy dog&quot;, normalize=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    df0 = pd.Series(result, name = &#39;KeyValue&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    logging.getLogger().setLevel(logging.INFO)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    col_names = df0.keys()  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    df = pd.DataFrame(columns=col_names)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    for folder in source_folder_path_list:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">        txt_list = []<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">        for file in os.listdir(folder):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">            if file.endswith(&quot;.txt&quot;):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">                txt_list.append(file)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">                <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">                for txt_i in txt_list:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">                    txt_file_name = txt_i<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">                    #logging_str = &quot;Coverting &quot; + txt_i<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">                    #logging.info(logging_str)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">                    txt_full_path = os.path.join(folder, txt_file_name)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">                    try:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">                        txt_file = open(txt_full_path, &#39;r&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">                        lines = txt_file.readlines()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">                        lexicon = Empath()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">                        result = lexicon.analyze(lines, normalize=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">                        new_result = pd.Series(result, name = txt_full_path)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">                        new_result.index.name = &#39;Key&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">                        new_result.reset_index()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">                        df = df.append(new_result)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">                        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">                        logging.info(txt_i, &quot; succesfully analyzed&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">                    except:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">                        logging.info(txt_i + &quot; open failed&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">                   <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">    df = df.dropna()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">    # Clean the data frame<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;Details&#39;] = df.index<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;Reviewer&#39;] = df[&#39;Details&#39;].str.split(&quot;\/&quot;).str[11]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;Text file&#39;] = df[&#39;Details&#39;].str.split(&quot;\/&quot;).str[12]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC47\" class=\"blob-code blob-code-inner js-file-line\">    df = df.set_index([&#39;Reviewer&#39;, &#39;Text file&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">    df = df.drop([&#39;Details&#39;], axis = 1)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-perform-empath-on-text-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-perform-empath-on-text-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    df.to_csv(&#39;.\/data\/output\/Empath-on-movie-reviews_results.csv&#39;, sep=&#39;,&#39;, encoding=&#39;utf-8&#39;)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/fb69ad447f4d520cfe1bb992eddb096f\/raw\/1fa301e8a267bff8b7c9cea519a1f8ba23e167e2\/perform%20empath%20on%20text.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/fb69ad447f4d520cfe1bb992eddb096f#file-perform-empath-on-text-py\" class=\"Link--inTextBlock\">\n          perform empath on text.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p><strong>Examine the Data<\/strong><\/p>\n<p>It is probably a bit overwhelming to look at all the numbers obtained from those numerous reviews examined. Perhaps, why don&#8217;t we have a closer look on one of the examples we just had. Examining the results of one of the reviews we looked at by Dennis Schwartz, it states that<\/p>\n<p>&#8220;&#8230;<em>This is an obscure Bela Lugosi film and it&#8217;s not bad. Ellis is the dame with class. She sings the happy tune &#8216;Bluebirds on wallpaper decorating our dreams.&#8217; Bela&#8217;s the bad guy with a foreign accent. His fans will love him here, as this film has been restored recently and is now watchable.<\/em>&#8220;<\/p>\n<p>This is a review on the film &#8216;Postal inspector&#8217; last 2001. See full review <a href=\"http:\/\/homepages.sover.net\/~ozus\/postalinspector.htm\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. The review circulates on what the characters do to live and what they do to survive their own circumstances. With that, the result of applying empath is summarized below.<\/p>\n<p><\/p>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"358\" src=\"https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-1024x358.png\" alt=\"\" class=\"wp-image-567\" srcset=\"https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-1024x358.png 1024w, https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-300x105.png 300w, https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-768x269.png 768w, https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-648x227.png 648w, https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1-549x192.png 549w, https:\/\/spectdata.com\/wp-content\/uploads\/2019\/05\/postal-inspector-28308-1.png 1440w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Bar plot of empath results in Schwartz&#8217; movie review of Postal Inspector<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Based on the chart above, occupation, business, music and listen are the top 4 categories found after analysing the text using empath. Now, let\u2019s try to go back to the text and check what could have probably contributed to the high scores. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, occupation. If we are to go back to the full review and get some key words which might have resulted to a high empath score on occupation, we will find phrases like <em>good work<\/em>, <em>job<\/em>, and <em>works for the post office<\/em>. For business, things like<em> shady owner of a prominent nightclub<\/em>. Lastly, for music and listen, we have <em>nightclub singer<\/em>,  <em>sing to the passengers<\/em>, and <em>sing at the nightclub.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There you go! You can now start examining your own texts and see how it&#8217;s interpreted when applied with empath.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>References<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Fast, E., Chen, B., Bernstein, M.S. (2016). Empath: Understanding Topic Signals in Large-Scale Text.  Proceedings of the 2016 CHI Conference on Human Factors in Computing Systems. pp. 4647-4657. USA CA, San Jose.  DOI: <a rel=\"noreferrer noopener\" target=\"_blank\" href=\"http:\/\/dx.doi.org\/10.1145\/2858036.2858535\">http:\/\/dx.doi.org\/10.1145\/2858036.2858535<\/a>.<\/li><li>Movie Review Data. <a href=\"http:\/\/www.cs.cornell.edu\/people\/pabo\/movie-review-data\/\">www.cs.cornell.edu\/people\/pabo\/movie-review-data\/<\/a> . Accessed on November 21, 2018.<\/li><li>Bo Pang and Lillian Lee. Seeing Stars: Exploiting class relationships for sentiment categorization with respect to rating scales. <em>Proceedings of ACL. <\/em>2005.<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>More and more businesses are now leveraging on their knowledge of what the customers want through feedback and reviews to improve their business processes. Thus, the ability to capture and understand the customers fast is now the real game among enterprises. A lot of tools were already being used by large companies to acquire and &hellip; <a href=\"https:\/\/spectdata.com\/index.php\/2018\/11\/01\/using-empath-to-analyze-movie-reviews\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using empath to analyze movie reviews<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":573,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5],"tags":[],"class_list":["post-314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9PSm6-54","jetpack_featured_media_url":"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/11\/cinema-1241422_1280s.jpg","_links":{"self":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":31,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions\/571"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/media\/573"}],"wp:attachment":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}