Skip to main content

Lattice Path Edit Distance and romanization-aware string comparison

Project description

mòine

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.
  • 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:

uv run python -m moine download ja
uv run python -m moine download zh

moine download ja
moine download zh

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

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 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.1.1.tar.gz (97.7 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.1.1-cp314-cp314-win_amd64.whl (529.5 kB view details)

Uploaded CPython 3.14Windows x86-64

moine-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl (692.5 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

moine-0.1.1-cp314-cp314-macosx_11_0_arm64.whl (625.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

moine-0.1.1-cp313-cp313-win_amd64.whl (529.4 kB view details)

Uploaded CPython 3.13Windows x86-64

moine-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl (692.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

moine-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (625.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

moine-0.1.1-cp312-cp312-win_amd64.whl (529.7 kB view details)

Uploaded CPython 3.12Windows x86-64

moine-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl (693.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

moine-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (625.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

moine-0.1.1-cp311-cp311-win_amd64.whl (532.6 kB view details)

Uploaded CPython 3.11Windows x86-64

moine-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl (697.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

moine-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (628.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for moine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d3f30fba67ddc473dba1893cd5a46e20d263ba4bc56f3002339edb13b3fd2dc
MD5 487382254ffb9d00df4a1bc4fe2e96b1
BLAKE2b-256 281cc45484a2bcac840bc8d5d2a069f012601c72edf9ae9ce9a88453c9a15ec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1.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.1.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: moine-0.1.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 529.5 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.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 faae76b02189fe1f85db11706c150f7994efddc4c3d7bc31add7cda4ee987f1a
MD5 077bb33dd1bbd35f82c5421bc8382028
BLAKE2b-256 7dbd4c5ec867e544ed21be258f69ea08354ae2ac5349fcec722f48b5c5b975b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db62c24e8dd379857bf98f1b556dd6fa7f25e097c54a92dd91cfe8b50b3cc99f
MD5 48d6ce49a70983e1b9c566e70011713f
BLAKE2b-256 588f3fc7570e9217cb451996a53518706ce33c9768bf1c2b3468cca710762e4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4698919ad82c5c3c598c370290d2cdada4df018196554499494917b6b70dab87
MD5 4c53a0214d42218cbe8414881e2174cc
BLAKE2b-256 e6aba28fec7b3b721f4077beeab27dda635a4f5a47443a6fed61cd2c69b28349

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: moine-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 529.4 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.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0869179db832e16c3b69fed86c07a64380ab905b6cd9ab983df3cb17443d0899
MD5 972e73713cc649c2ca1e29e5c8c42c5b
BLAKE2b-256 4df337d6103bacfdd9cf741df8474b0d71df0dfc4551113a4ac37163911f08cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 15a907a2c0d127a7d4bfa63461b077efb0b53c4ece59271f111a55d34a4502bc
MD5 415628d28a6036ca15683c0d8be845b2
BLAKE2b-256 4113a4eaaaa38ca9301a7a58b8933f27fbe0f79d92fb75664b39d07da51a680a

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b31c0e4ca02d5d3e7ce003b02500c30ac7cec731d357e04c316647ea550d2e7
MD5 98761aa3a5844dfc8d65e92d4d5e227b
BLAKE2b-256 5f149cd751788cc260dc7e29272d0b83e8ac218fc4f837208edeeea51b67349a

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: moine-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 529.7 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.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9fccdefd96e9f1806c2dfe97b0c28758defd379a92aab9991f2fde44ace8b5a8
MD5 76943ae87a5dc09d8f80a8c9751c4f98
BLAKE2b-256 eea44835e7b850957e98e01748ea3b63e0cf5dd679735d9da100d854cfa72e18

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a2d6e09a22799b3cec4f047175894e81627e69df36c6057fc8f58f7bca17172
MD5 b98fc498ded14010c52a1537b6ccf6f5
BLAKE2b-256 b8ed3e692cf3e1caa4c165b256596bd167f444dd355916c749997c0be60d26e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c9954b020c6091507aa07aeaf5e3c1c72e154d91f63f474687275688423a334
MD5 cff29a467e45dd1d16e781a53b6b231c
BLAKE2b-256 13910579422ddf9037c9cd5ad1adbedb1c29757752ed6d02dafaa0d990b94ee7

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: moine-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 532.6 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.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 23118de1c154d2cf7f5693c4c6593b5e0e5f060d9597992f0a1320fc8ce8a2fe
MD5 5f967b064dae9109b7ca22027370bdc0
BLAKE2b-256 4e6e09337f61c43758cf10240dd50a3a3b02991dab0dd7582d1c816a755863e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 70f6e65d9d09363d4e97714938631530fb559b581c21277228fa580299345aee
MD5 1277cf8ff2d6bddc55f2aeabf76d4e75
BLAKE2b-256 38c106eaca40c7cde01ee14b118e69c1ae324eeb17364878766bbc587d08407a

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moine-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 401a35ee01559b4ccf6d18ccbe4f1f8bf759da58cc467b261c78c6f7894427ac
MD5 2cf1849eefb8113c5c954979547bb173
BLAKE2b-256 7f54e00b8531974e6e508f350c31f7c6b9d7c089673f9dd827448f7aff231cf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for moine-0.1.1-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