Low-level access to the lexical dictionary for a locale.
Words map to grammatical properties (grammemes) represented as
integer bitmasks, and to the inflection patterns they belong to.
This module mirrors the upstream DictionaryMetaData and
DictionaryExposableMorphology APIs.
Summary
Functions
Returns the combined bitmask for a list of grammeme names.
Returns the combined grammeme bitmask for a surface form, or nil if the word is not in the dictionary.
Returns the grammeme bitmask sets for each reading of a word.
Returns true if the word has all the properties in mask.
Returns the inflection rows of pattern that could have produced
surface_form given the word's combined grammemes.
Returns the inflection patterns for a word.
Returns the grammeme name for a mask with exactly one bit set.
Returns the list of grammeme names present in mask.
Functions
Returns the combined bitmask for a list of grammeme names.
Names unknown to the locale are skipped, as upstream: the Arabic definiteness lookup asks for "definite" although no dictionary entry carries it.
Arguments
localeis a locale identifier.namesis a list of grammeme names, such as["noun", "plural"].
Returns
- The combined bitmask, or
nilwhen none of the names is known.
Examples
iex> mask = Localize.Inflection.Dictionary.binary_properties(:en, ["noun", "plural"])
iex> Localize.Inflection.Dictionary.has_all_properties?(:en, "cats", mask)
true
iex> Localize.Inflection.Dictionary.binary_properties(:en, ["not-a-grammeme"])
nil
Returns the combined grammeme bitmask for a surface form, or nil if the word is not in the dictionary.
Arguments
localeis any locale atom for which data has been generated.wordis the surface form to look up.
Returns
- The combined bitmask of all grammemes of all readings of
word, or nil ifwordis unknown.
Examples
iex> mask = Localize.Inflection.Dictionary.combined_grammemes(:en, "cats")
iex> Enum.sort(Localize.Inflection.Dictionary.property_names(:en, mask))
["consonant-start", "noun", "plural", "present", "simple", "singular", "third", "verb"]
iex> Localize.Inflection.Dictionary.combined_grammemes(:en, "xyzzy")
nil
Returns the grammeme bitmask sets for each reading of a word.
A word that belongs to inflection patterns gets one grammeme set per matching inflection row (the row grammemes combined with the pattern part of speech). A word without patterns returns its combined grammemes as the single set.
Arguments
localeis a locale identifier.wordis the word to look up.
Returns
- A list of grammeme bitmasks, one for each reading, or
[]when the word is unknown.
Examples
iex> for set <- Localize.Inflection.Dictionary.grammeme_sets(:en, "cats") do
...> Enum.sort(Localize.Inflection.Dictionary.property_names(:en, set))
...> end
[["present", "simple", "singular", "third", "verb"], ["noun", "plural"]]
Returns true if the word has all the properties in mask.
Arguments
localeis a locale identifier.wordis the word to look up.maskis a grammeme bitmask.
Returns
truewhen the word's combined grammemes include every bit ofmask, andfalseotherwise or when the word is unknown.
Examples
iex> mask = Localize.Inflection.Dictionary.binary_properties(:en, ["noun", "plural"])
iex> Localize.Inflection.Dictionary.has_all_properties?(:en, "cats", mask)
true
iex> Localize.Inflection.Dictionary.has_all_properties?(:en, "xyzzy", mask)
false
Returns the inflection rows of pattern that could have produced
surface_form given the word's combined grammemes.
Only rows whose grammemes are a subset of from_grammemes and
whose suffix is a suffix of the surface form qualify; among those,
only the rows with the longest matching suffix are returned.
Arguments
surface_formis the word as written.from_grammemesis the word's combined grammeme bitmask.patternis a pattern map frompatterns_for_word/2.
Returns
- A list of
{grammemes, suffix}rows, or[]when none qualifies.
Examples
iex> [pattern | _rest] = Localize.Inflection.Dictionary.patterns_for_word(:en, "cats")
iex> grammemes = Localize.Inflection.Dictionary.combined_grammemes(:en, "cats")
iex> for {_grammemes, suffix} <-
...> Localize.Inflection.Dictionary.matching_inflections("cats", grammemes, pattern),
...> do: suffix
["s"]
Returns the inflection patterns for a word.
Arguments
localeis a locale identifier.wordis the word to look up.
Returns
- A list of pattern maps, each with
:name,:inflections,:pos_maskand:lemma_suffix, or[]when the word is unknown or uninflectable.
Examples
iex> length(Localize.Inflection.Dictionary.patterns_for_word(:en, "cats"))
2
iex> Localize.Inflection.Dictionary.patterns_for_word(:en, "xyzzy")
[]
Returns the grammeme name for a mask with exactly one bit set.
Arguments
localeis a locale identifier.maskis a grammeme bitmask.
Returns
- The grammeme name, or
nilwhenmaskdoes not have exactly one bit set or names no grammeme of the locale.
Examples
iex> mask = Localize.Inflection.Dictionary.binary_properties(:en, ["plural"])
iex> Localize.Inflection.Dictionary.property_name(:en, mask)
"plural"
Returns the list of grammeme names present in mask.
Arguments
localeis a locale identifier.maskis a grammeme bitmask.
Returns
- A list of grammeme names, empty where the locale has no inflection data.
Examples
iex> mask = Localize.Inflection.Dictionary.binary_properties(:en, ["noun", "plural"])
iex> Enum.sort(Localize.Inflection.Dictionary.property_names(:en, mask))
["noun", "plural"]