Class: Search::Simple::Dictionary
- Inherits:
-
Object
- Object
- Search::Simple::Dictionary
- Defined in:
- lib/search/simple/dictionary.rb
Constant Summary collapse
- STOP_WORDS =
{ "a" => 1, "again" => 1, "all" => 1, "along" => 1, "also" => 1, "an" => 1, "and" => 1, "arialhelvetica" => 1, "as" => 1, "at" => 1, "but" => 1, "by" => 1, "came" => 1, "can" => 1, "cant" => 1, "couldnt" => 1, "did" => 1, "didn" => 1, "didnt" => 1, "do" => 1, "doesnt" => 1, "dont" => 1, "entrytitledetail" => 1, "ever" => 1, "first" => 1, "fontvariant" => 1, "from" => 1, "have" => 1, "her" => 1, "here" => 1, "him" => 1, "how" => 1, "i" => 1, "if" => 1, "in" => 1, "into" => 1, "is" => 1, "isnt" => 1, "it" => 1, "itll" => 1, "just" => 1, "last" => 1, "least" => 1, "like" => 1, "most" => 1, "my" => 1, "new" => 1, "no" => 1, "not" => 1, "now" => 1, "of" => 1, "on" => 1, "or" => 1, "should" => 1, "sidebartitl" => 1, "sinc" => 1, "so" => 1, "some" => 1, "textdecoration" => 1, "th" => 1, "than" => 1, "that" => 1, "the" => 1, "their" => 1, "then" => 1, "those" => 1, "to" => 1, "told" => 1, "too" => 1, "true" => 1, "try" => 1, "until" => 1, "url" => 1, "us" => 1, "were" => 1, "when" => 1, "whether" => 1, "while" => 1, "with" => 1, "within" => 1, "yes" => 1, "you" => 1, "youll" => 1, }
Instance Method Summary collapse
- #add_word(word) ⇒ Object
- #dump ⇒ Object
- #find(word) ⇒ Object
-
#initialize ⇒ Dictionary
constructor
A new instance of Dictionary.
- #size ⇒ Object
Constructor Details
#initialize ⇒ Dictionary
Returns a new instance of Dictionary.
94 95 96 |
# File 'lib/search/simple/dictionary.rb', line 94 def initialize @words = {} end |
Instance Method Details
#add_word(word) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/search/simple/dictionary.rb', line 98 def add_word(word) word = Stemmable::stem_porter(word) if STOP_WORDS[word] nil else @words[word] ||= @words.size end end |
#dump ⇒ Object
120 121 122 |
# File 'lib/search/simple/dictionary.rb', line 120 def dump puts @words.keys.sort end |
#find(word) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/search/simple/dictionary.rb', line 107 def find(word) word = Stemmable::stem_porter(word) if STOP_WORDS[word] nil else @words[word] end end |
#size ⇒ Object
116 117 118 |
# File 'lib/search/simple/dictionary.rb', line 116 def size @words.size end |