Class: VectorEmbed::StopWord

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_embed/stop_word.rb

Class Method Summary collapse

Instance Method Summary collapse

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