Inflection
Morphology Inflection
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
inflection::message2::MF2Factory Class Reference

The MF2Factory provides factory methods to create custom functions to work with the icu::message2 library. The intended usage is to create an icu::message2::Function and use it with icu::message2::MFFunctionRegistry::Builder to construct a custom function registry to build a MessageFormatter with MessageFormatter::Builder. More...

#include <MF2Factory.hpp>

Public Types

enum class  OutputMode { PLAIN , SSML }
 

Static Public Member Functions

static icu::message2::Function * createInflectFunction (OutputMode mode=OutputMode::PLAIN)
 
static icu::message2::Function * createNumeralFunction (OutputMode mode=OutputMode::PLAIN)
 
static icu::message2::Function * createQuantifyFunction (OutputMode mode=OutputMode::PLAIN)
 
static icu::message2::Function * createListFunction (OutputMode mode=OutputMode::PLAIN)
 
static icu::message2::Function * createPronounFunction (OutputMode mode=OutputMode::PLAIN)
 

Detailed Description

The MF2Factory provides factory methods to create custom functions to work with the icu::message2 library. The intended usage is to create an icu::message2::Function and use it with icu::message2::MFFunctionRegistry::Builder to construct a custom function registry to build a MessageFormatter with MessageFormatter::Builder.

For example:

auto customRegistry = icu::message2::MFFunctionRegistry::Builder(errorCode)
         .adoptFunction(FunctionName("i:inflect"),
                        MF2Factory::createInflectFunction(), errorCode)
         .build();

UParseError pe;
auto mf1 = icu::message2::MessageFormatter::Builder(errorCode)
             .setFunctionRegistry(customRegistry)
             .setLocale(Locale::forLanguageTag("es-MX", errorCode))
             .setPattern("Location is {$name :i:inflect hello=world \
                          definiteness=definite number=plural \
                          gender=feminine}",
                         pe, errorCode)
             .build(errorCode);

auto mf2 = icu::message2::MessageFormatter::Builder(errorCode)
             .setFunctionRegistry(customRegistry)
             .setLocale(Locale::forLanguageTag("es-MX", errorCode))
             .setPattern(".local $gender = {$name :i:inflect \
                                            feature=gender} \
                          .local $number = {$name :i:inflect \
                                            feature=number} \
                          .match $gender $number \
                          feminine singular {{Feminine Singular {$name}}}\
                          masculine singular {{Masculine Singular {$name}}}\
                          * * {{other {$name} }}\n",
                          pe, errorCode)
             .build(errorCode);

Definition at line 54 of file MF2Factory.hpp.

Member Enumeration Documentation

◆ OutputMode

Controls how formatters serialize their result: PLAIN emits the print form only; SSML emits Speech Synthesis Markup Language (SSML) markup — a <sub alias="..."> element when print differs from speak.

See also
https://www.w3.org/TR/speech-synthesis/

Definition at line 63 of file MF2Factory.hpp.

Member Function Documentation

◆ createInflectFunction()

static icu::message2::Function * inflection::message2::MF2Factory::createInflectFunction ( OutputMode  mode = OutputMode::PLAIN)
static

Create an implementation of icu::message2::Function*, based on the inflection library, which can be passed to icu::message2::MFFunctionRegistry::Builder::adoptFunction to register a custom function.

◆ createListFunction()

static icu::message2::Function * inflection::message2::MF2Factory::createListFunction ( OutputMode  mode = OutputMode::PLAIN)
static

Create a Function for the :i:list function (array → plain/and/or list).

◆ createNumeralFunction()

static icu::message2::Function * inflection::message2::MF2Factory::createNumeralFunction ( OutputMode  mode = OutputMode::PLAIN)
static

Create an implementation of icu::message2::Function* for the :i:numeral function (number formatting), based on the inflection library, which can be passed to icu::message2::MFFunctionRegistry::Builder::adoptFunction to register a custom function.

◆ createPronounFunction()

static icu::message2::Function * inflection::message2::MF2Factory::createPronounFunction ( OutputMode  mode = OutputMode::PLAIN)
static

Create a Function for the :i:pronoun function.

◆ createQuantifyFunction()

static icu::message2::Function * inflection::message2::MF2Factory::createQuantifyFunction ( OutputMode  mode = OutputMode::PLAIN)
static

Create a Function for the :i:quantify function (count + unit agreement).


The documentation for this class was generated from the following file: