merkmal
merkmal maps IPA transcriptions of speech segments to phonological feature
representations under several feature systems, and computes dissimilarities
between segments from those representations. This package is the Python
interface and command line of the merkmal C99 library. The extension module,
merkmal._native, is built against the CPython Limited API and calls the C
library for every computation; the package contains no separate implementation.
The library, its method and its limits are documented in the repository.
Installation
python -m pip install merkmal
The package requires CPython 3.12 or later and has no runtime dependencies.
Wheels are cp312-abi3, built with Py_LIMITED_API=0x030C0000.
Usage
import merkmal
merkmal.list_systems() # names of the built-in systems
merkmal.get_features("pʰ") # frozenset of feature labels
merkmal.distance("p", "b") # 0.125, default system
merkmal.distance("p", "b", system="phoible") # another feature system
merkmal.distance_with_coverage("ai", "au") # score, coverage, comparability
merkmal.segment_ipa_merged("tʰoŋ⁵⁵") # ['tʰ', 'o⁵⁵', 'ŋ']
merkmal.merge_tone_digits(["a", "⁵", "⁵"]) # ['a⁵⁵']
Every function that takes system uses merkmal.DEFAULT_SYSTEM
(distinctive) when none is given.
| Function | Result |
|---|---|
list_systems() |
Names of the available systems |
inventory(system=) |
Listed graphemes of a system, in inventory order |
get_features(g, system=) |
Feature labels of a grapheme |
is_segment(g, system=) |
Whether the system recognizes a grapheme; does not raise for unknown input |
diagnose(g, system=) |
Why a grapheme is refused: status, valid prefix, offending text |
distance(a, b, system=, node_weights=) |
Dissimilarity of two segments |
distance_with_coverage(a, b, ...) |
The same, as a Comparison of score, coverage and comparability (alias compatibility_dissimilarity) |
feature_vector(g, system=), vector_labels(system=) |
Fixed-width numeric vector of a grapheme, and its column names |
fixed_space_distance(a, b, system=) |
Mean absolute difference of two feature vectors |
feature_distance(f1, f2) |
Number of edges between two features in the geometry tree |
sound_distance(features_a, features_b, node_weights=) |
Distance between two feature sets in the geometry, without a system |
normalize(g) |
NFC form of a grapheme, with merkmal's IPA rewrites (ʧ becomes tʃ) |
segment_ipa(text) |
Orthographic segmentation: a split at every base character not joined by a tie bar |
system_segment_ipa(text, system=) |
Segmentation by the longest sequence the system recognizes as one segment |
merge_tone_digits(segments), segment_ipa_merged(text) |
Chao tone digits or tone letters merged into the vowel or syllabic consonant that bears them |
split_tone(segment) |
A merged segment split into base and tone |
system_fingerprint(system=), operation_fingerprint(...) |
Canonical description and SHA-256 of a system, or of a system with call settings |
AbstractSegment |
A feature bundle not identified with a grapheme |
Registry |
A registry of systems that also accepts models supplied at run time |
load_geometry(path), geometry_distance(a, b, geometry=) |
Experimental: scoring under a geometry loaded from a JSON file |
node_weights selects a weight preset of the geometry, such as
"ignore-tone"; an unknown preset raises ValueError. feature_distance and
sound_distance take no system, because they measure within the compiled
geometry, which all systems share. feature_distance raises ValueError for a
feature that is not a node of the tree, as many returned labels (bilabial)
are not.
UNICODE_VERSION is the Unicode version of the compiled normalization tables,
and DATA_PROFILE is "full", or "cc-by" for a build without the PHOIBLE
and P-base tables.
Unknown input
is_segment() is the predicate for tokens from external sources. For a
grapheme the system does not recognize, get_features() and distance() raise
ValueError; for an unknown system they raise KeyError. Markup of CLDF and
CLTS sources (<?>, <<->>, boundary markers) raises SourceMarkerError, a
subclass of ValueError, so that it can be handled separately from segments
the system lacks. diagnose() returns the
reason without raising.
Segments derived from listed ones
In the categorical systems (distinctive, descriptive), a sequence that the
table does not list is analysed as one segment where possible: vowel sequences,
consonant clusters, affricates and prenasalized stops written without a tie
bar, precomposed letters of source orthographies, and segments carrying tone.
merkmal.is_segment("aːi³³", system="descriptive") # True
merkmal.is_segment("ñ", system="descriptive") # True
merkmal.get_features("ai", system="descriptive") # includes 'diphthong', 'n1-open', 'n2-close'
merkmal.get_features("st") # includes 'consonant-cluster', 'n1-fricative', 'n2-stop'
A vowel sequence carries diphthong, positional features of each part
(n1-open, n2-close) and features of the movement between them
(move-height-open-close). A consonant cluster carries consonant-cluster and
positional features of each component (n1-nasal, n2-stop), with geminate
for two identical components and pre-nasalized for a nasal followed by an
obstruent (mp, nt). A voiced stop after a homorganic nasal (mb, nd,
ŋg, ɲɟ, ɳɖ) is read as a single prenasalized stop, as is the explicit
notation ᵐb, ⁿd. The policy and system used should be recorded with any
stored tokenization, since neither reading is a phonological analysis of a
particular language.
Models supplied at run time
A Registry holds the built-in systems and any categorical models added to it
in the runtime model format:
registry = merkmal.Registry()
registry.add_model_text("""
@model toy
@type categorical
@geometry clements-hume
grapheme X consonant voiceless bilabial stop
""")
registry.get_features("X", system="toy")
A Registry provides list_systems, inventory, get_features, is_segment,
diagnose, distance, distance_with_coverage (alias
compatibility_dissimilarity), feature_vector, vector_labels,
fixed_space_distance, system_segment_ipa, system_fingerprint,
operation_fingerprint, model_manifest and add_model_text. Each is the
module-level function of the same name, applied to that registry. AbstractSegment
and its class methods (from_grapheme, covering, columns) also accept
registry= for bundles over a runtime model. The native registry lives as long
as the object.
Module-level functions use a shared registry of the built-in systems only, so a
model added to a Registry is visible only through it. A name that is already
registered raises ValueError; manifest validation runs before native
registration, so a rejected manifest never leaves the model registered. The
format is described in docs/guide/runtime-model-format.md in the repository.
Command line
The package installs a merkmal command, also available as python -m merkmal:
merkmal systems
merkmal features p
merkmal diagnose pʰ "pʰ̳zz"
merkmal distance ai au
merkmal distance --node-weights ignore-tone a¹ a⁵
merkmal normalize ã
merkmal segment "tʃa pʰa"
merkmal fingerprint
merkmal --system phoible features bʰ
--system (-s) precedes the subcommand. With it, segment cuts the text as
that system reads it (system_segment_ipa); without it, at each base
character (segment_ipa). normalize does not depend on a system and refuses
the option. --node-weights (-w) selects a geometry weight preset for
distance and fingerprint (before or after the subcommand) and is refused by
other subcommands. diagnose and segment read from standard input when given
- or when piped without positional text. The default output is meant for
reading and may change between releases. The machine-readable modes are the
stable interface; each may be given before or after the subcommand:
| Mode | Output |
|---|---|
--json |
one JSON object per invocation |
--jsonl |
one JSON object per record, one per line |
--tsv |
a header row, then one row per record |
Records by subcommand:
| Subcommand | JSON object | JSONL/TSV record |
|---|---|---|
systems |
{"systems": [...]} |
system |
features |
{"system", "grapheme", "features": [...]} |
grapheme, feature |
diagnose |
{"system", "diagnoses": [...]} |
system, grapheme, ok, status, valid_prefix, offset, offending |
distance |
{"system", "a", "b", "distance", "coverage", "comparability"} (plus "node_weights" when given) |
the same fields |
normalize |
{"input", "normalized"} |
the same fields |
segment |
{"text", "segments": [...]}, with "system" when given |
index, segment |
fingerprint |
{"system", "sha256", "payload"} (plus "node_weights" when given) |
the same fields |
system is the system used: the one named, or merkmal.DEFAULT_SYSTEM. Text is
UTF-8. In TSV, a backslash, tab or newline inside a value is written \\, \t
or \n, so that a value never adds a column or a row. Floating-point values
are written at full precision.
The exit status is 0 on success and 1 on an error caused by the input (an unknown system or grapheme), with a message on standard error and nothing on standard output. A usage error, such as two modes at once, exits with 2.
Development
From the repository root:
python -m pip install -e ".[dev]"
python -m pytest python/tests -q
python -m build --sdist --wheel
License
The code is released under the MIT license. The feature data compiled into the
package carries the terms of its sources, and the distribution is licensed as
MIT AND CC-BY-4.0 AND CC-BY-SA-3.0 AND CC-BY-NC-SA-4.0; the NOTICE file
included in the distribution gives the attribution each source requires.
Metadata
Release files for merkmal 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| merkmal-0.13.0.tar.gz | 374.5 kB | With provenance | Details for merkmal-0.13.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| merkmal-0.13.0-cp312-abi3-musllinux_1_2_x86_64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ x86-64 | Details for merkmal-0.13.0-cp312-abi3-musllinux_1_2_x86_64.whl |
| merkmal-0.13.0-cp312-abi3-musllinux_1_2_aarch64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ ARM64 | Details for merkmal-0.13.0-cp312-abi3-musllinux_1_2_aarch64.whl |
| merkmal-0.13.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 | Details for merkmal-0.13.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
| merkmal-0.13.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 | Details for merkmal-0.13.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
Total release size: 2.3 MB
Release files / merkmal-0.13.0.tar.gz
| Download URL | merkmal-0.13.0.tar.gz |
|---|---|
| Size | 374.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31fb41d2e4e29f828255d9c7a799bb79fb5e1a5a0d9de827de31a17a6c7e938e
|
|
BLAKE2b-256 checksum How to use checksums |
2c519363b339d70f2f2f1e50034545986924ea117341613b1f4a025b32164eb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / merkmal-0.13.0-cp312-abi3-musllinux_1_2_x86_64.whl
| Download URL | merkmal-0.13.0-cp312-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 472.2 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
51ac4e4a0fbc7c2cb39327d88bac13ec1742fca79cec1737d7d691db43797608
|
|
BLAKE2b-256 checksum How to use checksums |
114cbf215d89464aa32a0a42a2b7030f8f34cbe62a3e2e893c2e9e0f0b877a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / merkmal-0.13.0-cp312-abi3-musllinux_1_2_aarch64.whl
| Download URL | merkmal-0.13.0-cp312-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 463.4 kB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3388b75c91741e1124f99d645f3ccd1aa3eeadfc7474cf6c9ac498d37371c523
|
|
BLAKE2b-256 checksum How to use checksums |
6f85ac96edf501c86dec3243be3cbe410813772c8886912f292356fdfc661445
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / merkmal-0.13.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | merkmal-0.13.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 475.2 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b0359eaedd9a9a1a0ce10f0d90425638b8fb0c2047b3768cc0d1efd674b7997d
|
|
BLAKE2b-256 checksum How to use checksums |
c561e8347498b92a65cb6b0cd764244996dc1472bb5f9448674a197e5b0e1a20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / merkmal-0.13.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | merkmal-0.13.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 469.4 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0b1e8cffc1bcb104b5286190597ca08332587fef69f50d416ed04361e0820dd3
|
|
BLAKE2b-256 checksum How to use checksums |
8ef9c6f8d8240b6a29d6276e0623f9a64264f308b654e28f80f8507a339bba10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logSecurity for merkmal 0.13.0
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.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for merkmal-0.13.0.tar.gz
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 Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.