Class: Bm25::Validator
- Inherits:
-
Object
- Object
- Bm25::Validator
- Defined in:
- lib/bm25/validator.rb
Class Method Summary collapse
-
.is_onechar?(word) ⇒ Boolean
Return True if the word is one character.
-
.is_stopword?(word) ⇒ Boolean
Return True if the word is a stopword.
-
.validate_word(word_obj) ⇒ Boolean
Return True if the mecab obj is noun.
Class Method Details
.is_onechar?(word) ⇒ Boolean
Return True if the word is one character
24 25 26 |
# File 'lib/bm25/validator.rb', line 24 def is_onechar?(word) return word.size == 1 end |
.is_stopword?(word) ⇒ Boolean
Return True if the word is a stopword
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bm25/validator.rb', line 8 def is_stopword? (word) match = false stopword_path = File.join( File.dirname(__FILE__), 'stopword.txt' ) File.open(stopword_path, "r") do |f| f.each_line do |t| if t.chomp === word match = true break end end end return match end |
.validate_word(word_obj) ⇒ Boolean
Return True if the mecab obj is noun
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bm25/validator.rb', line 30 def validate_word(word_obj) n = word_obj if (n.is_bos? || n.is_eos?) || n.feature.scan(/名詞/).length === 0 || n.surface.match(/[\/\d]/) || self.is_stopword?(n.surface) || self.is_onechar?(n.surface) return true end return false end |