根据对另一个问题的回答,在 sqlite 中,Levenshtein 距离是在名为editdist3. (也比较文档)
现在,当我尝试使用它时,我得到的只是它不存在的错误:
???> 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
Run Code Online (Sandbox Code Playgroud)
我在 Gentoo Linux 上使用 sqlite-3.11.1(默认) USE 标志icu,readline和secure-delete …
Python+Sqlite 中是否有可用的字符串相似性度量,例如sqlite3模块?
用例示例:
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('CREATE TABLE mytable (id integer, description text)')
c.execute('INSERT INTO mytable VALUES (1, "hello world, guys")')
c.execute('INSERT INTO mytable VALUES (2, "hello there everybody")')
Run Code Online (Sandbox Code Playgroud)
此查询应匹配 ID 为 1 的行,但不匹配 ID 为 2 的行:
c.execute('SELECT * FROM mytable WHERE dist(description, "He lo wrold gyus") < 6')
Run Code Online (Sandbox Code Playgroud)
如何在 Sqlite+Python 中做到这一点?
关于我到目前为止发现的内容的注释:
该Levenshtein距离,即单字符编辑(插入,删除或替换)的最小数量需要改变一个字到另一个,可能是有用的,但我不知道是否SQLite中存在的正式实施(我看到了一些自定义实现,比如这个)
所述Damerau-的Levenshtein是相同的,除了它也允许两个相邻字符之间换位; 它也被称为编辑距离
我知道自己定义一个函数是可能的,但是实现这样的距离并不容易(对数据库进行超高效的自然语言处理比较真的很重要),这就是为什么我想看看 Python / Sqlite 是否已经具有这样的功能一个工具
Sqlite 具有 …