Class: Sastrawi::StopWordRemover::StopWordRemover

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dictionary) ⇒ StopWordRemover

Returns a new instance of StopWordRemover.



6
7
8
# File 'lib/sastrawi/stop_word_remover/stop_word_remover.rb', line 6

def initialize(dictionary)
  @dictionary = dictionary
end

Instance Attribute Details

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



4
5
6
# File 'lib/sastrawi/stop_word_remover/stop_word_remover.rb', line 4

def dictionary
  @dictionary
end

Instance Method Details

#remove(text) ⇒ Object

Remove stop words



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sastrawi/stop_word_remover/stop_word_remover.rb', line 13

def remove(text)
  words = text.split(' ')
  stop_words = []

  words.each do |word|
    unless @dictionary.contains?(word)
      stop_words.push(word)
    end
  end

  stop_words.join(' ')
end