Class: FastFuzzy::Percolator
- Inherits:
-
Object
- Object
- FastFuzzy::Percolator
- Defined in:
- lib/fast_fuzzy/percolator.rb
Constant Summary collapse
- N =
>= 3 is necessary to wheight consecutiveness of words (ex “this car” => thi, his, is_, s_c, _ca, car)
4
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #<<(query) ⇒ Object
-
#initialize(options = {}) ⇒ Percolator
constructor
A new instance of Percolator.
- #percolate(str) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Percolator
Returns a new instance of Percolator.
10 11 12 13 14 15 16 17 18 |
# File 'lib/fast_fuzzy/percolator.rb', line 10 def initialize( = {}) @queries = .delete(:queries) || [] @analyzer_chain = .delete(:analyzer_chain) || Analyzer::STANDARD_CHAIN @index = Hash.new{|h, k| h[k] = []} @query_terms_count = [] build_index unless queries.empty? end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/fast_fuzzy/percolator.rb', line 7 def index @index end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
7 8 9 |
# File 'lib/fast_fuzzy/percolator.rb', line 7 def queries @queries end |
Instance Method Details
#<<(query) ⇒ Object
20 21 22 23 |
# File 'lib/fast_fuzzy/percolator.rb', line 20 def <<(query) @queries << query build_index end |
#percolate(str) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/fast_fuzzy/percolator.rb', line 25 def percolate(str) analyser = Analyzer.new(str, @analyzer_chain) terms_phrase = analyser.select{|term| term[1] == Lucene::ALPHANUM_TYPE}.map{|term| term[0]}.join(' ') terms_phrase = " #{terms_phrase} " grams = Ngram.generate(terms_phrase, N).uniq score(lookup(grams)) end |