A pronoun with grammatical constraints.
The locale pronoun table (ported from the upstream
pronoun_XX.csv resources) maps each pronoun surface form to its
grammatical constraints. Constraints put on the concept select
the matching pronoun; an initial pronoun seeds default
constraints so that reinflection ("they" with gender=masculine
becomes "he") preserves unconstrained properties.
This is the equivalent of the upstream PronounConcept.
Summary
Functions
Removes a constraint from the concept.
Returns true when a custom display-data entry matches the constraints.
Returns true when a pronoun matches the constraints without falling back to the default entry.
Returns the value of a feature for the currently selected pronoun, or nil.
Creates a pronoun concept for a locale.
Puts a constraint on the concept.
Removes all constraints from the concept.
Renders the selected pronoun.
Types
@type t() :: %Localize.Inflection.PronounConcept{ constraints: %{optional(binary()) => binary()}, custom_count: non_neg_integer(), default_constraints: %{optional(binary()) => binary()}, default_index: non_neg_integer() | nil, entries: [{binary(), %{optional(binary()) => binary()}}], locale: atom(), table_locale: binary() }
Functions
Removes a constraint from the concept.
Arguments
conceptis a pronoun concept fromnew/2.nameis the grammatical feature to remove, such as:person.
Returns
The concept without the constraint, or
{:error, exception}whenconceptis not a pronoun concept.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> concept |> Localize.Inflection.PronounConcept.clear_constraint(:person) |> Localize.Inflection.PronounConcept.to_speakable_string()
"they"
Returns true when a custom display-data entry matches the constraints.
Arguments
conceptis a pronoun concept fromnew/2.
Returns
truewhen an entry of the concept's:display_datamatches, andfalseotherwise or whenconceptis not a pronoun concept.
Examples
iex> {:ok, concept} =
...> Localize.Inflection.PronounConcept.new(:en,
...> display_data: [{"xe", %{person: :third, number: :singular}}]
...> )
iex> {:ok, third} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :third)
iex> Localize.Inflection.PronounConcept.custom_match?(third)
true
iex> {:ok, first} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> Localize.Inflection.PronounConcept.custom_match?(first)
false
Returns true when a pronoun matches the constraints without falling back to the default entry.
Arguments
conceptis a pronoun concept fromnew/2.
Returns
truewhen a pronoun matches, andfalseotherwise or whenconceptis not a pronoun concept.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> Localize.Inflection.PronounConcept.exists?(concept)
true
Returns the value of a feature for the currently selected pronoun, or nil.
Arguments
conceptis a pronoun concept fromnew/2.nameis a feature name such as "gender".
Returns
- The feature value string, or nil when the selected pronoun does not constrain the feature.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> Localize.Inflection.PronounConcept.feature_value(concept, :case)
:nominative
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> Localize.Inflection.PronounConcept.feature_value(concept, :gender)
nil
Creates a pronoun concept for a locale.
Arguments
localeis a locale atom or string, canonically in BCP47 form (:"zh-TW","zh-TW"); the underscore form is also accepted. Regional locales fall back to their parent language for the feature model, and for the pronoun table unless the region has one of its own:zh-TWuses the Traditional Chinese table that ships withzh, andzh-HKthe Cantonese (yue) table.optionsis a keyword list of options.
Options
:initial_pronounis a pronoun surface form whose grammatical properties seed the default constraints (unambiguous properties only).:display_datais a list of{word, constraints}custom pronoun entries searched before the locale table.:default_constraintsis a map of feature name to value used to break ties between otherwise equal matches.
Returns
{:ok, concept}on success.{:error, reason}when the locale has no pronoun table, the inflection data it needs (its own, or that of the language whose table it uses) has not been downloaded, or the initial pronoun is unknown.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> Localize.Inflection.PronounConcept.to_speakable_string(concept)
"they"
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en, initial_pronoun: "him")
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :case, :nominative)
iex> Localize.Inflection.PronounConcept.to_speakable_string(concept)
"he"
Puts a constraint on the concept.
Arguments
conceptis a pronoun concept fromnew/2.nameis a feature name such as "person" or "case".valueis the constraint value such as "third".
Returns
{:ok, concept}or{:error, reason}when the feature is unknown or the value is not valid for a bounded feature.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> Localize.Inflection.PronounConcept.to_speakable_string(concept)
"I"
Removes all constraints from the concept.
Arguments
conceptis a pronoun concept fromnew/2.
Returns
The concept without constraints, or
{:error, exception}whenconceptis not a pronoun concept.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> concept |> Localize.Inflection.PronounConcept.reset() |> Localize.Inflection.PronounConcept.to_speakable_string()
"they"
Renders the selected pronoun.
Arguments
conceptis a pronoun concept fromnew/2.referenced_conceptis an optionalLocalize.Inflection.Conceptthe pronoun depends on (a possessee), used to satisfydependency=constraints such as the French elision before a vowel.
Returns
- A speakable string (a binary, or
{print, speak}), or nil when no pronoun matches orconceptis not a pronoun concept.
Examples
iex> {:ok, concept} = Localize.Inflection.PronounConcept.new(:en)
iex> {:ok, concept} = Localize.Inflection.PronounConcept.put_constraint(concept, :person, :first)
iex> Localize.Inflection.PronounConcept.to_speakable_string(concept)
"I"