Giter Club home page Giter Club logo

sqlite3-ngram's Introduction

sqlite3-ngram

ngram is a SQLite3 FTS5 n-gram tokenizer, it tokenize the input text in computational linguistics level.

For the input text Hello 新 世界:

  • ngram = 1

    Hello, , ,

  • ngram = 2

    Hello, , 新世, 世界

  • ngram = 3

    Hello, , 新世, 新世界

The tokenization is based on UTF-8 character and character category boundary.

The ngram currently support is in range [1, 4], larger ngram can be supported but it's usually unnecessary.

This tokenizer extension can be used as a fallback(generic) tokenizer for FTS purpose.

Build

# Tested under podman, docker should also be ok.
container/build.sh

Usage

-- First load the ngram extension
.load build/libngram.so
-- By default N = 2, valid N is in range [1, 4]
CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize = 'ngram');
CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize = 'ngram gram N');

-- Or check sql/load-ext.sql for example usage
-- sqlite3 < sql/load-ext.sql

Advance usage

You can integrate this tokenizer with the SQLite3 official porter tokenizer:

.load build/libngram.so
CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize = 'porter ngram gram N');

In such case, if you tokenized the word direct. directed, directing, direction, directly... all can be coalesced into direct and thus hit a match.

Limitation

Currently only the UTF-8 string is supported for tokenization, usually not a big concern though.

Credits

This project was inspired from the following projects:

wangfenjin/simple - 支持中文(简体和繁体)和拼音的 SQLite fts5 扩展

TODO

  • Implement ngram_highlight() function
  • Add more test cases
  • Enable build & test CI

sqlite3-ngram's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dromozoa

sqlite3-ngram's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.