Skip to content
Snippets Groups Projects
Commit 340bbcac authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Rework strong agreement operator.

Clearer and better performing version, also more likely to actually work as expected :)
parent f88b7e15
Branches
No related merge requests found
...@@ -52,34 +52,46 @@ StrongAgreement::BaseRetValPtr StrongAgreement::apply_internal(const FunExecCont ...@@ -52,34 +52,46 @@ StrongAgreement::BaseRetValPtr StrongAgreement::apply_internal(const FunExecCont
int min_card = attribs->categories_count(tagset_); int min_card = attribs->categories_count(tagset_);
for(int i = abs_left; i <= abs_right; ++i) { const Corpus2::Token* t1 = sc.at(abs_left);
bool i_has_matched_tag = false; const Corpus2::Token* t2 = sc.at(abs_right);
foreach (const Corpus2::Lexeme& i_lex, sc.at(i)->lexemes()) { // to optimize a bit, make sure t1 is the one with less lexemes
const Corpus2::Tag& i_tag = i_lex.tag(); if (t1->lexemes().size() > t2->lexemes().size()) {
if (attribs->matching_categories(i_tag) >= min_card) { std::swap(t1, t2);
i_has_matched_tag = true; }
for(int j = abs_right; j > i; --j) { // check strong agreement between range endpoints
bool i_agrees_with_j = false; // for each possible agreement between them,
foreach(const Corpus2::Lexeme& j_lex, sc.at(j)->lexemes()) { // check if remaining tokens meet that agreement too
Corpus2::Tag intersection = i_tag.get_masked(j_lex.tag()); // return true if an agreement met by all tokens is found
// if the intersection matches enough categories we have agreement foreach (const Corpus2::Lexeme& t1_lex, t1->lexemes()) {
if (attribs->matching_categories(intersection) >= min_card) { const Corpus2::Tag& t1_tag = t1_lex.tag();
i_agrees_with_j = true; // don't bother checking t2 unless current t1_tag matches enough categories
break; if (attribs->matching_categories(t1_tag) >= min_card) {
foreach (const Corpus2::Lexeme& t2_lex, t2->lexemes()) {
Corpus2::Tag inter = t1_tag.get_masked(t2_lex.tag());
// if the intersection matches enough categories we have agreement
if (attribs->matching_categories(inter) >= min_card) {
// check if selected agreement is met by all remaining tokens
bool agreement_met = true;
for(int i = abs_left + 1; agreement_met && (i < abs_right); ++i) {
agreement_met = false;
foreach(const Corpus2::Lexeme& i_lex, sc.at(i)->lexemes()) {
Corpus2::Tag i_inter = i_lex.tag().get_masked(inter);
if (attribs->matching_categories(i_inter) < min_card) {
agreement_met = true;
break;
}
} }
} }
if (!i_agrees_with_j) { if (agreement_met) {
return Predicate::False(context); return Predicate::True(context);
} }
} }
} }
} }
if (!i_has_matched_tag) {
return Predicate::False(context);
}
} }
// None of possible agreements between endpoints carried over to all tokens
return Predicate::True(context); // or there was no such possible agreement at all, so return False.
return Predicate::False(context);
} }
} /* end ns Wccl */ } /* end ns Wccl */
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment