Skip to content

Commit

Permalink
Ensure &ADDED wrapped in spaces; new &ADDED-AFTER-BLANK to not ensure…
Browse files Browse the repository at this point in the history
… blank before

Fix #75
  • Loading branch information
unhammer committed Aug 7, 2024
1 parent 5c03ee5 commit 2d7d19b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
30 changes: 18 additions & 12 deletions src/suggest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ const Reading proc_subreading(const string& line, bool generate_all_readings) {
gentags.push_back(tag);
}
else if (result[2].length() != 0) {
if (tag == "&ADDED" || tag == "&ADDED-AFTER-BLANK") {
if (tag == "&ADDED") {
r.added = AddedEnsureBlanks;
}
else if (tag == "&ADDED-AFTER-BLANK") {
r.added = AddedAfterBlank;
}
else if (tag == "&ADDED-BEFORE-BLANK") {
Expand Down Expand Up @@ -614,10 +617,11 @@ if(verbose) std::cerr << "\t\033[0;35mr.suggestwf=" << tr.suggestwf << "\033[0
if(verbose) std::cerr << "\t\033[0;35mr.suggest=" << tr.suggest << "\033[0m" << "\t" << tr.line;
// Collect SUGGEST/SUGGESTWF:
if(!del) for(const auto& sf : tr.sforms) {
rep_this_trg.push_back(fromUtf8(withCasing(tr.fixedcase, casing, sf)));
const auto cased_sf = fromUtf8(withCasing(tr.fixedcase, casing, sf));
rep_this_trg.push_back(cased_sf);
if (tr.suggestwf) {
if (i == i_c) {
reps_suggestwf.push_back(fromUtf8(withCasing(tr.fixedcase, casing, sf)));
reps_suggestwf.push_back(cased_sf);
}
else {
std::cerr << "divvun-suggest: WARNING: Saw SUGGESTWF on non-central (co-)cohort, ignoring" << std::endl;
Expand All @@ -632,14 +636,16 @@ if(verbose) std::cerr << "\t\t\033[1;36msform=\t'" << sf << "'\033[0m" << std
UStringVector reps_next;
for(auto& rep: reps) {
// Prepend blank unless at left edge:
auto pre_blank = i == i_left || added_before_blank
? ""
: clean_blank(prev_added_before_blank + trg.raw_pre_blank);
const auto pre_blank = i == i_left || added_before_blank
? ""
: clean_blank(prev_added_before_blank + trg.raw_pre_blank);
// For &ADDED, enclose in blanks (unneeded blanks will get cleaned later):
const auto post_blank = trg.added ? u" " : u"";
if(rep_this_trg.empty()) {
reps_next.push_back(rep + fromUtf8(pre_blank) + trg.form);
reps_next.push_back(rep + fromUtf8(pre_blank) + trg.form + post_blank);
}
else for(const auto& form : rep_this_trg) {
reps_next.push_back(rep + fromUtf8(pre_blank) + form);
else for(const auto& sform : rep_this_trg) {
reps_next.push_back(rep + fromUtf8(pre_blank) + sform + post_blank);
}
}
reps.swap(reps_next);
Expand All @@ -659,7 +665,7 @@ if(verbose) for (const auto& sf : reps) { std::cerr << "\033[1;35mreps sf=\t'" <

variant<Nothing, Err> Suggest::cohort_errs(const ErrId& err_id, size_t i_c,
const Cohort& c, const Sentence& sentence, const u16string& text) {
if (cohort_empty(c) || c.added) {
if (cohort_empty(c) || c.added != NotAdded) {
return Nothing();
}
else if (ignores.find(err_id) != ignores.end()) {
Expand Down Expand Up @@ -848,7 +854,7 @@ Sentence Suggest::run_sentence(std::istream& is, FlushOn flush_on) {
sentence.ids_cohorts[c.id] = sentence.cohorts.size() - 1;
}
}
if (!c.added) {
if (c.added == NotAdded) {
pos += c.form.size();
sentence.text << toUtf8(c.form);
}
Expand Down Expand Up @@ -903,7 +909,7 @@ Sentence Suggest::run_sentence(std::istream& is, FlushOn flush_on) {
sentence.ids_cohorts[c.id] = sentence.cohorts.size() - 1;
}
}
if (!c.added) {
if (c.added == NotAdded) {
pos += c.form.size();
sentence.text << toUtf8(c.form);
}
Expand Down
2 changes: 1 addition & 1 deletion src/suggest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inline void dedupe(relations& rels) {
}
}

enum Added { NotAdded, AddedAfterBlank, AddedBeforeBlank };
enum Added { NotAdded, AddedEnsureBlanks, AddedAfterBlank, AddedBeforeBlank };

enum Casing { lower, Title, UPPER, mIxed };
inline Casing getCasing(string input) {
Expand Down
2 changes: 2 additions & 0 deletions test/suggest/expected.move-after.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
divvun-suggest: WARNING: No <description> for "syn-abs-wordorder" in xml:lang 'se', trying 'en'
divvun-suggest: WARNING: No <description> for "syn-abs-wordorder" in any xml:lang
1 change: 1 addition & 0 deletions test/suggest/expected.move-after.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"errs":[["Nrel mellom nabs",4,20,"syn-abs-wordorder","syn-abs-wordorder",["nabs Nrel mellom"],"syn-abs-wordorder"]],"text":"før Nrel mellom nabs"}
2 changes: 1 addition & 1 deletion test/suggest/expected.move.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"errs":[["Nrel mellom nabs",0,16,"syn-abs-wordorder","syn-abs-wordorder",["nabsNrel mellom"],"syn-abs-wordorder"]],"text":"Nrel mellom nabs"}
{"errs":[["Nrel mellom nabs",0,16,"syn-abs-wordorder","syn-abs-wordorder",["nabs Nrel mellom"],"syn-abs-wordorder"]],"text":"Nrel mellom nabs"}
15 changes: 15 additions & 0 deletions test/suggest/input.move-after.cg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"<før>"
"før" pr
:
"<nabs>"
"nabs" N Abs Sg &syn-abs-wordorder &ADDED co&syn-abs-wordorder ID:4 R:DELETE1:4 SPLITCOHORT:20 MOVE-AFTER:26:syn-abs-wordorder ADDRELATION(DELETE1):32
"<Nrel>"
"Nrel" N Rel
:
"<mellom>"
"mellom" pr
:
; "<nabs>"
; "nabs" N Abs Sg &syn-abs-wordorder ADD:11:syn-abs-wordorder SPLITCOHORT:20
"<nabs>"
"nabs" N Abs Sg &syn-abs-wordorder DELETE ID:5 R:$3:4 R:LEFT:4 SPLITCOHORT:20 ADDRELATION($3):31

0 comments on commit 2d7d19b

Please sign in to comment.