| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<HTML> |
| 3 |
<HEAD> |
| 4 |
<TITLE>Diff, Match and Patch: Demo of Diff</TITLE> |
| 5 |
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="../javascript/diff_match_patch.js"></SCRIPT> |
| 6 |
</HEAD> |
| 7 |
|
| 8 |
<BODY> |
| 9 |
<H1>Diff, Match and Patch</H1> |
| 10 |
<H2>Demo of Diff</H2> |
| 11 |
|
| 12 |
<P>Diff takes two texts and finds the differences. This implementation works on a character by character basis. |
| 13 |
The result of any diff may contain 'chaff', irrelevant small commonalities which complicate the output. |
| 14 |
A post-diff cleanup algorithm factors out these trivial commonalities.</P> |
| 15 |
|
| 16 |
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> |
| 17 |
var dmp = new diff_match_patch(); |
| 18 |
|
| 19 |
function launch() { |
| 20 |
var text1 = document.getElementById('text1').value; |
| 21 |
var text2 = document.getElementById('text2').value; |
| 22 |
dmp.Diff_Timeout = parseFloat(document.getElementById('timeout').value); |
| 23 |
dmp.Diff_EditCost = parseFloat(document.getElementById('editcost').value); |
| 24 |
|
| 25 |
var ms_start = (new Date()).getTime(); |
| 26 |
var d = dmp.diff_main(text1, text2); |
| 27 |
var ms_end = (new Date()).getTime(); |
| 28 |
|
| 29 |
if (document.getElementById('semantic').checked) { |
| 30 |
dmp.diff_cleanupSemantic(d); |
| 31 |
} |
| 32 |
if (document.getElementById('efficiency').checked) { |
| 33 |
dmp.diff_cleanupEfficiency(d); |
| 34 |
} |
| 35 |
var ds = dmp.diff_prettyHtml(d); |
| 36 |
document.getElementById('outputdiv').innerHTML = ds + '<BR>Time: ' + (ms_end - ms_start) / 1000 + 's'; |
| 37 |
} |
| 38 |
</SCRIPT> |
| 39 |
|
| 40 |
<FORM action="#" onsubmit="return false"> |
| 41 |
<TABLE WIDTH="100%"><TR> |
| 42 |
<TD WIDTH="50%"> |
| 43 |
<H3>Text Version 1:</H3> |
| 44 |
<TEXTAREA ID="text1" STYLE="width: 100%" ROWS=10>I am the very model of a modern Major-General, |
| 45 |
I've information vegetable, animal, and mineral, |
| 46 |
I know the kings of England, and I quote the fights historical, |
| 47 |
From Marathon to Waterloo, in order categorical.</TEXTAREA></TD> |
| 48 |
<TD WIDTH="50%"> |
| 49 |
<H3>Text Version 2:</H3> |
| 50 |
<TEXTAREA ID="text2" STYLE="width: 100%" ROWS=10>I am the very model of a cartoon individual, |
| 51 |
My animation's comical, unusual, and whimsical, |
| 52 |
I'm quite adept at funny gags, comedic theory I have read, |
| 53 |
From wicked puns and stupid jokes to anvils that drop on your head.</TEXTAREA></TD> |
| 54 |
</TR></TABLE> |
| 55 |
|
| 56 |
<H3>Diff timeout:</H3> |
| 57 |
<P><INPUT TYPE="text" SIZE=3 MAXLENGTH=5 VALUE="1" ID="timeout"> seconds<BR> |
| 58 |
If the mapping phase of the diff computation takes longer than this, then the computation |
| 59 |
is truncated and the best solution to date is returned. While guaranteed to be correct, |
| 60 |
it may not be optimal. A timeout of '0' allows for unlimited computation.</P> |
| 61 |
|
| 62 |
<H3>Post-diff cleanup:</H3> |
| 63 |
<DL> |
| 64 |
<DT><INPUT TYPE="radio" NAME="cleanup" ID="semantic" CHECKED> |
| 65 |
<LABEL FOR="semantic">Semantic Cleanup</LABEL></DT> |
| 66 |
<DD>Increase human readability by factoring out commonalities which are likely to be |
| 67 |
coincidental.</DD> |
| 68 |
<DT><INPUT TYPE="radio" NAME="cleanup" ID="efficiency"> |
| 69 |
<LABEL FOR="efficiency">Efficiency Cleanup</LABEL>, |
| 70 |
edit cost: <INPUT TYPE="text" SIZE=3 MAXLENGTH=5 VALUE="4" ID="editcost"> |
| 71 |
<DD>Increase computational efficiency by factoring out short commonalities which are |
| 72 |
not worth the overhead. The larger the edit cost, the more agressive the cleanup.</DD> |
| 73 |
<DT><INPUT TYPE="radio" NAME="cleanup" ID="raw"> |
| 74 |
<LABEL FOR="raw">No Cleanup</LABEL></DT> |
| 75 |
<DD>Raw output.</DD> |
| 76 |
</DL> |
| 77 |
|
| 78 |
<P><INPUT TYPE="button" onClick="launch()" VALUE="Compute Diff"></P> |
| 79 |
</FORM> |
| 80 |
|
| 81 |
<DIV ID="outputdiv"></DIV> |
| 82 |
|
| 83 |
<HR> |
| 84 |
Back to <A HREF="http://code.google.com/p/google-diff-match-patch/">Diff, Match and Patch</A> |
| 85 |
|
| 86 |
</BODY> |
| 87 |
</HTML> |