{"id":251,"date":"2015-01-23T21:58:04","date_gmt":"2015-01-24T02:58:04","guid":{"rendered":"http:\/\/jkthinks.synology.me\/?p=1785"},"modified":"2020-09-04T22:58:35","modified_gmt":"2020-09-04T22:58:35","slug":"how-to-interpret-texts","status":"publish","type":"post","link":"https:\/\/www.jkthinks.com\/?p=251","title":{"rendered":"How to Interpret Texts"},"content":{"rendered":"<p>If you have data regardless of whether they are obtained from social media or other sources, the next step is to analyze the meaning of those data. However, it is difficult to interpret the natural language in terms of sentiment analysis. Fortunately, there are several ways to understand text data and even provide quantification.<\/p>\n<p>TextBlob is one of the simplest ways to process textual data and you can find more detail information <a href=\"http:\/\/textblob.readthedocs.org\/en\/dev\/\">here<\/a>. For instance, the library provides sentiment analysis of whether textual data are positive (positive value of polarity) or not (<a href=\"http:\/\/textblob.readthedocs.org\/en\/dev\/quickstart.html#sentiment-analysis\">Tutorial of Textblob<\/a>). Further information about sentiment analysis is <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sentiment_analysis\">here<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. Preparation<\/strong><br \/>\nIn order to analyze data, install the library as follows:<br \/>\n<code><\/code><\/p>\n<p><code>pip install -U textblob<br \/>\npython -m textblob.download_corpora<\/code><\/p>\n<p><strong><br \/>\n2. TextBlob<\/strong><\/p>\n<p>Given that data is saved as a text file, you need to convert text into an object. Also, import TextBlob.<\/p>\n<p><code>import os<br \/>\nimport json<br \/>\nfrom textblob import TextBlob<br \/>\n<\/code><\/p>\n<p>Read data from the file and create the new file which will include the result of text processing.<\/p>\n<p><code>f1 = open(\"name of data file\",\"r\")<br \/>\nf2 = open(\u201cname of output file\u201d, \u201cw\u201d)<br \/>\n<\/code><\/p>\n<p>Convert every line of f1 file to an object to interpret textual data. Also, only English sentences are set to be analyzed.<\/p>\n<p><code>for line in f1<br \/>\nobj = json.loads(line)<br \/>\nif tweetobj['lang']!=\"en\":<br \/>\ncontinue<br \/>\ntweet = obj['text'].strip()<br \/>\n<\/code><\/p>\n<p>Prior to applying TextBlob to objects, you might need to change or sort them out. Also, you have to define \u201cKeyword\u201d that you want to analyze before saving output. As you can see the following codes, the output of sentiment analysis consists of \u201cKeyword\u201d, polarity, and subjectivity of each tweet.<\/p>\n<p><code>tweetBlob = TextBlob(tweet)<br \/>\nout = Keyword+\",\"+str(tweetBlob.sentiment.polarity)+\",\"+str(tweetBlob.sentiment.subjectivity)<br \/>\nfp2.write(out+\"\\n\")<br \/>\nfp1.close()<br \/>\nfp2.close()<br \/>\n<\/code><\/p>\n<p>Now, you can see a new csv file in the directory that you designated like the one below. This will be used as the fundamental data for analysis in R.<\/p>\n<p><a href=\"http:\/\/jkthinks.synology.me\/wp-content\/uploads\/2015\/01\/output.jpg\"><img loading=\"lazy\" class=\" wp-image-1767 aligncenter\" src=\"http:\/\/jkthinks.synology.me\/wp-content\/uploads\/2015\/01\/output-1024x742.jpg\" alt=\"output\" width=\"600\" height=\"435\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have data regardless of whether they are obtained from social media or other sources, the next step is to analyze the meaning of those data. However, it is difficult to interpret the natural language in terms of sentiment analysis. Fortunately, there are several ways to understand text data and even provide quantification. TextBlob [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/posts\/251"}],"collection":[{"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=251"}],"version-history":[{"count":1,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=\/wp\/v2\/posts\/251\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jkthinks.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}