[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Substring Diffing Ruby Challenge

S. Robert James

7/19/2007 1:03:00 AM

first = 'Joe went to the store and bought 2 loaves of bread'
second = 'Joe and I went to the market and bought 3 loaves of bread
and butter'

assert_equal [4..9, 21..29, 57..68], diff(first, second) # diff()
returns a list of Ranges spanning the position of edits or insertions

Anyone know an algorithm (or code) that can make that work?

1 Answer

Alex Fenton

7/19/2007 9:15:00 AM

0

S. Robert James wrote:
> first = 'Joe went to the store and bought 2 loaves of bread'
> second = 'Joe and I went to the market and bought 3 loaves of bread
> and butter'
>
> assert_equal [4..9, 21..29, 57..68], diff(first, second) # diff()
> returns a list of Ranges spanning the position of edits or insertions
>
> Anyone know an algorithm (or code) that can make that work?
>

I extended Austin Ziegler's LCS/Diff library to do just this for my project

LCS/Diff:
http://raa.ruby-lang.org/project...

Weft QDA code that does it:
http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/weft-qda/lib/weft/diff.rb?root=weft-qda&a...

The 'transform' method accepts two strings and returns an array of
'Transformation' objects, each representing a single insert/delete/change

hth
alex