amatch 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2005-01-20 (0.1.4)
2
+ * Better argument handling in initialization method
3
+ * Minor changes in Rakefile and README.en
1
4
  2004-09-27 (0.1.3)
2
5
  * Rakefile and gem support added.
3
6
  2004-09-24 (0.1.2)
@@ -0,0 +1,5 @@
1
+ /usr/local/stow/ruby/bin/
2
+ /usr/local/stow/ruby/bin/CVS
3
+ /usr/local/stow/ruby/bin/CVS
4
+ /usr/local/stow/ruby/bin/CVS
5
+ /usr/local/stow/ruby/lib/ruby/site_ruby/1.8/i686-linux/.
data/README.en CHANGED
@@ -10,6 +10,10 @@ Just type into the command line as root:
10
10
  install.rb was taken from Minero Aoki's setup project:
11
11
  http://www.ruby-lang.org/en/raa-list.rhtml?name=setup.rb
12
12
 
13
+ If you have installed rake (rake.rubyforge.org), you can also type:
14
+
15
+ # rake install
16
+
13
17
  Documentation
14
18
  =============
15
19
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ task :default => [:test]
17
17
 
18
18
  desc "Run unit tests"
19
19
  task(:test => [:compile]) do
20
- ruby %{-Iext test.rb}
20
+ ruby %{-Iext tests/test.rb}
21
21
  end
22
22
 
23
23
  desc "Compiling library"
@@ -79,16 +79,17 @@ EOF
79
79
 
80
80
  s.has_rdoc = true
81
81
  #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
82
- s.rdoc_options <<
83
- '--title' << 'Rake -- Ruby Make' <<
84
- '--main' << 'README' <<
85
- '--line-numbers'
82
+ #s.rdoc_options <<
83
+ # '--title' << 'Rake -- Ruby Make' <<
84
+ # '--main' << 'README' <<
85
+ # '--line-numbers'
86
+ s.test_files << 'tests/test.rb'
86
87
 
87
88
  #### Author and project details.
88
89
 
89
90
  s.author = "Florian Frank"
90
91
  s.email = "flori@ping.de"
91
- s.homepage = "http://XXX"
92
+ s.homepage = "http://amatch.rubyforge.org"
92
93
  s.rubyforge_project = "amatch"
93
94
  end
94
95
 
@@ -96,4 +97,6 @@ Rake::GemPackageTask.new(spec) do |pkg|
96
97
  pkg.need_tar = true
97
98
  pkg.package_files += PKG_FILES
98
99
  end
100
+
101
+ task :release => [ :clean, :compile, :package ]
99
102
  # vim: set et sw=4 ts=4:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -4,19 +4,19 @@ Approximate Matching/Searching/Comparing
4
4
 
5
5
  SYNOPSIS
6
6
 
7
- require 'amatch'
7
+ require 'amatch'
8
8
 
9
- m = Amatch.new("pattern")
9
+ m = Amatch.new("pattern")
10
10
 
11
- p m.match("pattren")
12
- p m.match(["pattren","parent"])
13
- p m.matchr("pattren")
14
- p m.compare("pattren")
15
- p m.comparer("pattren")
16
- p m.compare("pattn")
17
- p m.comparer("pattn")
18
- p m.search("abcpattrendef")
19
- p m.searchr("abcpattrendef")
11
+ p m.match("pattren")
12
+ p m.match(["pattren","parent"])
13
+ p m.matchr("pattren")
14
+ p m.compare("pattren")
15
+ p m.comparer("pattren")
16
+ p m.compare("pattn")
17
+ p m.comparer("pattn")
18
+ p m.search("abcpattrendef")
19
+ p m.searchr("abcpattrendef")
20
20
 
21
21
  DESCRIPTION
22
22
 
@@ -52,15 +52,15 @@ is given it has to be set with Amatch#pattern before matching.
52
52
 
53
53
  METHODS
54
54
 
55
- - Amatch#pattern pattern string to match against
55
+ - Amatch#pattern pattern string to match against
56
56
 
57
- - Amatch#subw weight of one substitution (type Fixnum)
57
+ - Amatch#subw weight of one substitution (type Fixnum)
58
58
 
59
- - Amatch#delw weight of one deletion (type Fixnum)
59
+ - Amatch#delw weight of one deletion (type Fixnum)
60
60
 
61
- - Amatch#insw weight of one insertion (type Fixnum)
61
+ - Amatch#insw weight of one insertion (type Fixnum)
62
62
 
63
- - Amatch#resetw resets all weights to their default values (=1).
63
+ - Amatch#resetw resets all weights to their default values (=1).
64
64
 
65
65
  The following methods require the parameter 'strings'. This parameter can be
66
66
  of type String or Array of Strings. The method executes the matching operation
@@ -110,7 +110,7 @@ Florian Frank <flori@ping.de>
110
110
 
111
111
  COPYRIGHT
112
112
 
113
- Copyright (c) 2002 Florian Frank <flori@ping.de>
113
+ Copyright (c) 2002 Florian Frank <flori@ping.de>
114
114
 
115
115
  This is free software; you can redistribute it and/or modify it under the
116
116
  terms of the GNU General Public License Version 2 as published by the Free
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,138 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /usr/local/stow/ruby/lib/ruby/1.9/i686-linux
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ prefix = $(DESTDIR)/usr/local/stow/ruby
11
+ exec_prefix = $(prefix)
12
+ sitedir = $(prefix)/lib/ruby/site_ruby
13
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
14
+ builddir = $(ac_builddir)
15
+ archdir = $(rubylibdir)/$(arch)
16
+ sbindir = $(exec_prefix)/sbin
17
+ datadir = $(prefix)/share
18
+ includedir = $(prefix)/include
19
+ infodir = $(prefix)/info
20
+ top_builddir = $(ac_top_builddir)
21
+ sysconfdir = $(prefix)/etc
22
+ mandir = $(prefix)/man
23
+ libdir = $(exec_prefix)/lib
24
+ sharedstatedir = $(prefix)/com
25
+ oldincludedir = $(DESTDIR)/usr/include
26
+ sitearchdir = $(sitelibdir)/$(sitearch)
27
+ bindir = $(exec_prefix)/bin
28
+ localstatedir = $(prefix)/var
29
+ sitelibdir = $(sitedir)/$(ruby_version)
30
+ libexecdir = $(exec_prefix)/libexec
31
+
32
+ CC = gcc
33
+ LIBRUBY = $(LIBRUBY_SO)
34
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
35
+ LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L. -l$(RUBY_SO_NAME)
36
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
37
+
38
+ CFLAGS = -fPIC -g -O2 -fPIC
39
+ CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
40
+ CXXFLAGS = $(CFLAGS)
41
+ DLDFLAGS =
42
+ LDSHARED = $(CC) -shared
43
+ AR = ar
44
+ EXEEXT =
45
+
46
+ RUBY_INSTALL_NAME = ruby
47
+ RUBY_SO_NAME = ruby
48
+ arch = i686-linux
49
+ sitearch = i686-linux
50
+ ruby_version = 1.9
51
+ ruby = /usr/local/stow/ruby/bin/ruby
52
+ RUBY = $(ruby)
53
+ RM = rm -f
54
+ MAKEDIRS = $(RUBY) -run -e mkdir -- -p
55
+ INSTALL_PROG = $(RUBY) -run -e install -- -vpm 0755
56
+ INSTALL_DATA = $(RUBY) -run -e install -- -vpm 0644
57
+ COPY = $(RUBY) -run -e cp -- -v
58
+
59
+ #### End of system configuration section. ####
60
+
61
+
62
+ preload =
63
+ libpath = $(libdir)
64
+ LIBPATH = -L'$(libdir)' -Wl,-R'$(libdir)'
65
+ DEFFILE =
66
+
67
+ CLEANFILES =
68
+ DISTCLEANFILES =
69
+
70
+ extout =
71
+ extout_prefix =
72
+ target_prefix =
73
+ LOCAL_LIBS =
74
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lcrypt -lm -lc
75
+ OBJS = amatch.o
76
+ TARGET = amatch
77
+ DLLIB = $(TARGET).so
78
+ STATIC_LIB =
79
+
80
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
81
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
82
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
83
+
84
+ CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
85
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
86
+
87
+ all: $(DLLIB)
88
+ static: $(STATIC_LIB)
89
+
90
+ clean:
91
+ @$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
92
+
93
+ distclean: clean
94
+ @$(RM) Makefile extconf.h conftest.* mkmf.log
95
+ @$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
96
+
97
+ realclean: distclean
98
+ install: install-so install-rb
99
+
100
+ install-so: $(RUBYARCHDIR)
101
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
102
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
103
+ @$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
104
+ install-rb: $(RUBYLIBDIR)
105
+ $(RUBYARCHDIR):
106
+ @$(MAKEDIRS) $@
107
+ $(RUBYLIBDIR):
108
+ @$(MAKEDIRS) $@
109
+
110
+ site-install: site-install-so site-install-rb
111
+ site-install-so: install-so
112
+ site-install-rb: install-rb
113
+
114
+ .SUFFIXES: .c .cc .m .cxx .cpp .C .o
115
+
116
+ .cc.o:
117
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
118
+
119
+ .cpp.o:
120
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
121
+
122
+ .cxx.o:
123
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
124
+
125
+ .C.o:
126
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
127
+
128
+ .c.o:
129
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
130
+
131
+ $(DLLIB): $(OBJS)
132
+ @-$(RM) $@
133
+ @-$(MAKEDIRS) $(@D)
134
+ $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
135
+
136
+
137
+
138
+ $(OBJS): ruby.h defines.h
@@ -7,60 +7,60 @@ static VALUE cAmatch;
7
7
  */
8
8
 
9
9
  typedef struct {
10
- int *ptr;
11
- int len;
10
+ int *ptr;
11
+ int len;
12
12
  } vector;
13
13
 
14
14
  static vector *
15
15
  vector_new(len)
16
- int len;
16
+ int len;
17
17
  {
18
- vector *v;
19
- v = ALLOC(vector);
20
- if (v == NULL) rb_raise(rb_eNoMemError, "couldn't malloc vector");
21
- v->ptr = ALLOC_N(int, len + 1);
22
- if (v->ptr == NULL) rb_raise(rb_eNoMemError, "couldn't malloc vector data");
23
- v->len = len;
24
- return v;
18
+ vector *v;
19
+ v = ALLOC(vector);
20
+ if (v == NULL) rb_raise(rb_eNoMemError, "couldn't malloc vector");
21
+ v->ptr = ALLOC_N(int, len + 1);
22
+ if (v->ptr == NULL) rb_raise(rb_eNoMemError, "couldn't malloc vector data");
23
+ v->len = len;
24
+ return v;
25
25
  }
26
26
 
27
27
  static void
28
28
  vector_print(v)
29
- vector *v;
29
+ vector *v;
30
30
  {
31
- int i;
32
- for(i = 0; i < v->len; i++) printf("%d", v->ptr[i]);
33
- puts("");
31
+ int i;
32
+ for(i = 0; i < v->len; i++) printf("%d", v->ptr[i]);
33
+ puts("");
34
34
  }
35
35
 
36
36
  static void
37
37
  vector_destroy(v)
38
- vector *v;
38
+ vector *v;
39
39
  {
40
- xfree(v->ptr);
41
- xfree(v);
40
+ xfree(v->ptr);
41
+ xfree(v);
42
42
  }
43
43
 
44
44
  static int
45
45
  vector_minimum(v)
46
- vector *v;
46
+ vector *v;
47
47
  {
48
- int i;
49
- int min;
50
-
51
- if (v->len == 0) return -1;
52
- min = v->ptr[0];
53
- for (i = 1; i <= v->len; i++) {
54
- if (min > v->ptr[i]) min = v->ptr[i];
55
- }
56
- return min;
48
+ int i;
49
+ int min;
50
+
51
+ if (v->len == 0) return -1;
52
+ min = v->ptr[0];
53
+ for (i = 1; i <= v->len; i++) {
54
+ if (min > v->ptr[i]) min = v->ptr[i];
55
+ }
56
+ return min;
57
57
  }
58
58
 
59
59
  static int
60
60
  vector_last(v)
61
- vector *v;
61
+ vector *v;
62
62
  {
63
- return v->ptr[v->len];
63
+ return v->ptr[v->len];
64
64
  }
65
65
 
66
66
  /*
@@ -70,133 +70,133 @@ vector_last(v)
70
70
  enum { MATCH = 1, MATCHR, SEARCH, SEARCHR, COMPARE, COMPARER };
71
71
 
72
72
  static int weight2int(weight, name)
73
- VALUE weight;
74
- char *name;
73
+ VALUE weight;
74
+ char *name;
75
75
  {
76
- if (TYPE(weight) != T_FIXNUM) {
77
- rb_raise(rb_eTypeError,
78
- "value of weight %s has to be of type Fixnum (%s given)",
79
- "subw", NIL_P(weight) ? "NilClass" : rb_class2name(CLASS_OF(weight)));
80
- }
81
- return FIX2INT(weight);
76
+ if (TYPE(weight) != T_FIXNUM) {
77
+ rb_raise(rb_eTypeError,
78
+ "value of weight %s has to be of type Fixnum (%s given)",
79
+ "subw", NIL_P(weight) ? "NilClass" : rb_class2name(CLASS_OF(weight)));
80
+ }
81
+ return FIX2INT(weight);
82
82
  }
83
83
 
84
84
  static VALUE
85
85
  calculate_distance (self, string, mode)
86
86
  VALUE self;
87
- VALUE string;
88
- char mode;
87
+ VALUE string;
88
+ char mode;
89
89
  {
90
- VALUE pattern, tmp;
91
- static VALUE result;
92
- int pattern_len, string_len;
93
- char *pattern_ptr, *string_ptr;
94
- vector *v[2];
95
- int weight, sw, dw, iw, i, j, tmpi;
96
- int c = 0, p = 1;
97
-
98
- Check_Type(string, T_STRING);
99
- string_ptr = RSTRING(string)->ptr;
100
- string_len = RSTRING(string)->len;
101
-
102
- pattern = rb_iv_get(self, "@pattern");
103
- Check_Type(pattern, T_STRING);
104
- pattern_ptr = RSTRING(pattern)->ptr;
105
- pattern_len = RSTRING(pattern)->len;
106
-
107
- sw = weight2int(rb_iv_get(self, "@subw"), "subw");
108
- dw = weight2int(rb_iv_get(self, "@delw"), "delw");
109
- iw = weight2int(rb_iv_get(self, "@insw"), "insw");
110
-
111
- v[0] = vector_new(string_len);
112
- switch (mode) {
113
- case MATCH:
114
- case MATCHR:
115
- case COMPARE:
116
- case COMPARER:
117
- for (i = 0; i <= v[0]->len; i++) v[0]->ptr[i] = i * iw;
118
- break;
119
- case SEARCH:
120
- case SEARCHR:
121
- for (i = 0; i <= v[0]->len; i++) v[0]->ptr[i] = 0;
122
- break;
123
- default:
124
- rb_raise(rb_eFatal, "unknown mode in calculate_distance");
125
- }
126
-
127
- v[1] = vector_new(string_len);
128
- for (i = 1; i <= pattern_len; i++) {
129
- c = i % 2; /* current row */
130
- p = (i - 1) % 2; /* previous row */
131
- v[c]->ptr[0] = i * dw; /* first column */
132
- for (j = 1; j <= string_len; j++) {
133
- /* Bellman's principle of optimality: */
134
- weight = v[p]->ptr[j - 1] +
135
- (pattern_ptr[i - 1] == string_ptr[j - 1] ? 0 : sw);
136
- if (weight > v[p]->ptr[j] + 1) weight = v[p]->ptr[j] + dw;
137
- if (weight > v[c]->ptr[j - 1] + 1) weight = v[c]->ptr[j - 1] + iw;
138
- v[c]->ptr[j] = weight;
139
- }
140
- }
141
- switch (mode) {
142
- case MATCH:
143
- result = INT2FIX(vector_last(v[c]));
144
- break;
145
- case MATCHR:
146
- result = rb_float_new((double) vector_last(v[c]) / pattern_len);
147
- break;
148
- case SEARCH:
149
- tmpi = vector_minimum(v[c]);
150
- result = tmpi < 0 ? INT2FIX(pattern_len) : INT2FIX(tmpi);
151
- break;
152
- case SEARCHR:
153
- tmpi = vector_minimum(v[c]);
154
- result = rb_float_new( tmpi < 0 ? 1.0 : (double) tmpi / pattern_len);
155
- break;
156
- case COMPARE:
157
- result = INT2FIX((string_len < pattern_len ? -1 : 1) *
158
- vector_last(v[c]));
159
- break;
160
- case COMPARER:
161
- result = rb_float_new((double)
162
- (string_len < pattern_len ? -1 : 1) *
163
- vector_last(v[c]) / pattern_len);
164
- break;
165
- default:
166
- rb_raise(rb_eFatal, "unknown mode in calculate_distance");
167
- }
168
- vector_destroy(v[0]);
169
- vector_destroy(v[1]);
170
- return result;
90
+ VALUE pattern, tmp;
91
+ static VALUE result;
92
+ int pattern_len, string_len;
93
+ char *pattern_ptr, *string_ptr;
94
+ vector *v[2];
95
+ int weight, sw, dw, iw, i, j, tmpi;
96
+ int c = 0, p = 1;
97
+
98
+ Check_Type(string, T_STRING);
99
+ string_ptr = RSTRING(string)->ptr;
100
+ string_len = RSTRING(string)->len;
101
+
102
+ pattern = rb_iv_get(self, "@pattern");
103
+ Check_Type(pattern, T_STRING);
104
+ pattern_ptr = RSTRING(pattern)->ptr;
105
+ pattern_len = RSTRING(pattern)->len;
106
+
107
+ sw = weight2int(rb_iv_get(self, "@subw"), "subw");
108
+ dw = weight2int(rb_iv_get(self, "@delw"), "delw");
109
+ iw = weight2int(rb_iv_get(self, "@insw"), "insw");
110
+
111
+ v[0] = vector_new(string_len);
112
+ switch (mode) {
113
+ case MATCH:
114
+ case MATCHR:
115
+ case COMPARE:
116
+ case COMPARER:
117
+ for (i = 0; i <= v[0]->len; i++) v[0]->ptr[i] = i * iw;
118
+ break;
119
+ case SEARCH:
120
+ case SEARCHR:
121
+ for (i = 0; i <= v[0]->len; i++) v[0]->ptr[i] = 0;
122
+ break;
123
+ default:
124
+ rb_raise(rb_eFatal, "unknown mode in calculate_distance");
125
+ }
126
+
127
+ v[1] = vector_new(string_len);
128
+ for (i = 1; i <= pattern_len; i++) {
129
+ c = i % 2; /* current row */
130
+ p = (i - 1) % 2; /* previous row */
131
+ v[c]->ptr[0] = i * dw; /* first column */
132
+ for (j = 1; j <= string_len; j++) {
133
+ /* Bellman's principle of optimality: */
134
+ weight = v[p]->ptr[j - 1] +
135
+ (pattern_ptr[i - 1] == string_ptr[j - 1] ? 0 : sw);
136
+ if (weight > v[p]->ptr[j] + 1) weight = v[p]->ptr[j] + dw;
137
+ if (weight > v[c]->ptr[j - 1] + 1) weight = v[c]->ptr[j - 1] + iw;
138
+ v[c]->ptr[j] = weight;
139
+ }
140
+ }
141
+ switch (mode) {
142
+ case MATCH:
143
+ result = INT2FIX(vector_last(v[c]));
144
+ break;
145
+ case MATCHR:
146
+ result = rb_float_new((double) vector_last(v[c]) / pattern_len);
147
+ break;
148
+ case SEARCH:
149
+ tmpi = vector_minimum(v[c]);
150
+ result = tmpi < 0 ? INT2FIX(pattern_len) : INT2FIX(tmpi);
151
+ break;
152
+ case SEARCHR:
153
+ tmpi = vector_minimum(v[c]);
154
+ result = rb_float_new( tmpi < 0 ? 1.0 : (double) tmpi / pattern_len);
155
+ break;
156
+ case COMPARE:
157
+ result = INT2FIX((string_len < pattern_len ? -1 : 1) *
158
+ vector_last(v[c]));
159
+ break;
160
+ case COMPARER:
161
+ result = rb_float_new((double)
162
+ (string_len < pattern_len ? -1 : 1) *
163
+ vector_last(v[c]) / pattern_len);
164
+ break;
165
+ default:
166
+ rb_raise(rb_eFatal, "unknown mode in calculate_distance");
167
+ }
168
+ vector_destroy(v[0]);
169
+ vector_destroy(v[1]);
170
+ return result;
171
171
  }
172
172
 
173
173
  static VALUE
174
174
  handle_strings(self, strings, mode)
175
- VALUE self;
176
- VALUE strings;
177
- char mode;
175
+ VALUE self;
176
+ VALUE strings;
177
+ char mode;
178
178
  {
179
- if (TYPE(strings) == T_ARRAY) {
180
- int i;
181
- VALUE result = rb_ary_new2(RARRAY(strings)->len);
182
- for (i = 0; i < RARRAY(strings)->len; i++) {
183
- VALUE string = rb_ary_entry(strings, i);
184
- if (TYPE(string) != T_STRING) {
185
- rb_raise(rb_eTypeError,
186
- "array has to contain only strings (%s given)",
187
- NIL_P(string) ? "NilClass" :
188
- rb_class2name(CLASS_OF(string)));
189
- }
190
- rb_ary_push(result, calculate_distance(self, string, mode));
191
- }
192
- return result;
193
- } else if (TYPE(strings) == T_STRING) {
194
- return calculate_distance(self, strings, mode);
195
- } else {
196
- rb_raise(rb_eTypeError,
197
- "value of strings needs to be string or array (%s given)",
198
- NIL_P(strings) ? "NilClass" : rb_class2name(CLASS_OF(strings)));
199
- }
179
+ if (TYPE(strings) == T_ARRAY) {
180
+ int i;
181
+ VALUE result = rb_ary_new2(RARRAY(strings)->len);
182
+ for (i = 0; i < RARRAY(strings)->len; i++) {
183
+ VALUE string = rb_ary_entry(strings, i);
184
+ if (TYPE(string) != T_STRING) {
185
+ rb_raise(rb_eTypeError,
186
+ "array has to contain only strings (%s given)",
187
+ NIL_P(string) ? "NilClass" :
188
+ rb_class2name(CLASS_OF(string)));
189
+ }
190
+ rb_ary_push(result, calculate_distance(self, string, mode));
191
+ }
192
+ return result;
193
+ } else if (TYPE(strings) == T_STRING) {
194
+ return calculate_distance(self, strings, mode);
195
+ } else {
196
+ rb_raise(rb_eTypeError,
197
+ "value of strings needs to be string or array (%s given)",
198
+ NIL_P(strings) ? "NilClass" : rb_class2name(CLASS_OF(strings)));
199
+ }
200
200
  }
201
201
 
202
202
  /*
@@ -207,105 +207,100 @@ static VALUE
207
207
  rb_amatch_resetw(self)
208
208
  VALUE self;
209
209
  {
210
- rb_iv_set(self, "@subw", INT2FIX(1));
211
- rb_iv_set(self, "@delw", INT2FIX(1));
212
- rb_iv_set(self, "@insw", INT2FIX(1));
210
+ rb_iv_set(self, "@subw", INT2FIX(1));
211
+ rb_iv_set(self, "@delw", INT2FIX(1));
212
+ rb_iv_set(self, "@insw", INT2FIX(1));
213
213
 
214
- return Qtrue;
214
+ return Qtrue;
215
215
  }
216
216
 
217
217
  static VALUE
218
- rb_amatch_initialize(argc, argv, self)
219
- int argc;
220
- VALUE* argv;
218
+ rb_amatch_initialize(self, pattern)
221
219
  VALUE self;
222
- {
223
220
  VALUE pattern;
221
+ {
224
222
 
225
- rb_scan_args(argc, argv, "01", &pattern);
226
- Check_Type(pattern, T_STRING);
227
- rb_iv_set(self, "@pattern", pattern);
228
-
229
- rb_amatch_resetw(self);
230
-
223
+ Check_Type(pattern, T_STRING);
224
+ rb_iv_set(self, "@pattern", pattern);
225
+ rb_amatch_resetw(self);
231
226
  return self;
232
227
  }
233
228
 
234
229
  static VALUE
235
230
  rb_amatch_pattern_is(self, pattern)
236
231
  VALUE self;
237
- VALUE pattern;
232
+ VALUE pattern;
238
233
  {
239
- Check_Type(pattern, T_STRING);
240
- rb_iv_set(self, "@pattern", pattern);
234
+ Check_Type(pattern, T_STRING);
235
+ rb_iv_set(self, "@pattern", pattern);
241
236
 
242
- return pattern;
237
+ return pattern;
243
238
  }
244
239
 
245
240
 
246
241
  static VALUE
247
242
  rb_amatch_match(self, strings)
248
- VALUE self;
249
- VALUE strings;
243
+ VALUE self;
244
+ VALUE strings;
250
245
  {
251
- return handle_strings(self, strings, MATCH);
246
+ return handle_strings(self, strings, MATCH);
252
247
  }
253
248
 
254
249
  static VALUE
255
250
  rb_amatch_matchr(self, strings)
256
- VALUE self;
257
- VALUE strings;
251
+ VALUE self;
252
+ VALUE strings;
258
253
  {
259
- return handle_strings(self, strings, MATCHR);
254
+ return handle_strings(self, strings, MATCHR);
260
255
  }
261
256
 
262
257
  static VALUE
263
258
  rb_amatch_compare(self, strings)
264
- VALUE self;
265
- VALUE strings;
259
+ VALUE self;
260
+ VALUE strings;
266
261
  {
267
- return handle_strings(self, strings, COMPARE);
262
+ return handle_strings(self, strings, COMPARE);
268
263
  }
269
264
 
270
265
  static VALUE
271
266
  rb_amatch_comparer(self, strings)
272
- VALUE self;
273
- VALUE strings;
267
+ VALUE self;
268
+ VALUE strings;
274
269
  {
275
- return handle_strings(self, strings, COMPARER);
270
+ return handle_strings(self, strings, COMPARER);
276
271
  }
277
272
 
278
273
 
279
274
  static VALUE
280
275
  rb_amatch_search(self, strings)
281
- VALUE self;
282
- VALUE strings;
276
+ VALUE self;
277
+ VALUE strings;
283
278
  {
284
- return handle_strings(self, strings, SEARCH);
279
+ return handle_strings(self, strings, SEARCH);
285
280
  }
286
281
 
287
282
  static VALUE
288
283
  rb_amatch_searchr(self, strings)
289
- VALUE self;
290
- VALUE strings;
284
+ VALUE self;
285
+ VALUE strings;
291
286
  {
292
- return handle_strings(self, strings, SEARCHR);
287
+ return handle_strings(self, strings, SEARCHR);
293
288
  }
294
289
 
295
290
  void
296
291
  Init_amatch()
297
292
  {
298
- cAmatch = rb_define_class("Amatch", rb_cObject);
299
- rb_define_method(cAmatch, "initialize", rb_amatch_initialize, -1);
293
+ cAmatch = rb_define_class("Amatch", rb_cObject);
294
+ rb_define_method(cAmatch, "initialize", rb_amatch_initialize, 1);
300
295
 
301
- rb_define_attr(cAmatch, "debug", 1, 1);
302
- rb_define_attr(cAmatch, "subw", 1, 1);
303
- rb_define_attr(cAmatch, "delw", 1, 1);
304
- rb_define_attr(cAmatch, "insw", 1, 1);
296
+ rb_define_attr(cAmatch, "debug", 1, 1);
297
+ rb_define_attr(cAmatch, "subw", 1, 1);
298
+ rb_define_attr(cAmatch, "delw", 1, 1);
299
+ rb_define_attr(cAmatch, "insw", 1, 1);
305
300
  rb_define_method(cAmatch, "resetw", rb_amatch_resetw, 0);
306
301
 
307
302
  rb_define_method(cAmatch, "pattern=", rb_amatch_pattern_is, 1);
308
- rb_define_attr(cAmatch, "pattern", 1, 0);
303
+ rb_define_attr(cAmatch, "pattern", 1, 0);
309
304
 
310
305
  rb_define_method(cAmatch, "match", rb_amatch_match, 1);
311
306
  rb_define_method(cAmatch, "matchr", rb_amatch_matchr, 1);
@@ -314,4 +309,4 @@ Init_amatch()
314
309
  rb_define_method(cAmatch, "search", rb_amatch_search, 1);
315
310
  rb_define_method(cAmatch, "searchr", rb_amatch_searchr, 1);
316
311
  }
317
- /* vim: set cin sw=4 ts=4: */
312
+ /* vim: set et cin sw=4 ts=4: */
Binary file
Binary file
File without changes
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: amatch
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2004-09-27
6
+ version: 0.1.4
7
+ date: 2005-01-20
8
8
  summary: Approximate String Matching library
9
9
  require_paths:
10
10
  - lib
11
11
  author: Florian Frank
12
12
  email: flori@ping.de
13
- homepage: http://XXX
13
+ homepage: http://amatch.rubyforge.org
14
14
  rubyforge_project: amatch
15
15
  description: Amatch is a library for approximate string matching and searching using a dynamic programming algorithm to compute the Levenstein distance between strings.
16
16
  autorequire: amatch
@@ -32,22 +32,23 @@ files:
32
32
  - bin
33
33
  - bin/agrep.rb
34
34
  - ext
35
+ - ext/Makefile
35
36
  - ext/MANIFEST
36
37
  - ext/amatch.c
37
38
  - ext/extconf.rb
39
+ - ext/amatch.o
40
+ - ext/amatch.so
38
41
  - Rakefile
39
42
  - VERSION
40
43
  - amatch.txt.en
41
44
  - install.rb
42
- - test.rb
43
- - index.html
44
- test_files: []
45
- rdoc_options:
46
- - "--title"
47
- - "Rake -- Ruby Make"
48
- - "--main"
49
- - README
50
- - "--line-numbers"
45
+ - config.save
46
+ - InstalledFiles
47
+ - tests
48
+ - tests/test.rb
49
+ test_files:
50
+ - tests/test.rb
51
+ rdoc_options: []
51
52
  extra_rdoc_files: []
52
53
  executables:
53
54
  - agrep.rb
data/index.html DELETED
@@ -1,9 +0,0 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Refresh" content="0; URL=http://www.rubyforge.org/projects/amatch/"/>
4
- <title>Approximate String Matching</title>
5
- </head>
6
- <body>
7
- Redirecting to project <a href="http://www.rubyforge.org/projects/amatch/">Approximate String Matching</a> on Rubyforge.
8
- </body>
9
- </html>