google-diff-match-patch - 如何在 google/diff-match-patch C# 中实现字级别

标签 google-diff-match-patch

我正在尝试在 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 文件,但单词和线条有效。

DiffMatchPatchSample

对于上面的示例文本,我得到以下输出。

at these | to those

关于google-diff-match-patch - 如何在 google/diff-match-patch C# 中实现字级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62187830/

相关文章:

javascript - 如何使 Google Diff Match Patch 更喜欢字符串末尾的更改?

Java : Getting effected sentence in Google-diff-match-patch

javascript - 在 Angular 中使用 google-diff-match-patch

c++ - 仅在添加第二个项目后才出现第一个项目的编译错误

javascript - 为什么 Diff-match-patch broken linediff 超过 65K 行

java - google-diff-match-patch 在运行时失败并出现 java.lang.NoClassDefFoundError