How to use editdist3 in sqlite

后端 未结 1 871

According to an answer to another question, in sqlite the Levenshtein distance is implemented in a SQL function called editdist3. (Compare also the documentatio

相关标签:
1条回答
  • 2020-12-18 07:15

    It turns out editdist3 is contained in an sqlite extension that has to be loaded explicitly. As I didn’t find it in the Gentoo sqlite package, I also had to build it myself. As the documentation says:

    The spellfix1 virtual table is not included in the SQLite amalgamation and is not a part of any standard SQLite build. It is a loadable extension.

    First I fetched the source code

    wget https://sqlite.org/2016/sqlite-src-3110100.zip
    unzip sqlite-src-3110100.zip
    

    then it has to be compiled

    gcc -shared -fPIC -Wall -Isqlite-src-3110100 sqlite-src-3110100/ext/misc/spellfix.c -o spellfix.so
    

    and finally it can be loaded with

    .load ./spellfix
    

    Note that sqlite automatically appends the extension .so.

    To use it in python – which was my original intention – the following needs to be done:

    db = sqlite3.connect(':memory:')
    
    db.enable_load_extension(True)
    db.load_extension('./spellfix')
    db.enable_load_extension(False)
    
    0 讨论(0)
提交回复
热议问题