Skip to content

Commit

Permalink
đźš‘ Fallback to all readings if no &LINK with right errtag
Browse files Browse the repository at this point in the history
In case CG rules removed them, we don't want to end up with duplicated
suggestions.
  • Loading branch information
unhammer committed Aug 21, 2019
1 parent 30272d2 commit ab7e322
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/suggest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ void rel_on_match(const relations& rels,
}
}

/**
* Return the readings of Cohort trg that have ErrId err_id; fallback
* to all the readings if no match.
*
* The reason we want readings with a certain error type, is if we
* have overlapping errors where e.g. one wants to DELETE a word. We
* don't want to suggest a deletion on the suggestions of the *other*
* error types.
*
* The reason we fallback to all the readings is that some times
* people write CG rules that delete the &LINK readings or similar –
* we don't want to fail to find the cohort that's supposed to be
* underlined in that case.
*/
vector<Reading> readings_with_errtype(const Cohort& trg, const ErrId& err_id) {
vector<Reading> filtered(trg.readings.size());
auto it = std::copy_if(trg.readings.begin(), trg.readings.end(),
Expand All @@ -352,7 +366,13 @@ vector<Reading> readings_with_errtype(const Cohort& trg, const ErrId& err_id) {
return tr.errtypes.find(err_id) != tr.errtypes.end();
});
filtered.resize(std::distance(filtered.begin(), it));
return filtered;
if(filtered.empty()) {
vector<Reading> unfiltered(trg.readings);
return unfiltered;
}
else {
return filtered;
}
}

bool both_spaces(char16_t lhs, char16_t rhs) {
Expand Down
4 changes: 4 additions & 0 deletions test/suggest/expected.missinglink.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
divvun-suggest: WARNING: No <description> for "no-space-after-punct-mark" in xml:lang 'se', trying 'en'
divvun-suggest: WARNING: No <description> for "no-space-after-punct-mark" in any xml:lang
divvun-suggest: WARNING: No <description> for "no-space-after-punct-mark" in xml:lang 'se', trying 'en'
divvun-suggest: WARNING: No <description> for "no-space-after-punct-mark" in any xml:lang
1 change: 1 addition & 0 deletions test/suggest/expected.missinglink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"errs":[[",Hellasis",8,17,"no-space-after-punct-mark","no-space-after-punct-mark",[", Hellasis"],"no-space-after-punct-mark"],[",Hellasis",8,17,"typo","Ii leat sátnelisttus",[],"Čállinmeattáhusat"],[",Hellasis",32,41,"no-space-after-punct-mark","no-space-after-punct-mark",[", Hellasis"],"no-space-after-punct-mark"],[",Hellasis",32,41,"typo","Ii leat sátnelisttus",[],"Čállinmeattáhusat"]],"text":"Romanias,Hellasis\nmánuidRomanias,Hellasis\n"}
24 changes: 24 additions & 0 deletions test/suggest/input.missinglink.cg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"<Romanias>"
"Romania" N Prop Sem/Sur Sg Loc <W:0.0> <cohort-with-dynamic-compound> @N<
"<,>"
"," CLB <W:0.0> <NoSpaceAfterPunctMark> &no-space-after-punct-mark ID:3 R:RIGHT:4
"," CLB <W:0.0> <NoSpaceAfterPunctMark> "<, Hellasis>" &no-space-after-punct-mark &SUGGESTWF ID:3 R:RIGHT:4
"<Hellasis>"
"Hellas" N Prop Sem/Plc Sg Loc <W:0.0> <cohort-with-dynamic-compound> @<ADVL &typo &SUGGEST ID:4
:\n

"<mánuid>"
"mánnu" N Sem/Measr_Time Pl Acc <W:0.0> @HNOUN
"mánnu" N Sem/Measr_Time Pl Gen <W:0.0> @<ADVL
:
"<Romanias>"
"Romania" N Prop Sem/Plc Sg Loc <W:0.0> <cohort-with-dynamic-compound> @N<
"Romania" N Prop Sem/Sur Sg Loc <W:0.0> <cohort-with-dynamic-compound> @N<
"<,>"
"," CLB <W:0.0> <NoSpaceAfterPunctMark> &no-space-after-punct-mark ID:7 R:RIGHT:8
"," CLB <W:0.0> <NoSpaceAfterPunctMark> "<, Hellasis>" &no-space-after-punct-mark &SUGGESTWF ID:7 R:RIGHT:8
"<Hellasis>"
"Hellas" N Prop Sem/Plc Sg Loc <W:0.0> <cohort-with-dynamic-compound> @<ADVL &typo &SUGGEST ID:8
"Hellas" N Prop Sem/Sur Sg Loc <W:0.0> <cohort-with-dynamic-compound> @<ADVL &typo &SUGGEST ID:8
:\n

0 comments on commit ab7e322

Please sign in to comment.