Differing results in (javascript)-Demo and Python3

114 views
Skip to first unread message

Stephan Schlögl

unread,
Jan 14, 2019, 7:41:09 AM1/14/19
to Diff Match Patch
I'm using diff-match-patch in python3 which generally works very well. However I noticed that in some cases the  results returned by the (javascript) Demo version are better (in the sense of more detailed) than the results produced by python3. As I understand that the demo is using the same function calls as the ones below for python3:

#!/usr/bin/python
from diff_match_patch import diff_match_patch

fileA
= '000225__109712657'
with open(fileA, 'r') as version:
    textA
=version.read()


fileB
= '000226__109712675'
with open(fileB, 'r') as version:
    textB
=version.read()


dmp
= diff_match_patch()
diff
= dmp.diff_main(textA, textB, checklines=False)
dmp
.diff_cleanupSemantic(diff)
print(dmp.diff_prettyHtml(diff))

Here are screenshot of the relevant part of the results of the example:

python3:

python3.png


vs. javascript

javascript.png


I tried calling dmp.main() with checklines=False but this didn't make any difference...
Are there any default function parameters that might be the cause for these differences? Or is there another reason for this?

In absence of a better and smaller example to reproduce this, I am attaching the original text files
I installed diff-match-patch via pip (diff-match-patch==20181111) and I'm using the demo found on the github page.


000226__109712675
000225__109712657

Stephan Schlögl

unread,
Jan 14, 2019, 10:07:57 AM1/14/19
to Diff Match Patch
I believe due to the fact that the the python3 implementation is slower than the javascript implementation.
Although the two implementations have the same timeout python3 needs longer to compute this diff and is interrupted. By disabling the Timeout I do get the same results (just a bit later ;))

dmp = diff_match_patch()
dmp
.Diff_Timeout = 0 #<------- setting timeout to 0 disables it
diff
= dmp.diff_main(textA, textB, checklines=False)
dmp
.diff_cleanupSemantic(diff)
print(dmp.diff_prettyHtml(diff))
Reply all
Reply to author
Forward
0 new messages