给定两种文本的通用基本版本,如何合并两种文本?

时间:2019-02-21 15:04:52

标签: python merge diff text-processing google-diff-match-patch

类似于git如何合并两个分支,但是:

  • 使用python
  • 我们有text1text2
  • ,而不是两个分支
  • 我们有text0而不是普通的提交-text1和text2的先前版本

diff-match-patch可能可以用来完成此任务,但是我在doc和python包源代码中都找不到合适的方法(因为docs不完整)。

到目前为止,我想出了这一点:

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])

看起来可行,但是我不确定这是否正确。 拥有diff-match-patch经验的人可以批准吗?

0 个答案:

没有答案