class Amatch::Sellers
The Sellers edit distance is very similar to the Levenshtein edit distance. The difference is, that you can also specify different weights for every operation to prefer special operations over others. This extension of the Sellers edit distance is also known under the names: Needleman-Wunsch distance.
Public Class Methods
Creates a new Amatch::Sellers instance from
pattern
, with all weights initially set to 1.0.
static VALUE rb_Sellers_initialize(VALUE self, VALUE pattern) { GET_STRUCT(Sellers) Sellers_pattern_set(amatch, pattern); Sellers_reset_weights(amatch); return self; }
Public Instance Methods
Returns the weight of the deletion operation, that is used to compute the Sellers distance.
Sets the weight of the deletion operation, that is used to compute the Sellers distance, to weight
. The
weight
should be a Float value >= 0.0.
Returns the weight of the insertion operation, that is used to compute the Sellers distance.
Sets the weight of the insertion operation, that is used to compute the Sellers distance, to weight
. The
weight
should be a Float value >= 0.0.
Uses this Amatch::Sellers instance to match #pattern against
strings
, while taking into account the given weights. It
returns the number of weighted character operations, the Sellers distance. strings
has to be
either a String or an Array of Strings. The
returned results
is either a Float or an Array of Floats
respectively.
static VALUE rb_Sellers_match(VALUE self, VALUE strings) { GET_STRUCT(Sellers) return Sellers_iterate_strings(amatch, strings, Sellers_match); }
Returns the current pattern string of this instance.
Sets the current pattern string of this instance to pattern
.
Resets all weights (substitution, deletion, and insertion) to 1.0.
static VALUE rb_Sellers_reset_weights(VALUE self) { GET_STRUCT(Sellers) Sellers_reset_weights(amatch); return self; }
searches #pattern in
strings
and returns the edit distance (the sum of weighted
character operations) as a Float value, by greedy trimming prefixes or
postfixes of the match. strings
has to be either a String or an Array of Strings. The returned
results
is either a Float or an Array of Floats respectively.
static VALUE rb_Sellers_search(VALUE self, VALUE strings) { GET_STRUCT(Sellers) return Sellers_iterate_strings(amatch, strings, Sellers_search); }
Uses this Amatch::Sellers instance to match #pattern against
strings
(taking into account the given weights), and compute a
Sellers distance metric number between 0.0 for
very unsimilar strings and 1.0 for an exact match. strings
has
to be either a String or an Array of Strings.
The returned results
is either a Fixnum or an Array of Fixnums
respectively.
static VALUE rb_Sellers_similar(VALUE self, VALUE strings) { GET_STRUCT(Sellers) return Sellers_iterate_strings(amatch, strings, Sellers_similar); }
Returns the weight of the substitution operation, that is used to compute the Sellers distance.
Sets the weight of the substitution operation, that is used to compute the
Sellers distance, to weight
. The
weight
should be a Float value >= 0.0.