根据一个回答另一个问题,在sqlite中,Levenshtein距离是在一个名为editdist3的SQL函数中实现的。(同时比较文档)
现在,当我尝试使用它时,我得到的只是一个错误,它不存在:
╰┄┄> sqlite3
SQLite version 3.11.1 2016-03-03 16:17:53
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE test (col1 TEXT);
sqlite> INSERT INTO test VALUES ('foobar');
sqlite> SELECT * FROM test WHERE editdist3(col1, 'f00bar') < 3;
Error: no such function: editdist3我在Gentoo Linux上使用sqlit-3.11.1,(默认)使用标志icu、readline和secure-delete。
发布于 2016-04-05 13:30:04
事实证明,editdist3包含在一个必须显式加载的sqlite扩展中。因为我没有在Gentoo sqlite包中找到它,所以我也不得不自己构建它。正如文档所说:
spellfix1虚拟表不包含在SQLite合并中,也不是任何标准SQLite构建的一部分。这是一个可下载的扩展。
首先,我获取了源代码
wget https://sqlite.org/2016/sqlite-src-3110100.zip
unzip sqlite-src-3110100.zip那么它必须被编译。
gcc -shared -fPIC -Wall -Isqlite-src-3110100 sqlite-src-3110100/ext/misc/spellfix.c -o spellfix.so最后,它可以装载
.load ./spellfix请注意,sqlite自动附加扩展.so。
要在python中使用它--这是我的初衷--需要做以下工作:
db = sqlite3.connect(':memory:')
db.enable_load_extension(True)
db.load_extension('./spellfix')
db.enable_load_extension(False)https://stackoverflow.com/questions/36427820
复制相似问题