Substring Diffing Ruby Challenge

S

S. Robert James

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?
 
A

Alex Fenton

S. Robert James said:
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/diff-lcs/

Weft QDA code that does it:
http://viewvc.rubyforge.mmmultiwork...ft-qda/lib/weft/diff.rb?root=weft-qda&view=co

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

hth
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top