Skip to main content

Lattice Path Edit Distance and romanization-aware string comparison

Project description

mòine

CI PyPI crates.io docs.rs

mòine is a Python and Rust library for romanization-aware string comparison.

It implements Lattice Path Edit Distance (Kaji, 2023), a distance metric that compares strings through possible reading paths rather than only through visible surface characters.

This is useful when romanized input and written Japanese or Chinese look far apart as strings, but stay close in reading space.

>>> import moine

>>> moine.distance("moine", "モイニャ", lang="ja")
2

>>> moine.distance("もいにゃ", "モイニャ", lang="ja")
0

>>> moine.distance("weishiji", "威士忌", lang="zh")
0

>>> moine.distance("布納哈奔", "布納哈本", lang="zh")
0

Name

The project name comes from Moine, a peated malt from Bunnahabhain and one of the developer's favorite Scotch whiskies. In Japanese, the name has several plausible katakana renderings, such as モイニャ, モーイン, and モアンヌ, which makes it a fitting name for a project about readings, spelling variation, and ambiguity in input sequences.

Features

  • Japanese comparison with UniDic-CWJ-derived reading artifacts and separate SudachiDict-derived artifacts.
  • Chinese comparison with CC-CEDICT-derived no-tone pinyin artifacts.
  • Plain string Levenshtein-compatible distance helpers.
  • Lattice-aware Damerau-Levenshtein distance for adjacent transpositions.
  • Normalized similarity / ratio helpers in 0.0..=1.0.
  • RapidFuzz-inspired APIs such as cdist and partial matching helpers.

When To Use

mòine is best used after another system has produced candidates: lexical retrieval, n-gram search, BM25, embeddings, a product catalog, or an entity list. Use mòine to rescore those candidates in reading space.

Good fit Poor fit
Romanized, kana, kanji, or pinyin input mixed together Same-script typo matching only
Query correction, search suggest, and candidate reranking Replacing a full search engine
Japanese and Mandarin pinyin Chinese entity matching Cantonese/Jyutping or arbitrary languages
Pipelines that can download dictionary artifacts explicitly Install-only workflows with no data step
Hundreds or thousands of candidates after retrieval Brute-force scoring over a whole corpus

Installation

Install the Python package:

pip install moine
uv pip install moine

Install the Rust command-line tool:

cargo install moine

The packages do not bundle dictionary data. Download the language artifacts you need explicitly:

# Default Japanese artifact: UniDic-CWJ
uv run python -m moine download ja

# Explicit Japanese sources
uv run python -m moine download ja-unidic
uv run python -m moine download ja-sudachi

# Chinese artifact: CC-CEDICT
uv run python -m moine download zh

# Same selectors are available from the Rust CLI.
moine download ja
moine download ja-unidic
moine download ja-sudachi
moine download zh

ja is the short default selector for the current Japanese artifact, which is UniDic-CWJ. Use ja-unidic or ja-sudachi when the dictionary source should be explicit.

Quick Start

Use the top-level Python API when you want mòine to load the default dictionary for a language:

import moine

print(moine.distance("もいにゃ", "モイニャ", lang="ja"))  # 0
print(moine.ratio("ピィート", "ピート", lang="ja"))  # 0.7142857142857143
print(moine.partial_ratio("ウイスキー", "ういすきーをのんでいます", lang="ja"))  # 1.0
print(moine.distance("weishiji", "威士忌", lang="zh"))  # 0

Load a dictionary explicitly when you want to control startup cost or artifact location:

import moine

dictionary = moine.load_dict(lang="ja")
moine.set_default_dictionary(dictionary)

print(moine.distance("もいにゃ", "モイニャ", lang="ja"))  # 0

Use cdist for query-by-choice matrices:

import moine

scores = moine.cdist(
    ["もいにゃ", "ぴーと", "ピィート"],
    ["モイニャ", "ピート", "ピーと", "ピィート"],
    lang="ja",
    metric="damerau_distance",
    score_cutoff=1,
)

For search or entity matching, generate candidates with your existing system and use mòine as a reading-aware reranker:

import moine

query = "moine"
candidates = ["モイニャ", "モーイン", "モアンヌ", "ストイーシャ"]

scores = moine.cdist(
    [query],
    candidates,
    lang="ja",
    metric="distance",
)[0]

ranked = sorted(zip(candidates, scores), key=lambda item: item[1])
print(ranked)
# [('モイニャ', 2), ('モーイン', 2), ('モアンヌ', 3), ('ストイーシャ', 7)]

Score interpretation is intentionally simple: distance=0 means the best reading paths are identical, distance metrics are smaller-is-better, ratio and normalized_similarity are in 0.0..=1.0 and larger-is-better, and score_cutoff filters in the RapidFuzz style.

Command Line

Most users only need the public runtime commands:

moine download ja
moine download zh
moine list
moine where
moine compare --left "もいにゃ" --right "モイニャ" \
  --artifact-metadata /path/to/moine-unidic-cwj-202512/metadata.yaml
moine chinese-compare --left weishiji --right 威士忌 \
  --artifact-metadata /path/to/moine-cedict-20260520/metadata.yaml

Use moine download ja-unidic for explicit UniDic-CWJ and moine download ja-sudachi for SudachiDict-full.

The artifact bundle, verification, archive, and diagnostic commands are maintainer-facing tools for producing and checking release assets. They are documented in docs/development.md and docs/release_process.md.

Japanese comparison diagnostics can emit romaji lattice graphs with --romaji-lattice <PATH> --output-format <dot|svg|png>. Writing SVG or PNG graphs requires the Graphviz dot command to be available in PATH; DOT output does not require that runtime dependency.

Documentation

Developer and maintainer notes live under docs/, starting with docs/development.md and docs/release_process.md. See CONTRIBUTING.md before opening pull requests.

How It Differs From RapidFuzz

RapidFuzz is the better fit when both inputs should be compared directly as surface strings and you need a broad set of highly optimized fuzzy-matching scorers. mòine focuses on a narrower problem: comparing strings through possible reading paths before edit distance is computed.

Limitations

  • mòine does not reproduce the original paper's private search-query-log evaluation.
  • Dictionary-backed comparison requires separately distributed dictionary artifacts.
  • UniDic matching intentionally does not use MeCab/Viterbi costs.
  • Chinese support is Mandarin pinyin only; it does not model Cantonese/Jyutping or non-Mandarin readings.
  • processor, score_hint, NumPy dtype options, and worker parallelism are not part of the initial cdist API.

Reference

[!CAUTION] This project is not the official implementation by the paper author.

@inproceedings{kaji-2023-lattice,
    title = "Lattice Path Edit Distance: A {R}omanization-aware Edit Distance for Extracting Misspelling-Correction Pairs from {J}apanese Search Query Logs",
    author = "Kaji, Nobuhiro",
    editor = "Wang, Mingxuan  and
      Zitouni, Imed",
    booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing: Industry Track",
    month = dec,
    year = "2023",
    address = "Singapore",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2023.emnlp-industry.24/",
    doi = "10.18653/v1/2023.emnlp-industry.24",
    pages = "233--242",
}

License

mòine source code is licensed under either MIT or Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.

Dictionary data is separate. UniDic-derived, SudachiDict-derived, and CC-CEDICT-derived artifacts carry their own license and attribution metadata, and should keep dictionary license information separate from the mòine source-code license. See THIRD_PARTY_NOTICES.md.

Project details


Download files

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

Source Distribution

moine-0.2.0.tar.gz (101.6 kB view details)

Uploaded Source

Built Distributions

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

moine-0.2.0-cp314-cp314-win_amd64.whl (529.1 kB view details)

Uploaded CPython 3.14Windows x86-64

moine-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl (695.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

moine-0.2.0-cp314-cp314-macosx_11_0_arm64.whl (623.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

moine-0.2.0-cp313-cp313-win_amd64.whl (527.9 kB view details)

Uploaded CPython 3.13Windows x86-64

moine-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl (695.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

moine-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (622.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

moine-0.2.0-cp312-cp312-win_amd64.whl (528.4 kB view details)

Uploaded CPython 3.12Windows x86-64

moine-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl (696.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

moine-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (623.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

moine-0.2.0-cp311-cp311-win_amd64.whl (531.2 kB view details)

Uploaded CPython 3.11Windows x86-64

moine-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (700.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

moine-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (625.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file moine-0.2.0.tar.gz.

File metadata

  • Download URL: moine-0.2.0.tar.gz
  • Upload date:
  • Size: 101.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ad97ee5c6ca5d673bc57ad699f9953689a43fd90704a61abf88eef66ff3a4e9b
MD5 afe8ed312a93f47f13be7d7bc5129e5c
BLAKE2b-256 17d86ad665819a002685c82ed3ba42beb2d8a334bc27ccd12beb6ac9e25350ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0.tar.gz:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: moine-0.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 529.1 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moine-0.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c498cda4ef3cc0b5b38ea643e87067c98cf0ba5067664bae2972581d3b645e18
MD5 b9268a79902829054fcea03fefd8f25b
BLAKE2b-256 b9ae657c2a053aa216cc1feba9e4e7b7d3f5518bf1d88bbe7527b634906e568c

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp314-cp314-win_amd64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6766c0e53213aa706ee3f401f8a873a8bd2dad1298dc85d2361f3a608fad4f46
MD5 5a667ea6ef5355c048b1193b14b7a2d4
BLAKE2b-256 6e8283af9360a22f9942dabcde0cff13dc70f7446d33323959bcbafbe2d25b84

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abb2812b060182843b5fe4b02d0d0ebec47d45418c88320fa9c4795fdb1ebb89
MD5 a2e25fb0c9110793d205af0313c828b1
BLAKE2b-256 de3130bdc745697d6e5b842390cae165661806d5804638c5de2793ab56cd9086

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: moine-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 527.9 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moine-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d27da159bd2308c10d3d7ee54736cb3cfcbdc391845a3dacbb0297607758712a
MD5 bbd46c78dc2f485d03ef5741ef2d9a1f
BLAKE2b-256 532bf977bfde7fac072f39c4a3e7b0f336ea4f0048f235a5992825150f6e82ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7f93c0464e4ed22bc7ef40b858d3a764548a7b5ddc8e56221d6205e46eacbb62
MD5 12df904f8fce7797f986047669b7ff8b
BLAKE2b-256 dfe0e04fc0ff215fcc07ee0aff3232cfb1efb3b51f020ba3c207e318e0bc264a

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 859e582b4335785522b28668c841bd864682dc4e9715eeced6c8b17a5ea283be
MD5 3b84668f6144112c126c71a9dece87c4
BLAKE2b-256 871e71999261ffa99ba5dfaf0d188fca007897ad5ee59d4495e6198874731417

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: moine-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 528.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moine-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 614314bad2751e1cdc95ce477cf29f0f78410b3a7fb103eecb63ec61b23ec1e1
MD5 2d8f26108c2a86bef41a2ebbc2680f50
BLAKE2b-256 e4dcece1220e9521fd5a5e97d1043780c2cd6090de05dc7e4b15d31023416710

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 be97332828c686c3fe88a180da99870af40ce203b03617128189f791d82628d2
MD5 300bf8f1ab87177b63f2d9d15cad1eea
BLAKE2b-256 34760b0ac9d97357c6d1560c20d393727b587235084821f8feb82126de905d56

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dbf6f6aef6407aec4bf685a6e38d066a08a935c790d023131d06176b8d333d48
MD5 8147167b53da73471ab42df270b47273
BLAKE2b-256 8c2b22b8d9888a9e1b65dfd57c9437a0145c1944d7a42d6bf5ea7e2e43784fc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: moine-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 531.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moine-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 abac5457e322aa46ea3a392b7cf50d854cb9efb26c6b8759abe98a09c56146ff
MD5 ed7e5a3a6c511218b378c5daa54eee0c
BLAKE2b-256 4dac1b2d118405228883c416ce5b863225149d18a60d6a186370b1f8e588530e

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5fdcbc5840af310e0bffd4106f57426c4b62f513db63f5c9702eae030516aad
MD5 af20f38995e4d6b8a9326867a514acf5
BLAKE2b-256 705ea4ad8daede7456d81babeae941f44b2c6ee1ac8eaf62d4714d806ba8ddf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: release.yml on tagucci/moine

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

File details

Details for the file moine-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a444f77caad49a2360f225a44073a4c7a0d05151071270942e0f23f016096f6e
MD5 f7e121a7647afa5b9312bbcc41626cc9
BLAKE2b-256 a14365014ec8ec125729d4e7c695270f1baa78aa2d3cc7b1e636ca871b0f9951

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on tagucci/moine

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