From: Phil Rhoades Date: 2008-04-27T05:26:38+09:00 Subject: Re: Howto get array.agrep (NOT array.grep) jens, On Sun, 2008-04-27 at 02:50 +0900, Jens Wille wrote: > Phil Rhoades [2008-04-26 19:13]: > > This might work but it would be more difficult without regexs - > > the current application does a system call to agrep but of course > > it is very slow for large numbers of calls. A typical call is > > something like: > > > > agrep -2 "Smith\|J.*12345" list1.txt list2.txt list3.txt > > > > This allows two differences on a minimum amount of information > > consisting of last name, first initial and zip code. If I use > > the Enumerable version, I would have to use the whole, delimited, > > name & address string and increase the differences/distance > > number? > > i think something like that could work in your case (requires the > Text gem): > > File.open('list1.txt').select { |line| > # extract name and zip code from line > line =~ /\A(.*?\|.).*\b(\d{5})\b/ # adjust appropriately! > > # name may have two errors, zip only one -- or whatever... > Text::Levenshtein.distance($1, 'Smith|J') <= 2 && > Text::Levenshtein.distance($2, '12345') <= 1 > } I see what you are doing but this would have to be repeated for the three different lists (list1.txt, list2.txt, list3.txt) - I guess that should still be faster than a single system call . . > > Did you just do that hack now? > that's right. but i just read a bit on agrep's algorithm and it > might be fun to implement it in ruby (though a bit slow, probably). I don't know if it helps but there is this: http://www.koders.com/ruby/fidCEAEDCAA28D4A59A76ADF20A0DA2A3858438834D.aspx > as an alternative, it might be even worth writing ruby bindings to > agrep. who knows, if time permits... ;-) I was wondering about something like that but I have never created a Ruby binding before . . > > - how do I get/install it? (Fedora 8). > well, i don't think that particular implementation suits your needs > and is obviously easily adapted (after all, it's just a select with > an appropriate block utilizing Text::Levenshtein.distance). but you > can get ruby-nuggets from rubyforge (gem install ruby-nuggets), or, > if the new version hasn't found its way onto the mirrors yet, from > our own gem server at http://prometheus.khi.uni-koeln.de/rubygems/. Thanks! Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Fax: +61:(0)2-8221-9599 E-mail: phil@pricom.com.au