Inflection
Morphology Inflection
Loading...
Searching...
No Matches
PronounConcept.hpp
1/*
2 * Copyright 2022-2024 Apple Inc. All rights reserved.
3 */
4#pragma once
5
6#include <inflection/dialog/fwd.hpp>
7#include <inflection/dialog/SemanticFeatureConceptBase.hpp>
8#include <inflection/dialog/SemanticFeatureModel_DisplayData.hpp>
9#include <inflection/dialog/DisplayValue.hpp>
10#include <optional>
11#include <memory>
12#include <string>
13#include <vector>
14
26class INFLECTION_CLASS_API inflection::dialog::PronounConcept
28{
29
30public:
32 typedef SemanticFeatureConceptBase super;
34
35private:
36 enum MatchState {
37 NO_MATCH,
38 GENERIC_MATCH,
39 FULL_MATCH
40 };
41 typedef std::map<std::u16string_view, std::u16string_view> ConstraintData;
42 typedef std::pair<std::u16string_view, ConstraintData> PronounEntry;
43 struct DefaultPronounData;
44 class PronounData;
45
46 std::shared_ptr<PronounData> pronounData;
47 ::std::map<std::u16string, ::std::u16string> defaultConstraints { };
48 int32_t defaultPronounIndex { -1 };
49
50private: /* protected */
51 static std::shared_ptr<PronounConcept::DefaultPronounData> createPronounDataForModel(const SemanticFeatureModel& model, const char16_t* const readerCharArray);
52 static std::shared_ptr<PronounConcept::DefaultPronounData> getPronounData(const SemanticFeatureModel& model);
53 static std::optional<::std::u16string_view> getFeatureValueForPronoun(const PronounConcept::ConstraintData &constraintData, const SemanticFeature& feature);
54 bool isMatchingSoundProperty(const ::std::u16string& displayValue, std::u16string_view matchType) const;
55 bool isMatchingInitialPronoun() const;
56 static MatchState getMatchState(const PronounConcept::ConstraintData& valueConstraintMap, const std::u16string& semanticName, const std::u16string& semanticValue);
57 const PronounEntry* getFirstPossibleValue(const inflection::dialog::SemanticFeatureConceptBase* referencedConcept, bool returnDefault, bool matchAll) const;
58 const PronounEntry* getCurrentValue(const inflection::dialog::SemanticFeatureConceptBase* referencedConcept, bool returnDefault, bool matchAll) const;
59
60public:
65
69 bool isExists() const override;
70
74 bool isCustomMatch() const;
75
81
90 virtual ::inflection::dialog::SpeakableString* toSpeakableString(const inflection::dialog::SemanticFeatureConceptBase& referencedConcept) const;
91
95 ::std::u16string toString() const override;
96
100 PronounConcept* clone() const override;
101
105 bool operator==(const PronounConcept& o) const;
106
113 PronounConcept(const SemanticFeatureModel& model, const ::std::vector<::inflection::dialog::DisplayValue>& defaultDisplayData, const ::std::map<SemanticFeature, ::std::u16string>& defaultConstraints);
114
122 PronounConcept(const SemanticFeatureModel& model, const ::std::map<SemanticFeature, ::std::u16string>& defaultConstraints);
123
137 PronounConcept(const SemanticFeatureModel& model, std::u16string_view initialPronoun);
138
143
147 ~PronounConcept() override;
148private:
149 static std::map<std::u16string, std::shared_ptr<PronounConcept::DefaultPronounData>>* PRONOUN_DATA_CACHE();
150
151 PronounConcept& operator=(const PronounConcept&) = delete;
152};
Provides a way to format a customizable pronoun for a given language.
PronounConcept(const SemanticFeatureModel &model, const ::std::vector<::inflection::dialog::DisplayValue > &defaultDisplayData, const ::std::map< SemanticFeature, ::std::u16string > &defaultConstraints)
PronounConcept * clone() const override
::inflection::dialog::SpeakableString * getFeatureValue(const SemanticFeature &feature) const override
::inflection::dialog::SpeakableString * toSpeakableString() const override
::std::u16string toString() const override
virtual ::inflection::dialog::SpeakableString * toSpeakableString(const inflection::dialog::SemanticFeatureConceptBase &referencedConcept) const
bool operator==(const PronounConcept &o) const
PronounConcept(const SemanticFeatureModel &model, std::u16string_view initialPronoun)
PronounConcept(const SemanticFeatureModel &model, const ::std::map< SemanticFeature, ::std::u16string > &defaultConstraints)
PronounConcept(const PronounConcept &other)
bool isExists() const override
Abstract base class of SpeakableConcept with inflectable constraints.
A semantic model that contains display data for semantic values and provides feature functions for de...
Represents a single semantic feature.
Represents a string with both a spoken and written representation.
The C++ namespace for Inflection.
Definition fwd.hpp:11