Class: Amatch::LongestSubstring
- Inherits:
-
Object
- Object
- Amatch::LongestSubstring
- Defined in:
- ext/amatch_ext.c,
ext/amatch_ext.c
Overview
The longest common substring is the longest substring, that is part of two strings. A substring is contiguous, while a subsequence need not to be. The longer the common substring is, the more similar the two strings will be.
The longest common substring between ‘string’ and ‘string’ is ‘string’ again, thus the longest common substring length is 6. The longest common substring between ‘string’ and ‘storing’ is ‘ring’, thus the longest common substring length is 4.
Instance Method Summary collapse
-
#new(pattern) ⇒ Object
constructor
Creates a new Amatch::LongestSubstring instance from
pattern. - #match ⇒ Object
-
#pattern ⇒ Object
call-seq: pattern -> pattern string.
-
#pattern= ⇒ Object
call-seq: pattern=(pattern).
-
#similar(strings) ⇒ Object
Uses this Amatch::LongestSubstring instance to match Amatch::LongestSubstring#pattern against
strings, and compute a longest substring distance metric number between 0.0 for very unsimilar strings and 1.0 for an exact match.
Constructor Details
#new(pattern) ⇒ Object
Creates a new Amatch::LongestSubstring instance from pattern.
1546 1547 1548 1549 1550 1551 |
# File 'ext/amatch_ext.c', line 1546
static VALUE rb_LongestSubstring_initialize(VALUE self, VALUE pattern)
{
GET_STRUCT(General)
General_pattern_set(amatch, pattern);
return self;
}
|
Instance Method Details
#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.
#similar(strings) ⇒ Object
Uses this Amatch::LongestSubstring instance to match Amatch::LongestSubstring#pattern against strings, and compute a longest substring 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.
1581 1582 1583 1584 1585 |
# File 'ext/amatch_ext.c', line 1581
static VALUE rb_LongestSubstring_similar(VALUE self, VALUE strings)
{
GET_STRUCT(General)
return General_iterate_strings(amatch, strings, LongestSubstring_similar);
}
|