From e32ccea8faea7ba5cc779864b18cb248c5254744 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(B-4.4.46a)> Date: Thu, 9 Dec 2010 18:57:47 +0100 Subject: [PATCH] agr operator, strong agreement on range of tokens. --- .../bool/predicates/strongagreement.cpp | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/libwccl/ops/functions/bool/predicates/strongagreement.cpp b/libwccl/ops/functions/bool/predicates/strongagreement.cpp index 82b27fd..4081562 100644 --- a/libwccl/ops/functions/bool/predicates/strongagreement.cpp +++ b/libwccl/ops/functions/bool/predicates/strongagreement.cpp @@ -1,4 +1,5 @@ #include <libwccl/ops/functions/bool/predicates/strongagreement.h> +#include <libpwrutils/foreach.h> namespace Wccl { @@ -47,14 +48,38 @@ StrongAgreement::BaseRetValPtr StrongAgreement::apply_internal(const FunExecCont 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; + foreach(const Corpus2::Lexeme& j_lex, sc.at(j)->lexemes()) { + Corpus2::Tag intersection = i_tag.get_masked(j_lex.tag()); + // if the intersection matches enough categories we have agreement + if (attribs->matching_categories(intersection) >= min_card) { + i_agrees_with_j = true; + break; + } + } + if (!i_agrees_with_j) { + return Predicate::False(context); + } + } + } + } + if (!i_has_matched_tag) { + return Predicate::False(context); + } + } + + return Predicate::True(context); } } /* end ns Wccl */ -- GitLab