From: Charles O Nutter Date: 2006-04-07T00:46:46+09:00 Subject: Re: String generalization called from JRuby ------=_Part_13572_17830793.1144338401687 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Forking the discussion a bit, but I'm interested in your use of JRuby here. It seems like a great idea to have little snippits of code that are easier to understand and maintain in Ruby, and be able to call them from Java with JRuby. Are you doing this already, or is this a first possible attempt at it? (I ask because I'm on the JRuby team) On 4/6/06, Peter Szinek wrote: > > Hello all, > > I am having the following problem: I have to implement a method > which accepts a string and returns a generalized form of the string. > Some examples: > > '12345' -> \d+ > 'ABCDE' -> [A-Z]+ > 'john.smith@my.super.server.rb' -> [a-z]+\.[a-z]+@([a-z]+\.)+[a-z] > '123-45-678-90' -> (\d+-)+\d+ > 'item:' -> [a-z]+: > 'Peter, SZINEK': -> [A-Z][a-z]+, [A-Z]+ > 'http://www.google.com' -> [a-z]+://([a-z]+\.)+[a-z] > 'jd=A3;d:L348kddd3' -> .* > > So, given an example, the function should generate a generic regexp > which is then used to match the instances of the same class (i.e. based > on an e-mail, you create a regexp which can be used to match other > emails). > Of course this problem is not solvable in general. You would need more > examples (both positive and negative ones, as it is proven that just > using positive examples you can not generalize a pattern (generate a > regular grammar desribibg it) and then machine learn/induce a > grammar/etc based on that. Unfortunately i have only one positive > example. So i do not need a perfect solution (which is not possible > anyway) just a mostly working one. > > I have implemented it in java, and it works pretty well but it is ugly > as hell (as any java code dealing with stuff where you need regexps, > slicing, maps etc). Any ideas for a nice Ruby code solving this? Then i > would call it via JRuby (and killed by the other colleagues using java > but not Ruby ;-). > > thx, > Peter > > -- Charles Oliver Nutter @ headius.blogspot.com JRuby Developer @ jruby.sourceforge.net Application Architect @ www.ventera.com ------=_Part_13572_17830793.1144338401687--