From f88b7e15155e8121d38363ec4b05c5c9382f7530 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(B-4.4.46a)> Date: Thu, 9 Dec 2010 19:14:23 +0100 Subject: [PATCH] wagr, weak agreement over range of tokens. --- .../bool/predicates/weakagreement.cpp | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/libwccl/ops/functions/bool/predicates/weakagreement.cpp b/libwccl/ops/functions/bool/predicates/weakagreement.cpp index ec37318..a8a8ce4 100644 --- a/libwccl/ops/functions/bool/predicates/weakagreement.cpp +++ b/libwccl/ops/functions/bool/predicates/weakagreement.cpp @@ -47,14 +47,43 @@ WeakAgreement::BaseRetValPtr WeakAgreement::apply_internal(const FunExecContext& return Predicate::False(context); } - const boost::shared_ptr<const TSet>& attribs_tset = attribs_expr_->apply(context); - const Corpus2::Tag& attribs = attribs_tset->get_value(); + const boost::shared_ptr<const TSet>& attribs = attribs_expr_->apply(context); - // - // @todo: implement - // + int min_card = attribs->categories_count(tagset_); - return Predicate::False(context); + for(int i = abs_left; i <= abs_right; ++i) { + bool i_has_matched_tag = false; + foreach (const Corpus2::Lexeme& i_lex, sc.at(i)->lexemes()) { + const Corpus2::Tag& i_tag = i_lex.tag(); + if (attribs->matching_categories(i_tag) >= min_card) { + i_has_matched_tag = true; + for(int j = abs_right; j > i; --j) { + bool i_agrees_with_j = false; + bool j_has_matched_tag = false; + foreach(const Corpus2::Lexeme& j_lex, sc.at(j)->lexemes()) { + const Corpus2::Tag& j_tag = j_lex.tag(); + if (attribs->matching_categories(i_tag) >= min_card) { + j_has_matched_tag = true; + Corpus2::Tag intersection = i_tag.get_masked(j_tag); + // if the intersection matches enough categories we have agreement + if (attribs->matching_categories(intersection) >= min_card) { + i_agrees_with_j = true; + break; + } + } + } + if (j_has_matched_tag && !i_agrees_with_j) { + return Predicate::False(context); + } + } + } + } + if (!i_has_matched_tag && (i == abs_left || i == abs_right)) { + return Predicate::False(context); + } + } + + return Predicate::True(context); } } /* end ns Wccl */ -- GitLab