An and/or list of concepts rendered with locale-correct conjunctions.
This is the port of the upstream SemanticConceptList and the
createAndList/createOrList factories. Separators derive from
Localize's own CLDR list patterns, and language-specific
conjunction rules are applied on top: Spanish y becomes e
before an i-sound (with the diphthong exception), Italian e
becomes ed before a vowel, Hebrew prefixes ו directly to
Hebrew words but hyphenates Latin ones, and the Korean particle
과/와 follows the sound of the preceding word.
Constraints put on the list propagate to every member, so an
and-list of nouns can be pluralized or case-marked as a unit.
Lists nest: a ConceptList can be a member of another
ConceptList.
Summary
Functions
Builds an and-list of concepts.
Returns true when the list has at least one member.
Returns the value of a feature for the list.
Builds an or-list of concepts.
Builds a plain list of concepts, with no conjunction and no
separators, as the upstream SemanticConceptList constructor
does. Separators are then set with put_separator/3.
Sets whether an item that already starts with the item prefix, or ends with the item suffix, is left without another.
Puts a constraint on every member and records it on the list.
Sets a separator field.
Returns the number of members.
Renders the list with locale-correct separators.
Types
@type t() :: %Localize.Inflection.ConceptList{ after_first: term(), after_last: term(), avoid_affix_redundancy: term(), before_first: term(), before_last: term(), concepts: term(), conjunction: term(), conjunction_kind: term(), item_delimiter: term(), item_prefix: term(), item_suffix: term(), locale: term() }
Functions
Builds an and-list of concepts.
Arguments
localeis a locale atom or string, canonically BCP47.conceptsis a list ofLocalize.Inflection.Conceptor nestedLocalize.Inflection.ConceptListmembers; nil members are dropped.
Returns
{:ok, list}or{:error, exception}when the locale's list patterns are unavailable.
Examples
iex> {:ok, jane} = Localize.Inflection.Concept.new(:es, "Jane")
iex> {:ok, ivan} = Localize.Inflection.Concept.new(:es, "Ivan")
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, [jane, ivan])
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"Jane e Ivan"
iex> concepts =
...> for word <- ["gato", "gata"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, concepts)
iex> {:ok, list} = Localize.Inflection.ConceptList.put_constraint(list, :number, :plural)
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"gatos y gatas"
Returns true when the list has at least one member.
Arguments
listis a concept list.
Returns
truewhen the list has a member, andfalsewhen it is empty or is not a concept list.
Examples
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, [])
iex> Localize.Inflection.ConceptList.exists?(list)
false
Returns the value of a feature for the list.
A grammatical category (number, gender, case, ...) returns the first member's value; a display feature renders the whole list with each member replaced by its feature value.
Arguments
listis a concept list.nameis the feature, such as:number.
Returns
- The feature's value, or
nilwhen the list is empty or is not a concept list.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, concepts)
iex> Localize.Inflection.ConceptList.feature_value(list, :number)
:singular
Builds an or-list of concepts.
Arguments
localeis a locale atom or string, canonically BCP47.conceptsis a list ofLocalize.Inflection.Conceptor nestedLocalize.Inflection.ConceptListmembers; nil members are dropped.
Returns
{:ok, list}or{:error, exception}when the locale's list patterns are unavailable.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.or_list(:es, concepts)
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"Jane u Omar"
Builds a plain list of concepts, with no conjunction and no
separators, as the upstream SemanticConceptList constructor
does. Separators are then set with put_separator/3.
Arguments
localeis a locale atom or string, canonically BCP47.conceptsis a list ofLocalize.Inflection.Conceptor nestedLocalize.Inflection.ConceptListmembers; nil members are dropped.
Returns
{:ok, list}or{:error, exception}when a member is not a concept.
Examples
iex> concepts =
...> for word <- ["gatos", "idiomas"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.plain_list(:es, concepts)
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"gatosidiomas"
Sets whether an item that already starts with the item prefix, or ends with the item suffix, is left without another.
Arguments
listis a concept list.avoid?istrue, the default for every list, orfalse.
Returns
- The updated list, or
{:error, exception}whenlistis not a concept list oravoid?is not a boolean.
Examples
iex> concepts =
...> for word <- ["[gato]", "gata"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.plain_list(:es, concepts)
iex> list =
...> list
...> |> Localize.Inflection.ConceptList.put_separator(:item_prefix, "[")
...> |> Localize.Inflection.ConceptList.put_separator(:item_suffix, "]")
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"[gato][gata]"
iex> list
...> |> Localize.Inflection.ConceptList.put_avoid_affix_redundancy(false)
...> |> Localize.Inflection.ConceptList.to_speakable_string()
"[[gato]][gata]"
Puts a constraint on every member and records it on the list.
Arguments
listis a concept list.nameis a grammatical feature, such as:numberor:gender.valueis the feature's value, such as:plural.
Returns
{:ok, list}with every member constrained, or{:error, exception}when a member cannot take the constraint orlistis not a concept list.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, concepts)
iex> {:ok, list} = Localize.Inflection.ConceptList.put_constraint(list, :number, :plural)
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"Janes y Omares"
Sets a separator field.
Arguments
listis a concept list.fieldis one of:before_first,:after_first,:item_delimiter,:before_last,:after_last,:item_prefixor:item_suffix.valueis the separator as a speakable string; the empty string unsets the field, re-enabling any language-specific dynamic conjunction.
Returns
The concept list with the field set, or
{:error, exception}whenfieldis not a separator field orlistis not a concept list.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.plain_list(:es, concepts)
iex> list = Localize.Inflection.ConceptList.put_separator(list, :item_delimiter, " / ")
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"Jane / Omar"
Returns the number of members.
Arguments
listis a concept list.
Returns
The number of members, or
{:error, exception}whenlistis not a concept list.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, concepts)
iex> Localize.Inflection.ConceptList.size(list)
2
Renders the list with locale-correct separators.
Arguments
listis a concept list.
Returns
A speakable string, or
nilwhen the list is empty, or{:error, exception}whenlistis not a concept list.
Examples
iex> concepts =
...> for word <- ["Jane", "Omar"] do
...> {:ok, concept} = Localize.Inflection.Concept.new(:es, word)
...> concept
...> end
iex> {:ok, list} = Localize.Inflection.ConceptList.and_list(:es, concepts)
iex> Localize.Inflection.ConceptList.to_speakable_string(list)
"Jane y Omar"