Class: Segments

Inherits:
Object
  • Object
show all
Defined in:
lib/my_segments.rb,
lib/my_segments/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(segments_lexicon) ⇒ Segments

Initializes with a segments lexicon



8
9
10
# File 'lib/my_segments.rb', line 8

def initialize(segments_lexicon)
  @lex = segments_lexicon
end

Instance Method Details

#for_term(query_term) ⇒ Object

Returns the query_term broken down into the substring rules (segments) we’ll use for searching



15
16
17
# File 'lib/my_segments.rb', line 15

def for_term(query_term)
  SubstringRules.for(query_term)
end

#suggest(query_term) ⇒ Object

Takes a query_term, generates the segments for that term, and searches for those segment matches in the lexicon.

Returns a ranked ordered list of candidates



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/my_segments.rb', line 24

def suggest(query_term)
  @qt = query_term
  @candidates = Candidates.new
  srs = for_term(@qt)

  srs.each do |seg|
    @lex.search(seg).each do |result|
      found(result)
    end
  end

  # Run substring rules
  # Check confidence
  #   Run ngrams
  # Return most confident candidate set
  return @candidates
end