Class: VectorEmbed::StopWord
- Inherits:
-
Object
- Object
- VectorEmbed::StopWord
- Defined in:
- lib/vector_embed/stop_word.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply!(str) ⇒ Object
-
#initialize(raw_stop_word) ⇒ StopWord
constructor
A new instance of StopWord.
Constructor Details
#initialize(raw_stop_word) ⇒ StopWord
Returns a new instance of StopWord.
17 18 19 |
# File 'lib/vector_embed/stop_word.rb', line 17 def initialize(raw_stop_word) @pattern = /\s*\b#{raw_stop_word}\b\s*/i end |
Class Method Details
.remove(stop_words, str) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/vector_embed/stop_word.rb', line 6 def remove(stop_words, str) memo = str.dup stop_words.each do |stop_word| stop_word.apply! memo end memo.gsub! /\s+/, ' ' memo.strip! memo end |
Instance Method Details
#apply!(str) ⇒ Object
20 21 22 |
# File 'lib/vector_embed/stop_word.rb', line 20 def apply!(str) str.gsub! @pattern, ' ' end |