esMorph¶
esMorph is a morphological analyzer of Spanish: a Rust core with a Python API. For a word form the analyzer finds its analyses in a dictionary built from Wiktionary - the lemma, the part of speech and the Universal Dependencies features - orders them by probability and builds the forms of the word: conjugation, gender and number.
Early version
Before 1.0 the API may change between 0.x versions; the changes are described in the release notes.
Features¶
-
Analysis
Lemma, UD part of speech and features, probability of the analysis; lists of words and lemmatization without the GIL
-
Universal Dependencies
Parts of speech, features and lemmas by the UD guidelines and the AnCora conventions; verbs with clitics, numbers, signs and names by rules, unknown words by their ending
-
Inflection
Forms of the lexeme and the form by UD features: conjugation, gender and number
-
Comparison
Accuracy, inflection and speed compared with simplemma, spaCy, Stanza, ablaut and verbecc, loading and memory
-
Exceptions
Built-in Python exceptions and
FormNotFoundErrorfor missing forms
Installation¶
Python 3.11 or newer is required.
pip install esmorph
Prebuilt wheels, building from source and the Rust crate are described on the Installation page.
Quick start¶
from esmorph import Analyzer
morph = Analyzer()
morph.lemmatize(["Los", "niños", "cantaban", "canciones"])
[(a.lemma, a.pos, round(a.prob, 3)) for a in morph.analyze("casa")][:2]
morph.analyze("gatos")[0].inflect(Gender="Fem")
morph.analyze("hablar")[0].inflect(Tense="Past", Person="3", Number="Plur")
['el', 'niño', 'cantar', 'canción']
[('casa', 'NOUN', 0.986), ('casar', 'VERB', 0.013)]
'gatas'
'hablaron'
Project structure
- crates/esmorph - the Rust core of the analyzer: dictionary format, building, analysis, rules, guessing and inflection
- crates/esmorph-build - building the dictionary from the export of Wiktionary and the counts of the treebanks
- crates/esmorph-dict-es - the crate with the dictionary for
esmorphon crates.io - crates/esmorph-py - the Python module
esmorph._esmorphon PyO3 - python/esmorph - the Python package
- scripts - exporting Wiktionary and the counts of the treebanks, the conventions of the dictionary, checking the installed package before publishing and the comparison with other tools
- data - the tables of closed classes after UD Spanish AnCora and of the symbols of units
- docs - MkDocs documentation in English and Spanish
- tests - tests of the Python package