Installation
The distribution name is sandborg-petersen-decoder;
the Python import name is sp_morph_decoder.
Install it from PyPI:
python -m pip install sandborg-petersen-decoder
To use the latest development revision directly from GitHub:
python -m pip install "git+https://github.com/tonyjurg/Sandborg-Petersen-decoder.git"
Quick start
from sp_morph_decoder import decode_tag
result = decode_tag("V-PAI-3S")
print(result)
The result is a dictionary containing the decoded fields:
{
'Part of Speech': 'Verb',
'Tense': 'Present',
'Voice': 'Active',
'Mood': 'Indicative',
'Person': 'Third Person',
'Number': 'Singular'
}
Input is normalized by trimming surrounding whitespace and converting letters to uppercase.
Permissive and strict modes
Permissive mode
Permissive mode is the default. It returns every field that can
be recovered and adds an Errors list when structural
validation finds a problem.
from sp_morph_decoder import decode_tag
result = decode_tag("N-XYZ")
for message in result.get("Errors", []):
print(message)
Strict mode
Strict mode raises MorphologyDecodeError when a tag
cannot be decoded cleanly. The exception retains the normalized
partial result and individual validation messages.
from sp_morph_decoder import MorphologyDecodeError, decode_tag
try:
result = decode_tag("N-XYZ", mode="strict")
except MorphologyDecodeError as error:
print(error.tag) # original input
print(error.errors) # tuple of messages
print(error.result) # partial decoded dictionary
Public API
| Name | Purpose |
|---|---|
decode_tag(tag, *, mode="permissive") |
Decode one tag and return a dictionary of fields. |
decodeTag(tagInput, *, mode="permissive") |
Backward-compatible camel-case alias. |
MorphologyDecodeError |
Strict-mode exception with tag, errors, and result attributes. |
DecodeMode |
Typing alias for Literal["permissive", "strict"]. |
DecodeResult |
Typing alias for the returned dictionary. |
__version__ |
The installed package version. |
Command-line interface
The package installs the sp-morph-decode command:
sp-morph-decode V-PAI-3S
sp-morph-decode N-XYZ --mode strict
It can also be invoked as a Python module:
python -m sp_morph_decoder V-PAI-3S --mode permissive
Results are written as formatted JSON. Successful and permissive decodes exit with status 0; a strict validation failure exits with status 2.
Example tags
| Tag | Highlights |
|---|---|
N-NSF | Noun, nominative singular feminine |
V-PAI-3S | Present active indicative, third-person singular |
V-RAN-ATT | Perfect active infinitive, Attic form |
P-1NS | First-person personal pronoun, nominative singular |