amatch 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/Rakefile +2 -5
- data/VERSION +1 -1
- data/bin/agrep.rb +11 -15
- metadata +43 -47
- data/InstalledFiles +0 -5
- data/config.save +0 -12
- data/ext/amatch.bundle +0 -0
- data/foo.rb +0 -9
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# vim: set et sw=2 ts=2:
|
3
2
|
require 'rake/clean'
|
4
3
|
require 'rake/testtask'
|
5
4
|
require 'rake/gempackagetask'
|
@@ -17,7 +16,7 @@ PKG_FILES.exclude(/^doc/)
|
|
17
16
|
task :default => :test
|
18
17
|
|
19
18
|
desc "Run unit tests"
|
20
|
-
task
|
19
|
+
task :test => :compile do
|
21
20
|
cd 'tests' do
|
22
21
|
ruby %{-I../ext runner.rb}
|
23
22
|
end
|
@@ -43,7 +42,6 @@ desc "Removing generated files"
|
|
43
42
|
task :clean do
|
44
43
|
rm_rf 'doc'
|
45
44
|
cd 'ext' do
|
46
|
-
rm_f 'amatch.o', :verbose => true
|
47
45
|
ruby 'extconf.rb'
|
48
46
|
sh "make distclean" if File.exist?('Makefile')
|
49
47
|
end
|
@@ -111,4 +109,3 @@ Rake::GemPackageTask.new(spec) do |pkg|
|
|
111
109
|
end
|
112
110
|
|
113
111
|
task :release => [ :clean, :package ]
|
114
|
-
# vim: set et sw=2 ts=2:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/bin/agrep.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
+
# vim: set et sw=2 ts=2:
|
2
3
|
#
|
3
|
-
## $Id: agrep.rb,v 1.
|
4
|
+
## $Id: agrep.rb,v 1.5 2006/09/26 15:59:48 flori Exp $
|
4
5
|
#
|
5
6
|
|
6
7
|
require 'amatch'
|
7
8
|
require 'getoptlong'
|
8
9
|
|
9
10
|
def usage(msg, options)
|
10
|
-
|
11
|
+
puts msg, "Usage: #{File.basename($0)} [OPTIONS] PATTERN [FILE ...]", ""
|
11
12
|
options.each do |o|
|
12
13
|
puts " " + o[1] + ", " + o[0] + " " +
|
13
14
|
(o[2] == GetoptLong::REQUIRED_ARGUMENT ? 'ARGUMENT' : '')
|
@@ -16,18 +17,14 @@ def usage(msg, options)
|
|
16
17
|
exit 0
|
17
18
|
end
|
18
19
|
|
19
|
-
class
|
20
|
-
def
|
21
|
-
|
22
|
-
l_search(strings).map { |x| x / pattern.size }
|
23
|
-
else
|
24
|
-
l_search(strings) / pattern.size
|
25
|
-
end
|
20
|
+
class Amatch::Levenshtein
|
21
|
+
def search_relative(strings)
|
22
|
+
search(strings).to_f / pattern.size
|
26
23
|
end
|
27
24
|
end
|
28
25
|
|
29
26
|
$distance = 1
|
30
|
-
$mode = :
|
27
|
+
$mode = :search
|
31
28
|
begin
|
32
29
|
parser = GetoptLong.new
|
33
30
|
options = [
|
@@ -43,7 +40,7 @@ begin
|
|
43
40
|
when 'distance'
|
44
41
|
$distance = arg.to_f
|
45
42
|
when 'relative'
|
46
|
-
$mode = :
|
43
|
+
$mode = :search_relative
|
47
44
|
when 'verbose'
|
48
45
|
$verbose = 1
|
49
46
|
when 'help'
|
@@ -55,7 +52,7 @@ rescue
|
|
55
52
|
end
|
56
53
|
pattern = ARGV.shift or usage('Pattern needed!', options)
|
57
54
|
|
58
|
-
matcher =
|
55
|
+
matcher = Amatch::Levenshtein.new(pattern)
|
59
56
|
size = 0
|
60
57
|
start = Time.new
|
61
58
|
if ARGV.size > 0 then
|
@@ -64,12 +61,12 @@ if ARGV.size > 0 then
|
|
64
61
|
size += File.size(filename)
|
65
62
|
begin
|
66
63
|
File.open(filename, 'r').each_line do |line|
|
67
|
-
if matcher.__send__($mode, line)
|
64
|
+
if matcher.__send__($mode, line) <= $distance
|
68
65
|
puts "#{filename}:#{line}"
|
69
66
|
end
|
70
67
|
end
|
71
68
|
rescue
|
72
|
-
STDERR.
|
69
|
+
STDERR.puts "Failure at #{filename}: #{$!} => Skipping!"
|
73
70
|
end
|
74
71
|
end
|
75
72
|
else
|
@@ -84,4 +81,3 @@ time = Time.new - start
|
|
84
81
|
$verbose and STDERR.printf "%.3f secs running, scanned %.3f KB/s.\n",
|
85
82
|
time, size / time / 1024
|
86
83
|
exit 0
|
87
|
-
# vim: set et sw=2 ts=2:
|
metadata
CHANGED
@@ -3,73 +3,69 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: amatch
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date:
|
6
|
+
version: 0.2.3
|
7
|
+
date: 2006-09-26 00:00:00 +02:00
|
8
8
|
summary: Approximate String Matching library
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- ext
|
11
11
|
email: flori@ping.de
|
12
12
|
homepage: http://amatch.rubyforge.org
|
13
13
|
rubyforge_project: amatch
|
14
|
-
description:
|
15
|
-
Several algorithms can be used to do this, and it's also possible to compute a
|
16
|
-
similarity metric number between 0.0 and 1.0 for two given strings."
|
14
|
+
description: Amatch is a library for approximate string matching and searching in strings. Several algorithms can be used to do this, and it's also possible to compute a similarity metric number between 0.0 and 1.0 for two given strings.
|
17
15
|
autorequire: amatch
|
18
16
|
default_executable: agrep.rb
|
19
17
|
bindir: bin
|
20
18
|
has_rdoc: true
|
21
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
20
|
requirements:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
27
24
|
version:
|
28
25
|
platform: ruby
|
29
26
|
signing_key:
|
30
27
|
cert_chain:
|
31
28
|
authors:
|
32
|
-
|
29
|
+
- Florian Frank
|
33
30
|
files:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
- tests/test_levenshtein.rb
|
58
|
-
- tests/test_pair_distance.rb
|
59
|
-
- tests/runner.rb
|
60
|
-
- tests/test_longest_subsequence.rb
|
31
|
+
- bin
|
32
|
+
- VERSION
|
33
|
+
- tests
|
34
|
+
- GPL
|
35
|
+
- README.en
|
36
|
+
- install.rb
|
37
|
+
- ext
|
38
|
+
- Rakefile
|
39
|
+
- CHANGES
|
40
|
+
- bin/agrep.rb
|
41
|
+
- tests/runner.rb
|
42
|
+
- tests/test_longest_substring.rb
|
43
|
+
- tests/test_levenshtein.rb
|
44
|
+
- tests/test_hamming.rb
|
45
|
+
- tests/test_sellers.rb
|
46
|
+
- tests/test_pair_distance.rb
|
47
|
+
- tests/test_longest_subsequence.rb
|
48
|
+
- ext/tags
|
49
|
+
- ext/pair.h
|
50
|
+
- ext/extconf.rb
|
51
|
+
- ext/MANIFEST
|
52
|
+
- ext/pair.c
|
53
|
+
- ext/amatch.c
|
61
54
|
test_files:
|
62
|
-
|
55
|
+
- tests/runner.rb
|
63
56
|
rdoc_options:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
- --title
|
58
|
+
- Amatch -- Approximate Matching
|
59
|
+
- --main
|
60
|
+
- Amatch
|
61
|
+
- --line-numbers
|
69
62
|
extra_rdoc_files: []
|
63
|
+
|
70
64
|
executables:
|
71
|
-
|
65
|
+
- agrep.rb
|
72
66
|
extensions:
|
73
|
-
|
67
|
+
- ext/extconf.rb
|
74
68
|
requirements: []
|
75
|
-
|
69
|
+
|
70
|
+
dependencies: []
|
71
|
+
|
data/InstalledFiles
DELETED
data/config.save
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
bin-dir=$prefix/bin
|
2
|
-
site-ruby=$prefix/lib/ruby/site_ruby/1.8
|
3
|
-
prefix=/usr/local/stow/ruby
|
4
|
-
ruby-path=/usr/local/stow/ruby/bin/ruby
|
5
|
-
make-prog=make
|
6
|
-
rb-dir=$site-ruby
|
7
|
-
without-ext=no
|
8
|
-
ruby-prog=/usr/local/stow/ruby/bin/ruby
|
9
|
-
site-ruby-common=$prefix/lib/ruby/site_ruby
|
10
|
-
std-ruby=$prefix/lib/ruby/1.8
|
11
|
-
data-dir=$prefix/share
|
12
|
-
so-dir=$prefix/lib/ruby/site_ruby/1.8/i686-linux
|
data/ext/amatch.bundle
DELETED
Binary file
|
data/foo.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
$:.unshift 'ext'
|
2
|
-
|
3
|
-
require 'amatch'
|
4
|
-
|
5
|
-
a = "A" * "lost this fantasy, this fantasy, this fantasy, this fantasy, this fantasy, this fantasy\r\n\r\nGood love Neat work\r\n\r\nSuper job Fancy work\r\n\r\nPants job Cool work".size
|
6
|
-
b = "A" * "lost\r\n\r\nGood love Neat work\r\n\r\nSuper job Fancy work\r\n\r\nPants job Cool work".size
|
7
|
-
#p a.levenshtein_similar(b)
|
8
|
-
amatch = Amatch::Levenshtein.new(a)
|
9
|
-
amatch.similar(b)
|