Class: Sastrawi::Stemmer::StemmerFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/sastrawi/stemmer/stemmer_factory.rb

Instance Method Summary collapse

Instance Method Details

#create_default_dictionary(is_dev = false) ⇒ Object



23
24
25
26
27
28
# File 'lib/sastrawi/stemmer/stemmer_factory.rb', line 23

def create_default_dictionary(is_dev = false)
  words = get_words(is_dev)
  dictionary = Sastrawi::Dictionary::ArrayDictionary.new(words)

  dictionary
end

#create_stemmer(is_dev = false) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/sastrawi/stemmer/stemmer_factory.rb', line 14

def create_stemmer(is_dev = false)
  stemmer = Sastrawi::Stemmer::Stemmer.new(create_default_dictionary(is_dev))

  cache_result = Sastrawi::Stemmer::Cache::ArrayCache.new
  cached_stemmer = Sastrawi::Stemmer::CachedStemmer.new(cache_result, stemmer)

  cached_stemmer
end

#get_words(is_dev = false) ⇒ Object



30
31
32
# File 'lib/sastrawi/stemmer/stemmer_factory.rb', line 30

def get_words(is_dev = false)
  get_words_from_file
end

#get_words_from_fileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sastrawi/stemmer/stemmer_factory.rb', line 34

def get_words_from_file
  root_directory = File.expand_path('../../../..', __FILE__)
  dictionary_file_path = File.join(root_directory, 'data/base-word.txt')

  dictionary_content = []
  File.open(dictionary_file_path, 'r') do |file|
    file.each do |line|
      dictionary_content.push(line.chomp)
    end
  end

  dictionary_content
end