Inflects words to a target set of grammatical constraints using the lexical dictionary and its inflection patterns.
This module mirrors the upstream Inflector_InflectionPattern,
MorphologicalAnalyzer and DictionaryLookupInflector behavior:
a word's candidate readings are ranked (optionally biased by
disambiguation grammemes and per-language priority tables) and the
best matching inflection row supplies the replacement suffix.
Summary
Functions
Inflects a word to the given constraints.
Inflects a word without trying case variants.
Reinflects a surface form within one pattern from its current grammemes to the target constraint mask.
Functions
Inflects a word to the given constraints.
Arguments
localeis any locale atom for which data has been generated.wordis the word to inflect.word_grammemesis the combined grammeme mask forword(fromLocalize.Inflection.Dictionary.combined_grammemes/2).constraintsis a list of grammeme names to inflect to, such as["plural"].
Options
:disambiguationis a list of grammeme names used to prefer readings, in priority order (for example["noun"]).:optional_constraintsis a list of grammeme names preferred but not required in the target inflection row.:prioritiesis a list of grammeme-name lists used to rank readings when disambiguation does not decide, mirroring the upstream per-language priority tables.:fallbackwhen true (the default) tries further readings when the best reading cannot be inflected.
Returns
{:ok, inflected}or:errorwhen the word cannot be inflected to the constraints.
Examples
iex> grammemes = Localize.Inflection.Dictionary.combined_grammemes(:en, "cat")
iex> Localize.Inflection.Inflector.inflect(:en, "cat", grammemes, ["plural"])
{:ok, "cats"}
Inflects a word without trying case variants.
Arguments
localeis any locale atom for which data has been generated.wordis the word to inflect, matched as written.word_grammemesis the combined grammeme mask forword.constraintsis a list of grammeme names to inflect to, such as["plural"].optionsis a keyword list of options.
Options
- The options of
inflect/5.
Returns
{:ok, inflected}or:errorwhen the word cannot be inflected to the constraints.
Examples
iex> grammemes = Localize.Inflection.Dictionary.combined_grammemes(:en, "cat")
iex> Localize.Inflection.Inflector.inflect_word(:en, "cat", grammemes, ["plural"], [])
{:ok, "cats"}
Reinflects a surface form within one pattern from its current grammemes to the target constraint mask.
Arguments
patternis a pattern map fromLocalize.Inflection.Dictionary.patterns_for_word/2.from_grammemesis the grammeme mask of the reading the surface form has.to_maskis the grammeme mask to inflect to;0returns the surface form unchanged.optional_masksis a list of grammeme masks preferred but not required in the target row. The default is[].surface_formis the word as written.tie_breakis:firstto keep the first of equally scored rows or:lastto take the last. The default is:first.
Returns
{:ok, inflected}or:errorwhen the pattern has no row satisfying the constraints.
Examples
iex> [pattern] =
...> for pattern <- Localize.Inflection.Dictionary.patterns_for_word(:en, "cats"),
...> "noun" in Localize.Inflection.Dictionary.property_names(:en, pattern.pos_mask),
...> do: pattern
iex> from = Localize.Inflection.Dictionary.binary_properties(:en, ["noun", "plural"])
iex> to = Localize.Inflection.Dictionary.binary_properties(:en, ["singular"])
iex> Localize.Inflection.Inflector.reinflect(pattern, from, to, "cats")
{:ok, "cat"}