首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >猪:Twitter情绪分析

猪:Twitter情绪分析
EN

Stack Overflow用户
提问于 2016-09-20 05:04:38
回答 3查看 605关注 0票数 1

我正在尝试实现对twitter情绪的分析,我需要获取所有的正面和负面信息,并将它们存储在特定的文本文件中。

sample.json

代码语言:javascript
复制
{"id": 252479809098223616, "created_at": "Wed Apr 12 08:23:20 +0000 2016", "text": "google is a good company", "user_id": 450990391}{"id": 252479809098223616, "created_at": "Wed Apr 12 08:23:20 +0000 2016", "text": "facebook is a bad company","user_id": 450990391}

dictionary.text有所有的正负词列表

代码语言:javascript
复制
weaksubj    1   bad     adj     n   negative
strongsubj  1   good    adj     n   positive

猪脚本:-

代码语言:javascript
复制
tweets = load 'new.json' using JsonLoader('id:chararray,text:chararray,user_id:chararray,created_at:chararray');

dictionary = load 'dictionary.text' AS (type:chararray,length:chararray,word:chararray,pos:chararray,stemmed:chararray,polarity:chararray);

words = foreach tweets generate FLATTEN( TOKENIZE(text) ) AS word,id,text,user_id,created_at;

sentiment = join words by word left outer, dictionary by word;

senti2 = foreach sentiment generate words::id as id,words::created_at as created_at,words::text as text,words::user_id as user_id,dictionary::polarity as polarity;

res = FILTER senti2 BY polarity MATCHES '.*possitive.*';

描述res:-

代码语言:javascript
复制
res: {id: chararray,created_at: chararray,text: chararray,user_id: chararray,polarity: chararray}

但是当我转储res时,我没有看到任何输出,但是它执行得很好,没有任何错误。

我在这里做的是什么错误。

请给我建议。

Mohan.V

EN

回答 3

Stack Overflow用户

发布于 2016-09-20 08:02:48

我在这里看到两个错误

  • 1:第2行-当您转储字典时,您将看到第1列中的所有记录,其余的列显示为空。

解决方案:使用PigStorage()指定适当的分隔符;

代码语言:javascript
复制
 dictionary = load 'dictionary.text' AS     (type:chararray,length:chararray,word:chararray,pos:chararray,stemmed:chararray,polarity:chararray);

DUMP dictionary;
(weaksubj    1   bad     adj     n   negative,,,,,)
(strongsubj  1   good    adj     n   positive,,,,,)

第二个错误:第6行:更正正数的拼写!使用类似的东西

代码语言:javascript
复制
res = FILTER senti2 BY UPPER(polarity) MATCHES '.*POSITIVE.*';
票数 0
EN

Stack Overflow用户

发布于 2016-10-07 23:44:50

我看到拼写错误:

代码语言:javascript
复制
res = FILTER senti2 BY polarity MATCHES '.*possitive.*';

不是'.*positive.*'吗?

票数 0
EN

Stack Overflow用户

发布于 2017-09-16 13:40:23

根据我的建议,您应该使用自定义的UDF来解决问题。现在你可以用大象-鸟-猪-4.1.jar,json-简单-1.1.1jar。另外,如果您想要查看这些示例,那么可以使用这些情感分析教程。如果你想要代码,那么你可以引用这些代码并按照教程和我的代码格式化你的代码,

代码语言:javascript
复制
REGISTER ‘/usr/local/elephant-bird-hadoop-compat-4.1.jar';
REGISTER '/ usr/local /elephant-bird-pig-4.1.jar';
REGISTER '/ usr/local /json-simple-1.1.1.jar’;
load_tweets = LOAD '/user/new.json' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS myMap;
extract_details = FOREACH load_tweets GENERATE myMap#'id' as id,myMap#'text' as text;
tokens = foreach extract_details generate id,text, FLATTEN(TOKENIZE(text)) As word;
dictionary = load '/user/dictionary.text' AS (type:chararray,length:chararray,word:chararray,pos:chararray,stemmed:chararray,polarity:chararray);
word_rating = join tokens by word left outer, dictionary by word using 'replicated’; describe word_rating;
rating = foreach word_rating generate tokens::id as id,tokens::text as text, dictionary::rating as rate;
word_group = group rating by (id,text);
avg_rate = foreach word_group generate group, AVG(rating.rate) as tweet_rating;
positive_tweets = filter avg_rate by tweet_rating>=0;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39586045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档