Class: VocabularyChest

Inherits:
Object
  • Object
show all
Defined in:
lib/vocabulary-chest.rb

Instance Method Summary collapse

Constructor Details

#initializeVocabularyChest

Returns a new instance of VocabularyChest.



9
10
11
12
13
# File 'lib/vocabulary-chest.rb', line 9

def initialize
  @known_file = File.open(TAUConfig.known_file,'a')
  @unknown_file = File.open(TAUConfig.unknown_file,'a')
  @stemmer= Lingua::Stemmer.new(:language => TAUConfig.language)
end

Instance Method Details

#add_to_known_words(word) ⇒ Object



23
24
25
26
# File 'lib/vocabulary-chest.rb', line 23

def add_to_known_words word
	@known_file.puts(stem word)
	@known_file.flush
end

#add_to_unknown_words(word) ⇒ Object



28
29
30
31
# File 'lib/vocabulary-chest.rb', line 28

def add_to_unknown_words word
	@unknown_file.puts(stem word)
	@unknown_file.flush
end

#contains?(word) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/vocabulary-chest.rb', line 33

def contains? word
	stemmed_word = stem word
	known_words.include?(stemmed_word) or unknown_words.include?(stemmed_word)
end

#is_known?(word) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/vocabulary-chest.rb', line 38

def is_known? word
	known_words.include?(stem(word)) or sanitize(word).empty? or (sanitize(word) =~ /^[-\d]*$/) != nil
end

#known_wordsObject



15
16
17
# File 'lib/vocabulary-chest.rb', line 15

def known_words
	File.open(@known_file,'r'){|f|f.readlines}.collect{|line| line.chomp}
end

#sanitize(word) ⇒ Object



46
47
48
# File 'lib/vocabulary-chest.rb', line 46

def sanitize word
	word.gsub(/[,\"\.:;()?!„“]/,"")
end

#stem(word) ⇒ Object



42
43
44
# File 'lib/vocabulary-chest.rb', line 42

def stem word
	@stemmer.stem(sanitize word).downcase
end

#unknown_wordsObject



19
20
21
# File 'lib/vocabulary-chest.rb', line 19

def unknown_words
	File.open(@unknown_file,'r'){|f|f.readlines}.collect{|line| line.chomp}
end