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

#initializeObject

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.



1072
1073
1074
1075
1076
# File 'ext/amatch_ext.c', line 1072

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.



1041
1042
1043
1044
1045
# File 'ext/amatch_ext.c', line 1041

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