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
32 33 34 35 |
# File 'lib/vocabulary-chest.rb', line 32 def self.add_to_known_words word @known_file.puts(stem word) @known_file.flush end |
.add_to_unknown_words(word) ⇒ Object
37 38 39 40 |
# File 'lib/vocabulary-chest.rb', line 37 def self.add_to_unknown_words word @unknown_file.puts(stem word) @unknown_file.flush end |
.contains?(word) ⇒ Boolean
42 43 44 45 |
# File 'lib/vocabulary-chest.rb', line 42 def self.contains? word stemmed_word = stem word known_words.include?(stemmed_word) or unknown_words.include?(stemmed_word) end |
.is_known?(word) ⇒ Boolean
47 48 49 |
# File 'lib/vocabulary-chest.rb', line 47 def self.is_known? word known_words.include?(stem(word)) or sanitize(word).empty? or (sanitize(word) =~ /^[-\d]*$/) != nil end |
.known_words ⇒ Object
24 25 26 |
# File 'lib/vocabulary-chest.rb', line 24 def self.known_words @known_words ||= File.open(KNOWN_FILE,'r'){|f|f.readlines}.collect{|line| line.chomp} end |
.sanitize(word) ⇒ Object
55 56 57 |
# File 'lib/vocabulary-chest.rb', line 55 def self.sanitize word word.gsub(/[,\"\.:;()?!„“]/,"") end |
.stem(word) ⇒ Object
51 52 53 |
# File 'lib/vocabulary-chest.rb', line 51 def self.stem word @stemmer.stem(sanitize word).downcase end |
.unknown_words ⇒ Object
28 29 30 |
# File 'lib/vocabulary-chest.rb', line 28 def self.unknown_words @unknown_words ||= File.open(UNKNOWN_FILE,'r'){|f|f.readlines}.collect{|line| line.chomp} end |