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.3-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.3-cp312-cp312-macosx_11_0_x86_64.whl (971.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

fstd-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (835.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fstd-0.1.3-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.3-cp311-cp311-macosx_11_0_x86_64.whl (970.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

fstd-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (834.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fstd-0.1.3-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.3-cp310-cp310-macosx_11_0_x86_64.whl (968.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

fstd-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (833.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fstd-0.1.3-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.3-cp39-cp39-macosx_11_0_x86_64.whl (968.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

fstd-0.1.3-cp39-cp39-macosx_11_0_arm64.whl (833.8 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63ef6b8aaf64fc4ac7a8cfcfbe5ff438fbf6fb514ede103afce6dc379e666f41
MD5 40d246292c63fdd8eecb7a9831986140
BLAKE2b-256 885957dacbf7323b2529fb4eed633be56c1818d99091a4fcb8d03e2ed0189a1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ec08cee9bc53d18f33cbf253f14f8a046f70a531f2c85f08e9f32c1f88ba5aaa
MD5 04fbf3ca4f4bd04224cd0d90c9abf2ea
BLAKE2b-256 e1b15a96c6b537ccf64236670ce25bcd0eafb4c5e3702285a732fd1a8ff9744b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a64c10688641001f13a32f932f1f0dae1453475a13fc56af7ac22434082bcc0
MD5 dbfaf28f8ac4a8f27d0f59ab8fc295d1
BLAKE2b-256 38e3b211832be7e9b4fdbffb6984e41c62295099126f387fa307d92821a1aab9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99e444b7f5d1653bc554e9790bd2302ed06a19b11f34ec064c8f048a6cdcf456
MD5 f5eb3f13366d408fad6c51b130bff2c0
BLAKE2b-256 74c8472fe434491d0154ded5468459974172a2a317bc57921f5a1bbf4aee5834

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 d253ca2ac59c01bdc6752a25a040592078a40939d4f04b935eff4e1ce5b7621f
MD5 46eaf394f5a73db0ade417a01ac0a6b1
BLAKE2b-256 180cbeaba787bc5e01c45f2179237688bb56eef036d4e9212c6967c747b025c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa0d9bef46755497037f51e8df50d6a7585d84a3f38bb33ee8f8fa4ad790a8e0
MD5 8f3f70ea9baaac329beea44dec5a009a
BLAKE2b-256 fa7287f00dddfeffe84272e7b12c7537d2ee5e73f5b297d3a2c386f86991777f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8dff67874350030f3db56ab6d74f27add24ec51be75478c1b73cad7083252d8
MD5 32f69614f252814882ee85e5888322d8
BLAKE2b-256 29341d49a6a550249bd9172d1940d5e503bad5bb20e034753c9579eb8ec3d344

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 a32feeee0166492ed95709d65702d965a8351997c2c3fd4bd5fe39dff9973c58
MD5 7d4b876b3c9f9cc6cbe8c616f0b369ac
BLAKE2b-256 7d976d513919f4fba25bbaf5373f927dee1f208bcae82cd8c2305d25f8f07d0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d709b4c59422491df10798eef9f26e33629f2d8a3a9cb90ff840ad8da394e27
MD5 32396290418b6b79d3378dd7f981d27b
BLAKE2b-256 78445a295bd0999707158302a3c3b25a5a1c42ce2f862f57d7e56b129681ba4e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fstd-0.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f27a974366f97db45dea2cdff52c9ccf31db40916e3772bef5ee99cbecf1833
MD5 fa6aa1568a8e8f7dd3a357f161d08c7e
BLAKE2b-256 0d81dfd5139621658c3b3432bb9a256060979ec4d55e1628f74d27980bfde7b9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fstd-0.1.3-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 968.5 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.3-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 96061c5550f4f035c6da5fdaf92ee8debfcea80cc9472ebbca4f47f09be2b063
MD5 8ac733559225d48991e5c589dd54e8f0
BLAKE2b-256 097c57ee2c2b317cc6775fd5283cfe7c57d657f7e4ce633766e80e2f30ed7906

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fstd-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 833.8 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.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c8c086572c5d1f0960f2840fa8701dc81e664c3fd9f4588322f8fd06e615aec1
MD5 40ea6e621854f6c50dc1411527fee736
BLAKE2b-256 ea6c5312299802d075373a6489b2f85a42d9ce676265df90ab4eab8e735f471d

See more details on using hashes here.

Provenance

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