Module: VocabularyChest
- Defined in:
- lib/vocabulary-chest.rb
Class Method Summary collapse
- .add_to_known_words(word) ⇒ Object
- .add_to_unknown_words(word) ⇒ Object
- .contains?(word) ⇒ Boolean
- .is_known?(word) ⇒ Boolean
- .known_words ⇒ Object
- .sanitize(word) ⇒ Object
- .stem(word) ⇒ Object
- .unknown_words ⇒ Object
Class Method Details
.add_to_known_words(word) ⇒ Object
21 22 23 24 |
# File 'lib/vocabulary-chest.rb', line 21 def self.add_to_known_words word @known_file.puts(stem word) @known_file.flush end |
.add_to_unknown_words(word) ⇒ Object
26 27 28 29 |
# File 'lib/vocabulary-chest.rb', line 26 def self.add_to_unknown_words word @unknown_file.puts(stem word) @unknown_file.flush end |
.contains?(word) ⇒ Boolean
31 32 33 34 |
# File 'lib/vocabulary-chest.rb', line 31 def self.contains? word stemmed_word = stem word known_words.include?(stemmed_word) or unknown_words.include?(stemmed_word) end |
.is_known?(word) ⇒ Boolean
36 37 38 |
# File 'lib/vocabulary-chest.rb', line 36 def self.is_known? word known_words.include?(stem(word)) or sanitize(word).empty? or (sanitize(word) =~ /^[-\d]*$/) != nil end |
.known_words ⇒ Object
13 14 15 |
# File 'lib/vocabulary-chest.rb', line 13 def self.known_words File.open(@known_file,'r'){|f|f.readlines}.collect{|line| line.chomp} end |
.sanitize(word) ⇒ Object
44 45 46 |
# File 'lib/vocabulary-chest.rb', line 44 def self.sanitize word word.gsub(/[,\"\.:;()?!„“]/,"") end |
.stem(word) ⇒ Object
40 41 42 |
# File 'lib/vocabulary-chest.rb', line 40 def self.stem word @stemmer.stem(sanitize word).downcase end |
.unknown_words ⇒ Object
17 18 19 |
# File 'lib/vocabulary-chest.rb', line 17 def self.unknown_words File.open(@unknown_file,'r'){|f|f.readlines}.collect{|line| line.chomp} end |