Class: Amatch::DamerauLevenshtein

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

Overview

XXX The DamerauLevenshtein edit distance is defined as the minimal costs involved to transform one string into another by using three elementary operations: deletion, insertion and substitution of a character. To transform “water” into “wine”, for instance, you have to substitute “a” -> “i”: “witer”, “t” -> “n”: “winer” and delete “r”: “wine”. The edit distance between “water” and “wine” is 3, because you have to apply three operations. The edit distance between “wine” and “wine” is 0 of course: no operation is necessary for the transformation – they’re already the same string. It’s easy to see that more similar strings have smaller edit distances than strings that differ a lot.

Instance Method Summary collapse

Constructor Details

#new(pattern) ⇒ Object

XXX Creates a new Amatch::DamerauLevenshtein instance from pattern.



1024
1025
1026
1027
1028
1029
# File 'ext/amatch_ext.c', line 1024

static VALUE rb_DamerauLevenshtein_initialize(VALUE self, VALUE pattern)
{
    GET_STRUCT(General)
    General_pattern_set(amatch, pattern);
    return self;
}

Instance Method Details

#matchObject

#patternObject

call-seq: pattern -> pattern string

Returns the current pattern string of this Amatch::Sellers instance.

#pattern=Object

call-seq: pattern=(pattern)

Sets the current pattern string of this Amatch::Sellers instance to pattern.

#search(strings) ⇒ Object

XXX searches Amatch::DamerauLevenshtein#pattern in strings and returns the edit distance (the sum of character operations) as a Fixnum 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.



1089
1090
1091
1092
1093
# File 'ext/amatch_ext.c', line 1089

static VALUE rb_DamerauLevenshtein_search(VALUE self, VALUE strings)
{
    GET_STRUCT(General)
    return General_iterate_strings(amatch, strings, DamerauLevenshtein_search);
}

#similar(strings) ⇒ Object

XXX Uses this Amatch::DamerauLevenshtein instance to match Amatch::DamerauLevenshtein#pattern against strings, and compute a DamerauLevenshtein 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.



1058
1059
1060
1061
1062
# File 'ext/amatch_ext.c', line 1058

static VALUE rb_DamerauLevenshtein_similar(VALUE self, VALUE strings)
{
    GET_STRUCT(General)
    return General_iterate_strings(amatch, strings, DamerauLevenshtein_similar);
}