How to merge two texts given the common base version of both texts?

142 Views Asked by At

Similar to how git merge two branches but:

  • using python
  • instead of two branches we have text1 and text2
  • instead of common commit we have text0 - previous version of both text1 and text2

diff-match-patch probably can be used to accomplish this task, but I didn't find appropriate method neither in doc nor in python package source code (because docs are not complete).

So far I come up with this:

c = "some base text with meaning"
a = "changed base text with meaning"
b = "some base text without meaning"
p1 = dmp.patch_make(c, a)
p2 = dmp.patch_make(c, b)
dmp.patch_apply(p1 + p2, c)
> ('changed base text without meaning', [True, True])

It looks like it works, but I'm not sure if this is correct method. Can someone experienced with diff-match-patch approve this?

0

There are 0 best solutions below