Skip to main content

High-performance dictionary engine based on FST

Project description

fstd

A dictionary engine powered by Finite State Transducers, a data structure that enables us to search in dictionaries with many ways, including regex, suggesting based on edit distance, other than just prefix search powered by trie data structure used by traditional dictionaries. Fstd dictionary provides two format file: fstdx and fstdd , which is similar to the popular dictionary format: mdx and mdd. A converter from mdx/mdd to fstdx/fstdd.

Features

  • Multiple threads are supported to offer high-performance search and dictionary compilation.
  • Regex search.
  • Fuzzy search: suggest candidates sorted by the similarity calculated by edit distance to input keyword.
  • Prefix distance search: provide candidates sorted by the distance calculated by common prefix and prior suffix. By providing prior suffix, it can top the candidates that has a longer common prefix with input keyword and has a prior suffix. It's useful to help us find the simple form of an verb in a language whose verb has some constant suffix, such as Japanese ("する", "う", "く", "ぐ", "す", "つ", "ぬ", "ぶ", "む", "る", "い") or Korean ("하다", "다"). However, it's not always effective in all cases.
  • Prefix search(predictive), a way as the same as traditional dictionaries can provide.
  • Esay to convert from mdx/mdd to fstdx/fstdd.
  • Data related to dictionaries is compressed to reduce disk usage.
  • Low memory usage and high-performance search, as the FST made by compiling entry words of a dictionary is loaded into memory to support high-performance search. FST is a data structure providing a better compression rate than trie, because it can not only compress common prefix but also common suffix.

Install

It has been tested on Macos and Linux platform now. On Windows platform, there might be a bug when launching a thread pool. It's not convenient to fix it because I don't have a windows machine. Pull a request to me if you can fix it.

Install from source code

  1. Install dependence

    brew install cmake googletest indicators spdlog fmt zstd pcre2 nlohmann-json cli11
    
  2. Compile and install

    git clone https://github.com/MouJieQin/fstd.git
    cd fstd
    mkdir build && cd build
    cmake ..
    make install -j8
    fstd -h
    
  3. Run test

    make check
    

Usage

  1. Compile fstdx/fstdd

    # go to the project directory
    cd fstd
    # use default configure to compile a fstdx
    fstd write -f tests/dict/dict.txt -o dict.fstdx
    # use default configure to compile a fstdd. Note: fstdd normally include resource data, such as pictures and audios, but we use the project lib directory for test.
    fstd write -f lib -o dict.fstdd
    

The raw content of tests/dict/dict.txt :

  1. The first entry requires no preceding delimiter: write the entry word (key) directly, followed by its corresponding definition (value). Definitions can span multiple lines, but entry words must stay on a single line.
  2. Starting from the second entry, each entry word (key) must be preceded by the delimiter </>. Entry words must still be written on one line, while definitions can span multiple lines.
  3. The end of each complete entry (entry word + corresponding definition) must be marked with the delimiter </> as a closing tag.
Ab
The definition of Ab
</>
Ababdeh
The definition of Ababdeh
</>
Abby
The definition of Abby
</>
...
  1. Search in a fstdx

    # show meta data
    > fstd search -m dict.fstdx
    {
      "Compressionlevel": 5,
      "Creationdate": "2026-06-28",
      "Description": "",
      "Encoding": "UTF-8",
      "Format": "Html",
      "Keycasesensitive": false,
      "Left2Right": true,
      "Record": 23603,
      "Stripkey": true,
      "Stylesheet": "",
      "Title": "",
      "Version": "0.1.0"
    }
    
    # exact match search
    > fstd search 'Ababdeh'  dict.fstdx
    ------------------------------
    The definition of Ababdeh
    ------------------------------
    
    # regex search
    > fstd search -r 'di.*na.*y' dict.fstdx
    dictionary
    disciplinability
    disproportionality
    disproportionably
    
    # suggest search
    > fstd search -g 'dicioa' dict.fstdx
    dictionary -> 0.544
    dilo -> 0.438889
    diol -> 0.438889
    radicicola -> 0.42
    decoat -> 0.4
    disc -> 0.303704
    io -> 0.185185
    coca -> 0.175926
    
    # fuzzy search
    > fstd search -e 5 'dicionary' dict.fstdx
    congiary
    dictionary
    donary
    missionary
    ordinary
    
    # enumerate all entry words in a dictionary
    > fstd search -u dict.fstdx
    Ab
    Aberia
    Abelite
    Abietineae
    Ababdeh
    Abby
    Acanthodidae
    Acarus
    ...
    
  2. Search in multiple fstdx

    It's just an example of showing how to search in multiple fstdx dictionaries. The project does not provide the following fstdx files.

    # Prefix distance search in multiple fstdx dicionaries
    >  fstd search -P 2 振り返ってみます -f lj.fstdx -f dcq.fstdx -f hgy.fstdx
    振り返る
    振り
    振り乱す
    振り仰ぐ
    振り出す
    振り切る
    振り合う
    ...
    
    > fstd search -P 2 알아보겠습 -f lj.fstdx -f dcq.fstdx -f hgy.fstdx
    알아보다
    알아보
    알아보-
    알아내다
    알아듣다
    알아먹다
    알아주다
    알아채다
    알다
    ...
    
  3. Extract a file from a fstdd

    # list all keys of a fstdd
    > fstd search -u dict.fstdd
    include/fstd/common.h
    include/fstd/fstdd_compressor.h
    include/fstd/fstdd_reader.h
    include/fstd/fstdd_writer.h
    ...
    
    # extract include/fstd/common.h from the fstdd to the data directory
    > fstd extract -k include/fstd/common.h -o data dict.fstdd
    

API reference

namespace fstd {

class FstdxSearcher {

public:
  FstdxSearcher(size_t worker_num = 0);

  FstdxSearcher(const std::string &meta_json_path, size_t worker_num = 0);

  operator bool() const;

  bool extract(const std::string &name, const std::string &file_path,
               const std::string &dst_dir) const;

  bool extract(const std::string &name, const std::string &file_path) const;

  bool contains(std::string_view word,
                const std::vector<std::string> &names) const;

  std::vector<std::string> search(std::string_view word,
                                  const std::string &name) const;

  std::unordered_map<std::string, std::vector<std::string>>
  search(std::string_view word, const std::vector<std::string> &names) const;

  std::vector<std::string>
  common_prefix_search(std::string_view word,
                       const std::vector<std::string> &names) const;

  size_t
  longest_common_prefix_search(std::string_view word,
                               const std::vector<std::string> &names) const;

  std::vector<std::string>
  edit_distance_search(std::string_view word,
                       const std::vector<std::string> &names,
                       size_t edit_distance = 1) const;

  std::vector<std::string>
  predictive_search(std::string_view word,
                    const std::vector<std::string> &names) const;

  std::vector<std::string> suggest(std::string_view word,
                                   const std::vector<std::string> &names) const;

  std::vector<std::string>
  prefix_distance_search(std::string_view word,
                         const std::vector<std::string> &names,
                         size_t max_distance) const;

  std::pair<std::vector<std::string>, std::string>
  regex_search(std::string_view pattern,
               const std::vector<std::string> &names) const;

  void insert_prior_suffix(const std::vector<std::string> &sufs);

  void insert_if_not_exists(const std::string &name,
                            const std::string &fstdx_path);

  bool insert(const std::string &name, const std::string &fstdx_path);

  bool save_to_disk(const std::string &meta_json_path);
}
}

Reference

Based on cpp-fstlib by yhirose.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fstd-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fstd-0.1.5-cp312-cp312-macosx_11_0_x86_64.whl (971.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

fstd-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (828.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fstd-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fstd-0.1.5-cp311-cp311-macosx_11_0_x86_64.whl (969.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

fstd-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (828.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fstd-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fstd-0.1.5-cp310-cp310-macosx_11_0_x86_64.whl (968.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

fstd-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (827.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fstd-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fstd-0.1.5-cp39-cp39-macosx_11_0_x86_64.whl (968.7 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

fstd-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (827.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file fstd-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7fc47121416752ec65eab76c47de661443287208a917d893b373430c4e31e540
MD5 18b358ebca5a430ad2b439db034348dd
BLAKE2b-256 16d592372c9b89d1c20e7e50b50186e50d0189813d010a0b3d479e50763bf6dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 1d550c61b60cc335391894f822d83dbfb8ee4695ad698d8db5cdaab43935bd86
MD5 8fcc17805feab04747b21895ca36cb25
BLAKE2b-256 a2257254c5e0906b824467e93b42aba32bd26f91528871d6191421b8f097ea4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp312-cp312-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33b6337318364409752ebc3601c7ce23a2cc2dca6a54f5a9fae291f0d7f37bff
MD5 25137ac90576b618784d872ebe9a4628
BLAKE2b-256 a367a9538bfc5f47e6fd1d7a7f04846dfb486c1d6ec36bdf3f278eba2eb13868

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f853820a409a7954e90e5873fac11aa43a671ee876bd99e36455d949b902580
MD5 75c9738df6d842a9447b997c441787d4
BLAKE2b-256 b8681c1415ff991d680fbd85914c7b664145c1703be26d1b8ef665bf2120b478

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ba8c6eb2becf49abf8015760354da68f6653cd0f29c4fb0d3303ee87b810464e
MD5 366d4b2c52e3db4353b5b664f4479e45
BLAKE2b-256 1ad982733eed6d07822f0403843d0b3a84a1269c30f6a4d4bc089be92ebba6b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp311-cp311-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72ea4137f37cd56deb8879ea055ec7bd58c90a1f00644d154e9a7dc9be94a547
MD5 f95f22d7f3e751087ea3e1a070f52627
BLAKE2b-256 8434a6dd721eb0ccd846ebe2dfb71ee5a3d2b99b6337e1475b607d63fac929fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c8cda34e7e62a84254396c06652c329bb759feb06dd08af101c7239ccb69ffe5
MD5 0a0dbecfb38f904e6d2ecdbc450334ef
BLAKE2b-256 4dbe060be6ca0221ed3ea6b52db169ff1492b8ebed0ebd739ed7a53e0cb221a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6aa6003641a95066ec83159d7add934007411ea723d2016480e7ae71e488ef96
MD5 e9ce956f04e42d3f47e5fb4d636a7af0
BLAKE2b-256 51d258222801157dc5a71e9414200fa7b6800a643ebc25a5424ccfec0d619db1

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp310-cp310-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abb0852f50b1a6a99fe749bba3de21e474e45cd98095c4819fbe49bab8c98f4f
MD5 1a18ec511cd84fee55ecf41f6229577e
BLAKE2b-256 edfc9e2e3206761ec52de71ce016cfa08aaf6ec8ddef930bed842b10f9abd79a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ca193ca9cfb1f090bd12c198337ad4a118c27463fca0ad5e720451732fb5254
MD5 17340e842d4ecc73d04842180f3f627b
BLAKE2b-256 29514445b14d1375e68fe3e28154d86c7780e41be13c9c19d49390ada878e2a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: fstd-0.1.5-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 968.7 kB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fstd-0.1.5-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c392b9ba16076a699b75bc640d5d82fb114da1f14b7f46f694fe98844a9c6e2a
MD5 0ac3d8abeefca2befab55044c3594236
BLAKE2b-256 e982e4f8887152a33c45a52a422f5653ac1915110836e458f5a33a9f6b536dc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp39-cp39-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fstd-0.1.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fstd-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 827.4 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fstd-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1464961fc5c906f86aa066098f6d63d04325ac4a6b19d6c373faf066f1e9281b
MD5 a46a9486f46bd82a31420e3b2d62f92b
BLAKE2b-256 39c2768088a902a737443d2d898686e16b33e7fec80a4c27f8193b38691f4880

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.5-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: wheels.yml on MouJieQin/fstd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page