Class: Gamefic::Scanner::Strict
- Defined in:
- lib/gamefic/scanner/strict.rb
Overview
Strict token matching.
An entity will only match a word in a strict scan if the entire word matches one of the entity’s keywords.
Direct Known Subclasses
Constant Summary collapse
- NOISE =
%w[ a an the of some ].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Gamefic::Scanner::Base
Instance Method Details
#match_word(available, word) ⇒ Object
31 32 33 |
# File 'lib/gamefic/scanner/strict.rb', line 31 def match_word available, word available.select { |obj| (obj.keywords + obj.nuance.keywords).include?(word) } end |
#reduce_noise(entities, keywords) ⇒ Object
35 36 37 38 |
# File 'lib/gamefic/scanner/strict.rb', line 35 def reduce_noise entities, keywords noiseless = keywords - NOISE entities.reject { |entity| (noiseless - entity.nuance.keywords).empty? } end |
#scan ⇒ Result
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gamefic/scanner/strict.rb', line 16 def scan words = token.keywords available = selection.clone filtered = [] words.each_with_index do |word, idx| # @todo This might not be the best way to filter articles, but it works for now tested = %w[a an the].include?(word) ? available : match_word(available, word) return matched_result(reduce_noise(filtered, words[0, idx]), words[idx..].join(' ')) if tested.empty? filtered = tested available = filtered end matched_result(reduce_noise(filtered, words), '') end |