Module: Synt::Similar
- Extended by:
- Similar
- Included in:
- Similar
- Defined in:
- lib/synt/similar.rb
Defined Under Namespace
Modules: Jaccard, Tanimoto
Instance Method Summary
collapse
Instance Method Details
#compare(opts) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/synt/similar.rb', line 11
def compare opts
error 'no compare propery provided' unless opts[:compare]
error 'no to propery provided' unless opts[:to]
src = opts[:compare] || ''
cmp = opts[:to] || ''
algorithm = algorithms[(opts[:algorithm] || 'jaccard').to_sym]
n_start, n_end = ngram_range opts[:ngram]
src_t = normalize_ripper_tokens Synt::Parser.parse(src)
cmp_t = normalize_ripper_tokens Synt::Parser.parse(cmp)
a = generate_ngrams src_t, n_start, n_end
b = generate_ngrams cmp_t, n_start, n_end
sim = algorithm.compare a, b
sim.to_f.round 2
end
|