Class: Sastrawi::StopWordRemover::StopWordRemover
- Inherits:
-
Object
- Object
- Sastrawi::StopWordRemover::StopWordRemover
- Defined in:
- lib/sastrawi/stop_word_remover/stop_word_remover.rb
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
Instance Method Summary collapse
-
#initialize(dictionary) ⇒ StopWordRemover
constructor
A new instance of StopWordRemover.
-
#remove(text) ⇒ Object
Remove stop words.
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
#dictionary ⇒ Object (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 |