我正在尝试在 Google Diff Match Patch 中实现单词级别匹配,但它让我很困惑。
我得到的结果是:
=I've never been =|-a-|=t=|= th=|-e-|=se places=|
=I've never been =|=t=|+o+|= th=|+o+|=se places=|
我想要的结果是:
=I've never been =|-at these-|= places=|
=I've never been =|+to those+|= places=|
文档说:
make a copy of diff_linesToChars and call it diff_linesToWords. Look for the line that identifies the next line boundary: lineEnd = text.indexOf('\n', lineStart);
在c#版本中,我在diff_linesToCharsMunge中找到了需要更改的行,我将其更改为:
lineEnd = text.Replace(@"/[\n\.,;:]/ g"," ").IndexOf(" ", lineStart);
但是,粒度没有变化 - 它仍然发现字符级别的差异。
我正在打电话:
List<Diff> differences = diffs.diff_main(linepair.Original, linepair.Corrected, true);
diffs.diff_cleanupSemantic(differences);
我已逐步检查以确保它符合我所做的更改(顺便说一句,在生效之前有至少 100 个字符的硬编码)。
最佳答案
我使用 diffmatch 程序创建了一个示例 dotnet 项目。它可能是旧版本的 DiffMatchPatch 文件,但单词和线条有效。
对于上面的示例文本,我得到以下输出。
at these | to those
关于google-diff-match-patch - 如何在 google/diff-match-patch C# 中实现字级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62187830/