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 fstdtools that can convert 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.
  • Python support by pip install fstd

Install

It has been tested on Macos and Linux platform now. On Windows platform, there might be a bug while 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.

It's recommanded to install a python command line tool fstdtools by pip install fstdtools. Because it offers a safer and more friendly usage than the CLI compiled from c plus plus.

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
    </>
    ...
    
  2. 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
    ...
    
  3. 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
    알아보다
    알아보
    알아보-
    알아내다
    알아듣다
    알아먹다
    알아주다
    알아채다
    알다
    ...
    
  4. 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.6-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.6-cp312-cp312-macosx_11_0_x86_64.whl (988.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

fstd-0.1.6-cp312-cp312-macosx_11_0_arm64.whl (850.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fstd-0.1.6-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.6-cp311-cp311-macosx_11_0_x86_64.whl (985.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

fstd-0.1.6-cp311-cp311-macosx_11_0_arm64.whl (849.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fstd-0.1.6-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.6-cp310-cp310-macosx_11_0_x86_64.whl (983.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

fstd-0.1.6-cp310-cp310-macosx_11_0_arm64.whl (848.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fstd-0.1.6-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.6-cp39-cp39-macosx_11_0_x86_64.whl (983.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

fstd-0.1.6-cp39-cp39-macosx_11_0_arm64.whl (848.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for fstd-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 672a308e5e140f13f7a368d9ebf03760412d2d34857010bb340d5c8a449b9e06
MD5 c23d1e5ad5d8d00881b7644cb89ea102
BLAKE2b-256 8db5e54878c659b0be9a349f8971f4ada03ee68695acac8226e3903e2d34edb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f59cc75978e7f797c8b42363f0e1a278f2fe671c0b45f7477b4d83ca5501e435
MD5 de7ff19ac3fe8d6f7ee26a5ea65bc0ee
BLAKE2b-256 6819537ef3ddb5a4ee50157f61b921ccb0f53c7616df78acf3baf5c21bd73325

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6aee969ff4033b2ed8b0681be70af31bb070fab25e28fc3b4d47506c34709c16
MD5 1316a768614e16763dd0610484cdc207
BLAKE2b-256 e10191314eff894dd19b4c1fd5f91b0c67d35885df02e1eabe228a1d963e5852

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0cfc6f1f9a04a4eb61d55e9131768cedba47a0fe1cd4a7de92e591be05d06736
MD5 8640e6873f3ac132ac79299d6b3f6c28
BLAKE2b-256 190b6aed106e8a0204fe6ee23aa85714d046a1270a3ccfe7d5a128653f07a178

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fc64c6caea1045832f796660917c0ae9a2f891a93d6a8e6bbcc8d0230b849363
MD5 6f4664b57e3a426cc46ebfdfa7500d75
BLAKE2b-256 4ac3adef2777707dff0e3d02aae562b30cd055ff65934e280e191bc7c98d3dd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1c09d99da65313cb9abaf0315ba809de7abc0d4be3160113f9067a8c0a63cf9
MD5 0ee14f5ca3772ca381b61dc8a29f778a
BLAKE2b-256 02072d4dd72b5aee4d2e4210880f8945b4511499d66570adafcf68c261fe2533

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2aa40ce463094ec8fb865fa74af943f36e7882a390d15e26c43bfc55c6d27a3
MD5 9907b320bc98e6f52b427228de334447
BLAKE2b-256 1524b1a24e55c27bb1acbabc0f9a0d7e34d41dfe34bf5c88fb941ee1199d0ec2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fb15ad16fb783c6f263750850af52ffa43bc542c5d68be5ca52df6333288a7e2
MD5 c45f59d82396296288fa168a9550c82a
BLAKE2b-256 29d893774cb5e12958584a1270a18bfe207e8dd0c4ffdd4c5de6593653eade11

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bbcfb02cf8604fdd428cb5eb3a558a72dbe2322446435c602d13e40da4eb93d1
MD5 4d03d38b7ef39b4c6832c359a45c5050
BLAKE2b-256 57e0f0086e6499172697fb882ebb8ca05cbc2ba093222b5f57bbb055ef7cf635

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fstd-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be5f26ab0aab6a62e1b2560c0b1f6000d3cc3ffc7901d170af9b92075669db27
MD5 2ceff50214deb695d9c1d08d4345921c
BLAKE2b-256 8b7edb238d1d33633cea8b91189a5d2b358fc7a15ec2d2e544e71b4a78420be2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: fstd-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 983.0 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.6-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 987e009ccb87e08bca72f3ce927c2d876f32f801d19faab58ebd62540aa8134e
MD5 56155ac6db2bc689d9997abdb5ca98c3
BLAKE2b-256 2a90f1c92a270b691b2b078f100120b287ce6616e2eb86c50c842d4c960bae36

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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.6-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fstd-0.1.6-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 848.3 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.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2745850272db1c519bb909e1a76b0ad603ec0563767f4df0cb8f6116f5233b97
MD5 27e8e1ccd8fed72fc10ca8861f9f6585
BLAKE2b-256 9a30e42862dd6e0cd4c690f0b43839e6bd6d153f36034fe506cd4b0cd09682d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fstd-0.1.6-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