Skip to main content

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 (LPED; 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.

With the package installed and language artifacts downloaded:

>>> 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.
  • Combined min(surface Damerau-Levenshtein, LPED) scorer for candidate reranking.
  • Normalized similarity / ratio helpers in 0.0..=1.0.
  • RapidFuzz-inspired APIs such as cdist and partial matching helpers.

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, combined_distance is the minimum of surface Damerau-Levenshtein and LPED, 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.

Dictionary reading expansion is bounded by controls such as max_paths, max_readings_per_segment, and longest_only. When those controls prune candidates, a score is exact for the retained reading paths but may differ from an exhaustive score over every dictionary reading. Candidate retention follows deterministic expansion order; it is not a frequency or probability ranking.

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 raw-dictionary inspection commands are maintainer-facing tools for producing and checking release assets. They are documented in docs/development.md and docs/release_process.md.

The public comparison commands can also emit lattice graphs: moine compare --romaji-lattice <PATH> --output-format <dot|svg|png> for Japanese romaji lattices, and moine chinese-compare --pinyin-lattice <PATH> --output-format <dot|svg|png> for Chinese pinyin lattices. Writing SVG or PNG graphs requires the Graphviz dot command to be available in PATH; DOT output does not require that runtime dependency. See CLI usage for rendered examples.

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.

Benchmark

The scoring table was recorded on 2026-06-28. It reports scoring time only; dictionary loading is shown separately below.

uv run python -m moine download ja
uv run --python python3.14 --with rapidfuzz \
  python scripts/benchmark_distances.py \
  --loops 10000

This is a quick local benchmark command. The release-wheel command used for the recorded table lives in development notes.

Method mean (±std) relative
RapidFuzz Levenshtein 0.15 ± 0.01 us/call 1.00x
mòine ja distance 26.08 ± 33.82 us/call 177x

Fresh dictionary loads from the standard installed artifacts, recorded on 2026-06-28 and measured over 100 loads:

Dictionary mean (±std)
UniDic-CWJ 476.82 ms ± 14.09 ms
SudachiDict-full 2002.83 ms ± 42.17 ms
CC-CEDICT 176.68 ms ± 30.45 ms

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 current cdist API.

Reference

@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.

Metadata

Release files for moine 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moine 0.2.3
File Size Uploaded
moine-0.2.3.tar.gz 121.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for moine 0.2.3
File
moine-0.2.3-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
moine-0.2.3-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
moine-0.2.3-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
moine-0.2.3-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
moine-0.2.3-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
moine-0.2.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
moine-0.2.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
moine-0.2.3-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
moine-0.2.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
moine-0.2.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
moine-0.2.3-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
moine-0.2.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 8.2 MB

Release files / moine-0.2.3.tar.gz

Download URL moine-0.2.3.tar.gz
Size 121.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ae8676b4bc4b755ef6366ac806c76909786889f3b9378f85e8d081aaf07afc40
BLAKE2b-256 checksum
How to use checksums
0196fe23df06aee034d5139be2fb0cad0c97d49f3d0ff3b4e27852696d8af75e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp314-cp314-win_amd64.whl

Download URL moine-0.2.3-cp314-cp314-win_amd64.whl
Size 588.8 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
c89a933232bbc42e7671a92552d32c28436fe7ed2f5709786853328f9a89371e
BLAKE2b-256 checksum
How to use checksums
92908fbcd22b7ad34ee3035fffb423fa1d3bfc96baa2b8511dbe0eca72d7a9f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL moine-0.2.3-cp314-cp314-manylinux_2_28_x86_64.whl
Size 759.3 kB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8f967f2fa970f2eea73796a456469735bd96de6f4dfcebdb70c3bafd99e33cfd
BLAKE2b-256 checksum
How to use checksums
5f81dcd3b9ce5799755d7b807d79d86cc75b1d1aadfea7fe4b7242c0157084d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp314-cp314-macosx_11_0_arm64.whl

Download URL moine-0.2.3-cp314-cp314-macosx_11_0_arm64.whl
Size 681.3 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
87be1aa54f3582aed1ad68118f504637083fc8efa6db0ad2f2fb5ca7743cb3d5
BLAKE2b-256 checksum
How to use checksums
f2b3cec464f3f68cb7be3e571ec5286e8cd75b435398554986a26451591e6169
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp313-cp313-win_amd64.whl

Download URL moine-0.2.3-cp313-cp313-win_amd64.whl
Size 588.3 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
83c2c2bb3bd6abc5dd8fa43388ccf66771e39f46e57dd1f90ff768c12d9e030e
BLAKE2b-256 checksum
How to use checksums
400a617c0ad3e4360f92558acd1afc7f5ce5e60cf1751a8275b6a077715b10a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL moine-0.2.3-cp313-cp313-manylinux_2_28_x86_64.whl
Size 758.1 kB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
dfdd0101cd5dcee4abb07b19e32e78c4c38ee11bcde13ef6aa8ce2b2c6b71f40
BLAKE2b-256 checksum
How to use checksums
61691dbcdae30cb3f4b96f2f5016dc159808270192f51fb691c97d54ad01541c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL moine-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Size 682.3 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e775f71d526595c98073e4c635a854acd1d6b974205379bff8dded0740c14120
BLAKE2b-256 checksum
How to use checksums
2c42feb80231776ab99d82d581a00d72b1b6bcdd3216126e6eefcb692d251745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp312-cp312-win_amd64.whl

Download URL moine-0.2.3-cp312-cp312-win_amd64.whl
Size 588.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
5960f14ecd2c22655d6d634c9991fa09f08d9413cd6f23818808b0ed0b51844d
BLAKE2b-256 checksum
How to use checksums
3362f4eb8a28fb15a1a770141320dfa2651b6a60e128c5715e276559b2c8819e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL moine-0.2.3-cp312-cp312-manylinux_2_28_x86_64.whl
Size 758.9 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f13545e06bfccfaa38aad3539e523efbf9a77412800ffd41d0bf6c24ba95504f
BLAKE2b-256 checksum
How to use checksums
cfd8727051ece219934ef4587def71ff2f8bcb72ce15ac7ebe87ec2e757667be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL moine-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Size 682.5 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
34dbafffb4b370a9bb9158f2c3a2b301197013ff509f6b25725ff8b8a6b167fd
BLAKE2b-256 checksum
How to use checksums
468251dc3bdda949d21a938c22b822743199e5fe7b1df8717c01ecb3ac39d43c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp311-cp311-win_amd64.whl

Download URL moine-0.2.3-cp311-cp311-win_amd64.whl
Size 591.9 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
035fa6663fa4dc432a08878d74ff156c7823e503c67efb8defb8ed235791e3a8
BLAKE2b-256 checksum
How to use checksums
3706034e1083193399c1e27a8454b25f9bff9552f20536cf4f6818be7736bd87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL moine-0.2.3-cp311-cp311-manylinux_2_28_x86_64.whl
Size 762.8 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0eae16380a4131a30fe4fe924b05219151bca2138b85a907bc8b486581a036dc
BLAKE2b-256 checksum
How to use checksums
789884061d4ee3dae8487b5d050d9b1f7e86dd89f0c06ecd4a2153c7e25dbd03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / moine-0.2.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL moine-0.2.3-cp311-cp311-macosx_11_0_arm64.whl
Size 685.0 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7333f2827f4d289c5e946a69971e12896f98f1e7efb6d8bd2d0aa29c5541d7ca
BLAKE2b-256 checksum
How to use checksums
4d28319e728d5cc9707b15781024b94d63fec9e12672760ab70deebebc92c4bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.3 This release

13 release files

0.2.2

13 release files

0.2.1

13 release files

0.2.0

13 release files

0.1.0

13 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page