-1

Like the title, How to compare text?. For a example, go to textdiff.com.

cdxf
  • 5,501
  • 11
  • 50
  • 65

5 Answers5

4

Check out Levenshtein distance. This is a fairly general algorithm for identifying differences between two strings.

JoshD
  • 12,490
  • 3
  • 42
  • 53
  • No, i want to ask the algorithm. Not a software. But it is good if you give me a php class – cdxf Oct 04 '10 at 05:20
  • PHP has a `levenshtein()` function you can look into. – Russell Dias Oct 04 '10 at 05:45
  • Levensthein measures the "amount of difference" between two strings, but will not return the location of the differences. Also, I am not sure how useful it is for comparing sentences. `Text_Diff` will do exactly what the OP asked for (see my answer for links) – nico Oct 04 '10 at 06:01
1

You may want to have a look at Pear's Text_Diff

http://pear.php.net/package/Text_Diff/

nico
  • 50,859
  • 17
  • 87
  • 112
  • @Snoob: Yes, `Text_Diff` is one of the classes of the Pear framework. You will have to install the base Pear components first (see http://pear.php.net/manual/en/installation.introduction.php ) and, once that is working you can add Text_Diff. Looking at the page you linked I would say that's what they used. `Text_Diff` comes with documentation and examples: http://pear.php.net/package/Text_Diff/docs/latest/ – nico Oct 04 '10 at 05:26
0

I would suggest Jaccard's Similarity coefficient. Treating each sentence as a unit.

roopalgarg
  • 429
  • 1
  • 6
  • 19
0

if you're looking for a terminal command, check out diff, found in linux by default. You can also have it on windows by installing cygwin [with a LOT of excess baggage. :\ ]

Karthick
  • 4,456
  • 7
  • 28
  • 34