Class: HintableLevenshtein
- Inherits:
-
Object
- Object
- HintableLevenshtein
show all
- Defined in:
- lib/hintable_levenshtein.rb,
lib/hintable_levenshtein/event.rb,
lib/hintable_levenshtein/rule_set.rb
Defined Under Namespace
Classes: Event, Position, Rule, RuleSet
Instance Method Summary
collapse
Constructor Details
#initialize(new_rule_set = nil, &block) ⇒ HintableLevenshtein
Returns a new instance of HintableLevenshtein.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/hintable_levenshtein.rb', line 6
def initialize(new_rule_set = nil, &block)
@rule_set = []
instance_eval(&block) if block
if new_rule_set
rule_set.concat(new_rule_set)
end
if rule_set.empty?
rule_set << RuleSet.new(1, Rule.delete)
rule_set << RuleSet.new(1, Rule.insert)
rule_set << RuleSet.new(1, Rule.substitute)
end
end
|
Instance Method Details
#delete(score, match) ⇒ Object
30
31
32
|
# File 'lib/hintable_levenshtein.rb', line 30
def delete(score, match)
rule_set << RuleSet.new(score, Rule.delete(match))
end
|
#distance(s, t) ⇒ Object
44
45
46
47
48
|
# File 'lib/hintable_levenshtein.rb', line 44
def distance(s, t)
matrix = levenshtein_matrix(s, t)
steps = calculate_steps(s, t, matrix)
calculate_score(steps)
end
|
#insert(score, match) ⇒ Object
34
35
36
|
# File 'lib/hintable_levenshtein.rb', line 34
def insert(score, match)
rule_set << RuleSet.new(score, Rule.insert(match))
end
|
#largest_rule_size ⇒ Object
26
27
28
|
# File 'lib/hintable_levenshtein.rb', line 26
def largest_rule_size
rule_set_sizes.first
end
|
#rule_set_sizes ⇒ Object
22
23
24
|
# File 'lib/hintable_levenshtein.rb', line 22
def rule_set_sizes
@rule_set_sizes ||= rule_set.collect{|r| r.rules.size}.uniq.sort.reverse
end
|
#substitute(score, match) ⇒ Object
38
39
40
|
# File 'lib/hintable_levenshtein.rb', line 38
def substitute(score, match)
rule_set << RuleSet.new(score, Rule.substitute(match))
end
|