similar_text 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.markdown +8 -4
- data/ext/similar_text/similar_text.c +19 -9
- data/lib/similar_text.rb +0 -4
- data/lib/similar_text/version.rb +2 -2
- data/similar_text.gemspec +2 -2
- data/test/similar_text_test.rb +3 -3
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/README.markdown
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
Ruby similar_text
|
2
2
|
=================
|
3
3
|
|
4
|
-
Port of PHP similar_text function to Ruby, built as a native extension.
|
4
|
+
Calculate the similarity between two strings. Port of PHP similar_text function to Ruby, built as a native extension.
|
5
|
+
|
6
|
+
Description from php.net:
|
7
|
+
|
8
|
+
This calculates the similarity between two strings as described in Oliver [1993]. Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string.
|
5
9
|
|
6
10
|
INSTALL
|
7
11
|
=======
|
@@ -17,8 +21,8 @@ Load extension:
|
|
17
21
|
|
18
22
|
require 'similar_text'
|
19
23
|
|
20
|
-
And use it by calling one of two methods (similar or
|
24
|
+
And use it by calling one of two methods (similar or similar_chars):
|
21
25
|
|
22
|
-
"Hello, World!".similar("Hello World!")
|
23
|
-
"Hello, World!".
|
26
|
+
"Hello, World!".similar("Hello World!") #=> 96.0
|
27
|
+
"Hello, World!".similar_chars("Hello World!") #=> 12
|
24
28
|
|
@@ -55,6 +55,13 @@ int similar_text(const char *txt1, const char *txt2, double *percent)
|
|
55
55
|
return sim;
|
56
56
|
}
|
57
57
|
|
58
|
+
/**
|
59
|
+
* Calculate the similarity between strings.
|
60
|
+
*
|
61
|
+
* "Hello, World!".similar("Hello, World!") #=> 100.0
|
62
|
+
*
|
63
|
+
* @return the percentage of similarity between two strings. Type of value Float from 0.0 to 100.0.
|
64
|
+
*/
|
58
65
|
static VALUE t_similar(VALUE str1, VALUE str2)
|
59
66
|
{
|
60
67
|
double percent;
|
@@ -64,24 +71,27 @@ static VALUE t_similar(VALUE str1, VALUE str2)
|
|
64
71
|
return rb_float_new(percent);
|
65
72
|
}
|
66
73
|
|
67
|
-
|
74
|
+
/**
|
75
|
+
* Calculate the similarity between strings.
|
76
|
+
*
|
77
|
+
* 'Hello WORLD!'.similar_chars 'Hello, World!' #=> 8
|
78
|
+
*
|
79
|
+
* @return number of matching chars between strings.
|
80
|
+
*/
|
81
|
+
static VALUE t_similar_chars(VALUE str1, VALUE str2)
|
68
82
|
{
|
69
83
|
double percent;
|
84
|
+
int sim;
|
70
85
|
|
71
|
-
similar_text(StringValueCStr(str1), StringValueCStr(str2), &percent);
|
86
|
+
sim = similar_text(StringValueCStr(str1), StringValueCStr(str2), &percent);
|
72
87
|
|
73
|
-
|
74
|
-
return Qtrue;
|
75
|
-
}
|
76
|
-
else {
|
77
|
-
return Qfalse;
|
78
|
-
}
|
88
|
+
return rb_int_new(sim);
|
79
89
|
}
|
80
90
|
|
81
91
|
void Init_similar_text()
|
82
92
|
{
|
83
93
|
rb_cString = rb_define_class("String", rb_cObject);
|
84
94
|
rb_define_method(rb_cString, "similar", t_similar, 1);
|
85
|
-
rb_define_method(rb_cString, "
|
95
|
+
rb_define_method(rb_cString, "similar_chars", t_similar_chars, 1);
|
86
96
|
}
|
87
97
|
|
data/lib/similar_text.rb
CHANGED
data/lib/similar_text/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module SimilarText
|
2
|
-
VERSION = "0.0.
|
1
|
+
module SimilarText #:nodoc:
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
end
|
data/similar_text.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Arthur Murauskas"]
|
9
9
|
s.email = ["arthur.murauskas@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/valcker/similar_text-ruby"
|
11
|
-
s.summary = %q{Port of PHP function similar_text to Ruby as a native extension. Adds methods similar and
|
12
|
-
s.description = %q{Port of PHP function similar_text to Ruby as a native extension. Adds methods similar and
|
11
|
+
s.summary = %q{Port of PHP function similar_text to Ruby as a native extension. Adds methods similar and similar_chars to core String class.}
|
12
|
+
s.description = %q{Port of PHP function similar_text to Ruby as a native extension. Adds methods similar and similar_chars to core String class.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "similar_text"
|
15
15
|
|
data/test/similar_text_test.rb
CHANGED
@@ -6,9 +6,9 @@ class SimilarTextTest < Test::Unit::TestCase
|
|
6
6
|
assert_equal(96.0, "Hello, World!".similar("Hello World!"))
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
assert_equal(
|
11
|
-
assert_equal(
|
9
|
+
def test_similar_chars
|
10
|
+
assert_equal(13, "Hello, World!".similar_chars("Hello, World!"))
|
11
|
+
assert_equal(8, "Hello WORLD!".similar_chars("Hello, World!"))
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: similar_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-19 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Port of PHP function similar_text to Ruby as a native extension. Adds
|
15
|
-
methods similar and
|
15
|
+
methods similar and similar_chars to core String class.
|
16
16
|
email:
|
17
17
|
- arthur.murauskas@gmail.com
|
18
18
|
executables: []
|
@@ -59,5 +59,5 @@ rubygems_version: 1.8.6
|
|
59
59
|
signing_key:
|
60
60
|
specification_version: 3
|
61
61
|
summary: Port of PHP function similar_text to Ruby as a native extension. Adds methods
|
62
|
-
similar and
|
62
|
+
similar and similar_chars to core String class.
|
63
63
|
test_files: []
|