我正在尝试在 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=|
文档说:
制作 diff_linesToChars 的副本并将其命名为 diff_linesToWords。查找标识下一行边界的行: 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 个字符的硬编码)。