Hashset fsdatainputstreamfi newbufferedreader stringline while line catch returnwords inthemapperstep tweet thetweet lengthofthetweetstoestimatethesentimentexpressedbyatweetonahashtag follows string integernegativecount integerwordscount for positivecount elseif wordscount integersentimentdifference sentimentdifference for word stats context inthereducerstep hashtaganddividebythetotalsizeofallthetweetsinwhichitoccurred extendsreducer throwsioexception doubletotaldifference doubletotalwords for string totalwords context
{
����HashSet<String>�words�=�new�HashSet<String>();����try�{
��������if�(fs.exists(wordsListPath))�{
������������FSDataInputStream�fi�=�fs.open(wordsListPath);
We’ll�use�these�in�the�reducer�to�calculate�an�overall�sentiment�ratio�weighted�by�the length�of�the�tweets�to�estimate�the�sentiment�expressed�by�a�tweet�on�a�hashtag,�as follows:
��������public�void�map(Object�key,�Text�value,�Context�context)�throws�IOException,�InterruptedException�{
������������String[]�words�=�value.toString().split("�")�;������������Integer�positiveCount�=�new�Integer(0);
������������Integer�negativeCount�=�new�Integer(0);
������������}
������������Integer�sentimentDifference�=�0;
������������if�(wordsCount�>�0)�{
��������������sentimentDifference�=�positiveCount�-�negativeCount;������������}After�running�the�preceding�code,�execute�HashTagSentiment�with�the�following command:
$�hadoop�jar�build/libs/mapreduce-example.jar�
com.learninghadoop2.mapreduce.HashTagSentiment�twitter.txt�output-sentiment�<positive�words>�<negative�words>