I need to do Word by word comparison of two strings. Something like diff, but for words, not for lines.
Like it is done in wikipedia http://en.wikipedia.org/w/index.php?title=Horapollo&action=historysubmit&diff=21895647&oldid=21893459
In result I want return the two arrays of indexes of words, which are different in two string.
Are there any libraries/frameworks/standalone_methods for .NET which can do this?
P.S. I want to compare several kilobytes of text
Actually, you probably want to implement a variation of the Local Alignment/Global Alignment algorithms we use in DNA sequence alignments. This is because you probably cannot do a word-by-word comparison of the two strings. I.e:
In other words, if you cannot identify insertions and deletions of whole words, your comparison algorithm can become very sc(r)ewed. Take a look at the Smith-Waterman algorithm and the Needleman-Wunsch algorithm and find a way to adapt them to your needs. Since such a search space can become very large if the strings are long, you could also check out BLAST. BLAST is a very common heuristic algorithm, and is pretty much the standard in genetic searches.
It seems I will use/port algorithm used here
http://www.google.com/codesearch/p?hl=en&sa=N&cd=6&ct=rc#Jc4aufN53J8/src/main/net/killingar/WordDiff.java&q=worddiff
It seems I've found needed solution:
DiffPlex is a combination of a .NET Diffing Library with both a Silverlight and HTML diff viewer. http://diffplex.codeplex.com/
But It has one bug. In those lines "Hello-Kitty" "Hello - Kitty", the word "Hello" will be marked as difference. Although the difference is space symbol.
you can replace all the words in your 2 texts with unique numbers, take some ready made code for Edit distance computation and replace it's character to character comparison with number to number comparison and you are done!
I am not sure if there exists any library for exactly what u want. But you will surely find lots of code for edit distance.
Further, depending on whether you want to actually want to allow substitutions or not in the edit distance computation, you can change the conditions in the dynamic programming code.
See this. http://en.wikipedia.org/wiki/Levenshtein_distance
One more library for c# is diff-match-patch - http://code.google.com/p/google-diff-match-patch/.
The bad thing it finds difference in characters. The good thing, there is instruction what you have to add to diff the words.
Use RegularExpressions.
Like in the example: