-
-
Notifications
You must be signed in to change notification settings - Fork 19
Add secondary longest-suffix exemplar guessing for Serbian #197
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
74431e6
7d75b2d
87ff785
cc389e5
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ак,=,изузетак | ||
| њак,=,надвожњак | ||
| ац,=,дворац | ||
| ник,=,камен | ||
| ач,=,брод | ||
| ар,=,булевар | ||
| бус,=,аутобус | ||
| ан,=,Драган | ||
| ош,=,Милош | ||
| иша,=,Љубиша | ||
| а,=,Јелена | ||
| ица,=,Љубица | ||
| ија,=,Србија | ||
| ка,=,мачка | ||
| о,=,брдо | ||
| бло,=,дебло | ||
| е,=,море | ||
| сеље,=,насеље | ||
| ме,=,име | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,12 @@ | |
| #include <array> | ||
| #include <iterator> | ||
| #include <memory> | ||
| #include <inflection/util/ResourceLocator.hpp> | ||
| #include <string> | ||
|
|
||
| static constexpr int32_t MAX_SUFFIX_LEN = 7; | ||
| static constexpr int32_t MIN_STEM_LEN = 2; | ||
|
|
||
| namespace inflection::grammar::synthesis { | ||
|
|
||
| SrGrammarSynthesizer_SrDisplayFunction::SrGrammarSynthesizer_SrDisplayFunction(const ::inflection::dialog::SemanticFeatureModel& model) | ||
|
|
@@ -39,6 +43,7 @@ SrGrammarSynthesizer_SrDisplayFunction::SrGrammarSynthesizer_SrDisplayFunction(c | |
| {GrammemeConstants::NUMBER_SINGULAR, GrammemeConstants::NUMBER_PLURAL}, | ||
| {GrammemeConstants::GENDER_MASCULINE, GrammemeConstants::GENDER_FEMININE, GrammemeConstants::GENDER_NEUTER} | ||
| }, {}, true) | ||
| , suffixToExemplar(inflection::util::ResourceLocator::getRootForLocale(inflection::util::LocaleUtils::SERBIAN()) + u"/exemplar/suffix_" + inflection::util::LocaleUtils::SERBIAN().toString() + u".bist") | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -159,8 +164,37 @@ ::inflection::dialog::DisplayValue *SrGrammarSynthesizer_SrDisplayFunction::getD | |
| if (dictionary.isKnownWord(displayString)) { | ||
| displayString = inflectFromDictionary(constraints, displayString); | ||
| } else if (enableInflectionGuess) { | ||
| // Let's use rule based inflection for nouns. Assume lemma is singular, nominative. | ||
| displayString = inflectWithRule(constraints, displayString); | ||
| // Primary guess: Rule based inflection for nouns. | ||
| ::std::u16string ruleResult = inflectWithRule(constraints, displayString); | ||
| if (ruleResult != displayString) { | ||
| displayString = ruleResult; | ||
| } else { | ||
| // Secondary guess: Longest suffix exemplar guessing. | ||
|
Comment on lines
+167
to
+172
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 is an interesting combination. Why not go all in for one or the other? What is the advantage of one over the other?
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. Rule based inflection is going to give the correct answer for words not in the dictionary (with minor exceptions).
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. So I actually went and implemented the other 3 cases and it wasn't that bad. Let's discuss it tomorrow. |
||
| auto countString = GrammarSynthesizerUtil::getFeatureValue(constraints, numberFeature); | ||
| auto caseString = GrammarSynthesizerUtil::getFeatureValue(constraints, caseFeature); | ||
| auto genderString = GrammarSynthesizerUtil::getFeatureValue(constraints, genderFeature); | ||
| std::vector<::std::u16string> constraintsVec; | ||
| if (!countString.empty()) constraintsVec.push_back(countString); | ||
| if (!caseString.empty() && caseString != GrammemeConstants::CASE_NOMINATIVE) constraintsVec.push_back(caseString); | ||
| if (!genderString.empty()) constraintsVec.push_back(genderString); | ||
|
Comment on lines
+173
to
+179
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. I would have expected these values to already be derived. Why are they being queried here? Also please don't inline if statements. It makes it hard to debug, and get decent code coverage metrics. |
||
|
|
||
| for (int32_t suffixLen = std::min(MAX_SUFFIX_LEN, static_cast<int32_t>(displayString.length() - MIN_STEM_LEN)); suffixLen > 0; --suffixLen) { | ||
| std::u16string_view suffix = std::u16string_view(displayString).substr(displayString.length() - suffixLen); | ||
| auto exemplarResult = suffixToExemplar.findTarget(suffix); | ||
| if (exemplarResult.has_value()) { | ||
| const auto& exemplar = *exemplarResult; | ||
| int64_t exemplarGrammemes = 0; | ||
| dictionary.getCombinedBinaryType(&exemplarGrammemes, exemplar); | ||
| if (exemplarGrammemes != 0) { | ||
| auto guessedResult = dictionaryInflector.inflectExemplar(displayString, exemplar, exemplarGrammemes, constraintsVec, {}); | ||
| if (guessedResult.has_value()) { | ||
| displayString = *guessedResult; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return new ::inflection::dialog::DisplayValue(displayString, constraints); | ||
| } | ||
|
|
||
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.
Was this file manually generated or generated from genExemplars? It seems a little short.
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.
FYI the other tables are mostly generated with some small manual tweaking.
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 was manually generated - I'll look into genExemplars, thanks for the pointer.