Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pluralizer for the dictionary added

  • Loading branch information...
commit a3f7f6df9333b5bc74ccafed139567dd16d54b1a 1 parent b11de2b
@vraja2 vraja2 authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/twitter-sentiment/parser/text_mood.rb
View
16 lib/twitter-sentiment/parser/text_mood.rb 100644 → 100755
@@ -1,4 +1,6 @@
require 'progressbar'
+require 'Linguistics'
+include Linguistics::EN
module TwitterSentiment
module Parser
@@ -39,12 +41,14 @@ def initialize file
else
raise ArgumentError, "Expected String or Symbol input for file"
end
- pb = ProgressBar.new "Dictionary", 2 # steps
+ pb = ProgressBar.new "Dictionary", 3 # steps
pb.format = Paint["[info] ", [50,50,50]] + "%-#{@title_width}s %3d%% "+Paint["%s",:blue]
generate_dictionary File.open(file, "r")
pb.inc
generate_opposites
pb.inc
+ generate_plurals
+ pb.inc
# done
pb.finish
end
@@ -76,6 +80,16 @@ def generate_opposites
@dict.merge!(notdict) {|key, oldval, newval| oldval } # collisions won't be overwritten
end
private :generate_opposites
+
+
+ def generate_plurals
+ plurals = {}
+ @dict.each do |word, score|
+ plurals[symbolize(plural(desymbolize(word)))] = score
+ end
+ @dict.merge!(plurals) {|key,oldval,newval| oldval }
+ end
+ private :generate_plurals
# Turn a potentially poorly-formatted "tweet-like" message into an array of
# words that would hopefully exist in a dictionary. This will never be perfect,
Please sign in to comment.
Something went wrong with that request. Please try again.