我知道 q-gram 距离是两个字符串的 q-gram 向量之间的绝对差之和。但是当其中一个字符串比所选的 q 短时,我看到了一些奇怪的行为。
所以对于这两个字符串,虽然qgrams
函数是正确的:
> qgrams("a", "the cat sat on the mat", q = 2)
th he t sa on n ma e c ca at s t o m
V1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
V2 2 2 2 1 1 1 1 2 1 1 3 1 1 1 1
stringdist
函数返回:
> stringdist("a", "the cat sat on the mat", q = 2, method = "qgram")
[1] Inf
而不是返回:
> sum(qgrams("a", "the cat sat on the mat", q = 2)[2,])
[1] 21
我错过了什么还是这是一个错误?谢谢。
stringdist 版本:0.9.4.1 和 0.9.4.2