2017-08-26 49 views
0

A BK Trees (Burkhard-Keller Trees)與模糊字符串搜索(例如拼寫檢查,單詞推薦)相關聯。所有的BK樹搜索算法都與explained here相同。目標是返回,例如"seek" and "peek" if I search for "aeek"BK - 樹搜索全部

現在,我的問題是,我想利用這個模糊字符串搜索算法來搜索從所有類似的項目給予詞典。例如,給一個詞「尋找」,我想找到全部類似的單詞,如「偷看」,「怪胎」,「座位」等字典內。但是我發現BK Trees searching algorithm that everyone uses不是爲此設計的。

看看我的sample test result here。我發現the dictionary will be different if the feeding words order is different, thus the search result can be different as well

我要的是,使用,給定任意的四個Python的書我上面sample test,一個SearchAll函數總是返回四個Python的書,儘管字典構建順序,或搜索完成的順序。

但是,我嘗試了很多方法,但都失敗了(例如,this is one of them)。現在我正在甩手並尋求幫助。僞代碼或通用算法描述會做。謝謝。

+0

@templatetypedef? – xpt

+0

@Duck,你能幫忙嗎? – xpt

回答

1

你必須在線路77和bktree.go的106的整數溢出:

K:= d - R

由於類型druint8,類型k也是uint8,所以當d < r,k結束大於d + r,並且下面的循環不執行。

你能解決這個問題是這樣的:

k := int16(d) - int16(r) 
max_k := int16(d) + int16(r) 
if k < 1 { 
    k = 1 
} 
for ; k <= max_k; k++ { 
    ... 
} 
+0

實際上,這不會發生,如行https://github.com/go-dedup/simhash/blob/master/sho/bktree.go#L73-L74,也就是說,在77行和106行時, d'會是'> = r'。但感謝您抽出寶貴時間進行研究! – xpt

+0

我用調試器瀏覽過它,它發生在[106]行(https://github.com/go-dedup/simhash/blob/master/sho/bktree.go#L106)。而且,修復後,'ExampleSearch_filesA','ExampleSearch_filesB','ExampleSearch_filesS'全部輸出相同的結果。 – Anton

+0

哦,那裏!非常感謝!你用什麼調試器BTW? – xpt