class Bm25::Validator
Public Class Methods
is_onechar?(word)
click to toggle source
@param [String] word @return [Boolean] return True if the word is one character
# File lib/bm25/validator.rb, line 24 def is_onechar?(word) return word.size == 1 end
is_stopword?(word)
click to toggle source
@param [String] word @return [Boolean] return True if the word is a stopword
# 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)
click to toggle source
@param [Object] mecab object @return [Boolean] return True if the mecab obj is noun
# 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