重新打包google的diff match和patch库。提供强大的算法来执行同步纯文本所需的操作。
diff-match-patch的Python项目详细描述
差异匹配修补程序
google的Diff Match and Patch库,为现代python打包。
安装
Python2.7或Python3.4或更新版本支持diff match补丁。 您可以从pypi安装它:
python -m pip install diff-match-patch
用法
在两个文本之间生成补丁集(类似于统一diff):
fromdiff_match_patchimportdiff_match_patchdmp=diff_match_patch()patches=dmp.patch_make(text1,text2)diff=dmp.patch_toText(patches)
对文本应用修补程序集,然后可以使用:
fromdiff_match_patchimportdiff_match_patchdmp=diff_match_patch()patches=dmp.patch_fromText(diff)new_text,_=dmp.patch_apply(patches,text)
原始自述文件
diff match和patch库提供了执行 同步纯文本所需的操作。
- 差异:
- 比较两个纯文本块并有效返回差异列表。
- Diff Demo
- 匹配:
- 给定一个搜索字符串,在纯文本块中找到它的最佳模糊匹配。对精度和位置进行加权。
- Match Demo
- 修补程序:
- 在纯文本上应用修补程序列表。即使基础文本不匹配,也要尽最大努力应用修补程序。
- Patch Demo
最初建立在2006的谷歌文档中,这个库现在可以用C++,C,DART,Java,JavaScript,Lua,Object C和Python提供。
参考值
- API-跨所有语言的通用api。
- Line or Word Diffs-不太详细的差异。
- Plain Text vs. Structured Content-如何处理xml之类的数据。
- Unidiff-修补程序序列化格式。
- Support-开发者新闻组。
语言
尽管diff match补丁的每个语言端口都使用相同的api,但仍有一些特定于语言的注释。
标准化的速度测试跟踪每种语言中的relative performance of diffs。
算法
这个库实现了Myer's diff algorithm这通常被认为是最好的通用diff。围绕diff算法的pre-diff speedups and post-diff cleanups层提高了性能和输出质量。
这个库还实现了位于flexible matching and patching strategy核心的Bitap matching algorithm。