Class: Amatch::Sellers
- Inherits:
-
Object
- Object
- Amatch::Sellers
- 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
-
#deletion ⇒ Object
call-seq: deletion -> weight.
-
#deletion= ⇒ Object
call-seq: deletion=(weight).
-
#new(pattern) ⇒ Object
constructor
Creates a new Amatch::Sellers instance from
pattern, with all weights initially set to 1.0. -
#insertion ⇒ Object
call-seq: insertion -> weight.
-
#insertion= ⇒ Object
call-seq: insertion=(weight).
- #match ⇒ Object
-
#pattern ⇒ Object
call-seq: pattern -> pattern string.
-
#pattern= ⇒ Object
call-seq: pattern=(pattern).
- #reset_weights ⇒ Object
-
#search(strings) ⇒ Object
searches Sellers#pattern in
stringsand returns the edit distance (the sum of weighted character operations) as a Float value, by greedy trimming prefixes or postfixes of the match. -
#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. -
#substitution ⇒ Object
call-seq: substitution -> weight.
-
#substitution= ⇒ Object
call-seq: substitution=(weight).
Constructor Details
#new(pattern) ⇒ Object
Creates a new Amatch::Sellers instance from pattern, with all weights initially set to 1.0.
1179 1180 1181 1182 1183 1184 1185 |
# File 'ext/amatch_ext.c', line 1179 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
#deletion ⇒ Object
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.
#insertion ⇒ Object
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.
#match ⇒ Object
#pattern ⇒ Object
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.
#reset_weights ⇒ Object
#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.
1248 1249 1250 1251 1252 |
# File 'ext/amatch_ext.c', line 1248 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.
1233 1234 1235 1236 1237 |
# File 'ext/amatch_ext.c', line 1233 static VALUE rb_Sellers_similar(VALUE self, VALUE strings) { GET_STRUCT(Sellers) return Sellers_iterate_strings(amatch, strings, Sellers_similar); } |
#substitution ⇒ Object
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.