良好的抄袭检测将根据文档类型(例如特定语言的论文或程序代码)应用启发式方法。
但是,您也可以应用通用解决方案。看看Normalized Compression Distance (NCD)。显然,您无法准确计算文本的Kolmogorov complexity,但您可以通过简单地压缩文本来处理它。
较小的 NCD 表示两个文本更相似。一些压缩
算法将提供比其他算法更好的结果。幸运的是 PHP 提供了支持
对于several 压缩算法,所以你可以有你的NCD驱动的抄袭
检测代码立即运行。下面我将给出使用的示例代码
Zlib:
PHP:
function ncd($x, $y) {
$cx = strlen(gzcompress($x));
$cy = strlen(gzcompress($y));
return (strlen(gzcompress($x . $y)) - min($cx, $cy)) / max($cx, $cy);
}
print(ncd('this is a test', 'this was a test'));
print(ncd('this is a test', 'this text is completely different'));
Python:
>>> from zlib import compress as c
>>> def ncd(x, y):
... cx, cy = len(c(x)), len(c(y))
... return (len(c(x + y)) - min(cx, cy)) / max(cx, cy)
...
>>> ncd('this is a test', 'this was a test')
0.30434782608695654
>>> ncd('this is a test', 'this text is completely different')
0.74358974358974361
请注意,对于较大的文本(阅读:实际文件),结果会更多
发音。试一试并报告您的经验!