Text comparison algorithm

java_mouse picture java_mouse · Jan 30, 2012 · Viewed 41k times · Source

We have a requirement in the project that we have to compare two texts (update1, update2) and come up with an algorithm to define how many words and how many sentences have changed.

Are there any algorithms that I can use?

I am not even looking for code. If I know the algorithm, I can code it in Java.

Answer

FatalError picture FatalError · Jan 30, 2012

Typically this is accomplished by finding the Longest Common Subsequence (commonly called the LCS problem). This is how tools like diff work. Of course, diff is a line-oriented tool, and it sounds like your needs are somewhat different. However, I'm assuming that you've already constructed some way to compare words and sentences.