Class: Amatch::Sellers

Inherits:
Object
  • Object
show all
Defined in:
ext/amatch_ext.c,
ext/amatch_ext.c

Overview

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.

Instance Method Summary collapse

Constructor Details

#new(pattern) ⇒ Object

Creates a new Amatch::Sellers instance from pattern, with all weights initially set to 1.0.



964
965
966
967
968
969
970
# File 'ext/amatch_ext.c', line 964

static VALUE rb_Sellers_initialize(VALUE self, VALUE pattern)
{
    GET_STRUCT(Sellers)
    Sellers_pattern_set(amatch, pattern);
    Sellers_reset_weights(amatch);
    return self;
}

Instance Method Details

#deletionObject

call-seq: deletion -> weight

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

#deletion=Object

call-seq: 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.

#insertionObject

call-seq: insertion -> weight

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

#insertion=Object

call-seq: 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.

#matchObject

#patternObject

call-seq: pattern -> pattern string

Returns the current pattern string of this instance.

#pattern=Object

call-seq: pattern=(pattern)

Sets the current pattern string of this instance to pattern.

#reset_weightsObject

#search(strings) ⇒ Object

searches Sellers#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.



1033
1034
1035
1036
1037
# File 'ext/amatch_ext.c', line 1033

static VALUE rb_Sellers_search(VALUE self, VALUE strings)
{                                                                            
    GET_STRUCT(Sellers)
    return Sellers_iterate_strings(amatch, strings, Sellers_search);
}

#similar(strings) ⇒ Object

Uses this Amatch::Sellers instance to match Amatch::Sellers#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.



1018
1019
1020
1021
1022
# File 'ext/amatch_ext.c', line 1018

static VALUE rb_Sellers_similar(VALUE self, VALUE strings)
{                                                                            
    GET_STRUCT(Sellers)
    return Sellers_iterate_strings(amatch, strings, Sellers_similar);
}

#substitutionObject

call-seq: substitution -> weight

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

#substitution=Object

call-seq: 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.