-
-
Notifications
You must be signed in to change notification settings - Fork 16
Inflection 77: Adding C and C++ API for stating source grammemes and tests for the same. #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c008f15
c8f22ec
70fa3e1
9c8ba42
c41ec8c
e676a21
873db46
52dc3d1
e3851a6
0c4bbeb
fa7133e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,23 @@ | |
|
|
||
| namespace inflection::dialog { | ||
|
|
||
| InflectableStringConcept::InflectableStringConcept(const SemanticFeatureModel* model, const SpeakableString& value) | ||
|
|
||
| InflectableStringConcept::InflectableStringConcept( | ||
| const SemanticFeatureModel* model, | ||
| const SpeakableString& value | ||
| ) | ||
| : InflectableStringConcept(model, value, {}) | ||
| { | ||
| } | ||
|
|
||
| InflectableStringConcept::InflectableStringConcept( | ||
| const SemanticFeatureModel* model, | ||
| const SpeakableString& value, | ||
| const ::std::map<SemanticFeature, ::std::u16string>& intitialConstraints | ||
| ) | ||
| : super(model) | ||
| , value(value) | ||
| , defaultDisplayValue(value, *npc(super::getSpeakFeature())) | ||
| , defaultDisplayValue(value, *npc(super::getSpeakFeature()), intitialConstraints) | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -39,11 +52,40 @@ SpeakableString* InflectableStringConcept::getFeatureValue(const SemanticFeature | |
| if (constraint != nullptr) { | ||
| return new SpeakableString(*npc(constraint)); | ||
| } | ||
| const auto displayValueResult = getDisplayValue(true); | ||
| if (displayValueResult) { | ||
| const auto defaultFeatureFunction = npc(getModel())->getDefaultFeatureFunction(feature); | ||
| ::std::unique_ptr<SpeakableString> computedValue; | ||
| ::std::unique_ptr<SpeakableString> baseValue; | ||
| if (defaultFeatureFunction != nullptr) { | ||
| computedValue.reset(npc(defaultFeatureFunction)->getFeatureValue(*displayValueResult, constraints)); | ||
| baseValue.reset(npc(defaultFeatureFunction)->getFeatureValue(defaultDisplayValue, constraints)); | ||
| } | ||
| const auto& displayConstraintMap = displayValueResult->getConstraintMap(); | ||
| auto displayConstraint = displayConstraintMap.find(feature); | ||
| if (displayConstraint != displayConstraintMap.end()) { | ||
| auto numberFeature = npc(getModel())->getFeature(u"number"); | ||
| if (feature.getName() == u"gender" && baseValue && numberFeature != nullptr && displayConstraintMap.find(*npc(numberFeature)) != displayConstraintMap.end()) { | ||
| return baseValue.release(); | ||
| } | ||
| return new SpeakableString(displayConstraint->second); | ||
| } | ||
| if (computedValue) { | ||
| return computedValue.release(); | ||
| } | ||
| if (baseValue) { | ||
| return baseValue.release(); | ||
| } | ||
| } | ||
| const auto& initialConstraintMap = defaultDisplayValue.getConstraintMap(); | ||
| auto initialConstraint = initialConstraintMap.find(feature); | ||
| if (initialConstraint != initialConstraintMap.end()) { | ||
| return new SpeakableString(initialConstraint->second); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are confusing. Why are these changes needed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More precisely, why is getFeatureValue being called here? Why is the feature name being checked for gender? What's special about gender or number? Why not grammatical case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto displayConstraint = displayConstraintMap.find(feature);
if (displayConstraint != displayConstraintMap.end()) {
auto numberFeature = npc(getModel())->getFeature(u"number");
if (feature.getName() == u"gender" && baseValue && numberFeature != nullptr
&& displayConstraintMap.find(*npc(numberFeature)) != displayConstraintMap.end()) {
return baseValue.release();
}
return new SpeakableString(displayConstraint->second);
} This is the test case which was failing before the changes: <test>
<source definiteness="definite">cometa</source>
<initial gender="masculine"/>
<result gender="masculine" number="singular">el cometa</result>
</test>
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior does not scale, and it does not make sense in my mind. An InflectableStringConcept is just a simplified SemanticConcept. A SemanticConcept should not have this issue. It does not have this kind of logic, and it does not check on specific grammatical category values. |
||
| auto defaultFeatureFunction = npc(getModel())->getDefaultFeatureFunction(feature); | ||
| if (defaultFeatureFunction != nullptr) { | ||
| const auto displayValueResult = getDisplayValue(true); | ||
| if (displayValueResult) { | ||
| return npc(defaultFeatureFunction)->getFeatureValue(*displayValueResult, constraints); | ||
| if (auto fallbackValue = ::std::unique_ptr<SpeakableString>(npc(defaultFeatureFunction)->getFeatureValue(defaultDisplayValue, constraints))) { | ||
| return fallbackValue.release(); | ||
| } | ||
| } | ||
| return nullptr; | ||
|
|
@@ -63,11 +105,7 @@ ::std::optional<DisplayValue> InflectableStringConcept::getDisplayValue(bool all | |
| { | ||
| auto defaultDisplayFunction = npc(getModel())->getDefaultDisplayFunction(); | ||
| if (defaultDisplayFunction != nullptr && !constraints.empty()) { | ||
| ::std::map<SemanticFeature, ::std::u16string> constraintMap; | ||
| if (!value.speakEqualsPrint()) { | ||
| constraintMap.emplace(*npc(getSpeakFeature()), value.getSpeak()); | ||
| } | ||
| SemanticFeatureModel_DisplayData displayData({DisplayValue(value.getPrint(), constraintMap)}); | ||
| SemanticFeatureModel_DisplayData displayData({defaultDisplayValue}); | ||
| ::std::unique_ptr<DisplayValue> returnVal(npc(defaultDisplayFunction)->getDisplayValue(displayData, constraints, allowInflectionGuess)); | ||
| if (returnVal != nullptr) { | ||
| return *returnVal; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,4 +221,11 @@ | |
| <test><source definiteness="definite">álgebra añeja</source><result>el álgebra añeja</result></test> <!-- An exception to the gender rule. --> | ||
| <test><source definiteness="definite">añeja álgebra</source><result>la añeja álgebra</result></test> | ||
| <test><source>área</source><result withDemAdj="esta área"/></test> | ||
|
|
||
| <!-- New Tests for stating grammemes --> | ||
| <test><source definiteness="definite">cometa</source><initial gender="masculine"/><result number="singular" gender="masculine">el cometa</result></test> | ||
| <test><source definiteness="definite">cometa</source><initial gender="feminine"/><result number="singular" gender="feminine">la cometa</result></test> | ||
| <test><source definiteness="definite">QQQQ</source><initial gender="masculine" number="plural"/><result number="plural" gender="masculine">los QQQQ</result></test> | ||
| <test><source definiteness="definite">QQQQ</source><initial gender="feminine" number="plural"/><result number="plural" gender="masculine">las QQQQ</result></test> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests look reasonable. |
||
|
|
||
| </inflectionTest> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good improvement.