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

new(pattern) click to toggle source

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

deletion → weight

Returns the weight of the deletion operation, that is used to compute the Sellers distance.

deletion=(weight)

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.

insertion → weight

Returns the weight of the insertion operation, that is used to compute the Sellers distance.

insertion=(weight)

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.

match(strings) → results click to toggle source

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);
}
pattern → pattern string

Returns the current pattern string of this instance.

pattern=(pattern)

Sets the current pattern string of this instance to pattern.

reset_weights() click to toggle source

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;
}
similar(strings) → results click to toggle source

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);
}
substitution → weight

Returns the weight of the substitution operation, that is used to compute the Sellers distance.

substitution=(weight)

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.