Inflection¶
Every analysis knows its lexeme - the forms of the word with the same lemma and part of speech. forms() gives all of them, and inflect() gives the form with the given Universal Dependencies features. The lexeme follows the conventions of the analyses: the auxiliary haber and the verb haber are two lexemes, and so are a participle and the adjective it makes.
Forms of the lexeme¶
forms() returns the forms as analyses like those of analyze, with prob equal to 1. The lemma goes first, then the paradigm: for a verb the infinitive, the gerund, the participles and the finite forms by mood (indicative, conditional, subjunctive, imperative), tense, number and person; for a noun or an adjective by number and gender. Variants - the forms of vos, old and regional spellings - follow the paradigm. An analysis equals its form from forms(): the probability takes no part in the comparison.
from esmorph import Analyzer
morph = Analyzer()
[form.word for form in morph.analyze("bonitas")[0].forms()]
[form.word for form in morph.analyze("hablamos")[0].forms()][:12]
['bonito', 'bonita', 'bonitos', 'bonitas']
['hablar', 'hablando', 'hablado', 'hablada', 'hablados', 'habladas', 'hablo', 'hablas', 'habla', 'hablamos', 'habláis', 'hablan']
Form by features¶
inflect(**feats) returns the form with the given features as a string. The features that are not given are kept where possible: gatos in the singular is gato, in the feminine gatas. An infinitive or a gerund asked for a tense, a mood, a person or a number gives a finite form.
gatos = morph.analyze("gatos")[0]
gatos.inflect(Number="Sing"), gatos.inflect(Gender="Fem")
morph.analyze("hablar")[0].inflect(Tense="Past", Person="3", Number="Plur")
('gato', 'gatas')
'hablaron'
Several forms may have the same features. A variant comes only from a variant: hablás in the imperative is hablá, while hablas is habla. A variant of a noun, an adjective, a determiner or a pronoun still gives a main form closer in spelling than its variants: buen in the plural is buenos, not the older bones. Of the two forms of the imperfect subjunctive the analysis keeps its own: hablase in the first person plural is hablásemos. Otherwise a form that the treebanks have clearly more often goes first (the verb haber gives hay, the auxiliary gives ha), and the order of the table of the word decides the rest: ser gives soy, not seigo. A form of some countries only is a variant: the feminine participle of apagar is apagada, not apaga.
[(a.pos, a.inflect(Person="3", Number="Sing")) for a in morph.analyze("haber")[:2]]
[('AUX', 'ha'), ('VERB', 'hay')]
A form of a noun, a name, an adjective, a determiner, a pronoun or a numeral without a gender or a number agrees with any: grande in the feminine plural is grandes, and an analysis of a rule stays itself (ETA). Of the forms that keep equally many features of the analysis, a form that changes another feature goes after one that lacks it, and a form with the gender and number of the analysis before one without them: chulitos in the singular is chulito, lo in the dative is le, sí in the dative is se, and ustedes, which has no gender, stays ustedes in the feminine. A value with several parts, such as Case=Acc,Nom, may be given in any order. A verb with clitics inflects as its verb, and its forms have no clitics: dámelo in the plural is dad.
grande, token = morph.analyze("grande")[0], morph.analyze("dámelo")[0]
grande.inflect(Gender="Fem", Number="Plur"), token.inflect(Number="Plur")
('grandes', 'dad')
Errors¶
FormNotFoundError, a subclass ofLookupError- the lexeme has no form with these features:casahas no masculine; or the dictionary has no lexeme of the analysis, as one pickled with another version of it;ValueError- the dictionary has no such feature or value, as inNumber="Plural"; the message lists the valid ones;TypeError- a value is not a string.
from esmorph import FormNotFoundError
try:
morph.analyze("casa")[0].inflect(Gender="Masc")
except FormNotFoundError as error:
print(error)
The lexeme of 'casa' has no form Gender=Masc