From 139055a4f1c6e36fb995ea7979883a7d2be874b8 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(B-4.4.46a)> Date: Fri, 18 Mar 2011 17:41:39 +0100 Subject: [PATCH] Tweak some code. MatchResult - change constructor so when you provide Match it defaults to matched = true. TokenCondition - be a bit defensive about possibility of inner predicates changing $_ --- libwccl/ops/match/conditions/tokencondition.cpp | 11 ++++++----- libwccl/ops/match/matchresult.h | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libwccl/ops/match/conditions/tokencondition.cpp b/libwccl/ops/match/conditions/tokencondition.cpp index e6c0b0f..51604e6 100644 --- a/libwccl/ops/match/conditions/tokencondition.cpp +++ b/libwccl/ops/match/conditions/tokencondition.cpp @@ -3,10 +3,10 @@ namespace Wccl { - TokenCondition::TokenCondition(const boost::shared_ptr<Function<Bool> >& predicate) : _predicate(predicate) { + BOOST_ASSERT(_predicate); } std::string TokenCondition::name() const @@ -21,14 +21,15 @@ std::string TokenCondition::to_string(const Corpus2::Tagset& tagset) const MatchResult TokenCondition::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const { + int orig_iter = iter_pos->get_value(); if (_predicate->apply(context)->get_value()) { - boost::shared_ptr<Match> match = boost::shared_ptr<Match>(new TokenMatch( - context.sentence_context().get_abs_position(*iter_pos))); + boost::shared_ptr<Match> match(new TokenMatch(context.sentence_context().get_abs_position(*iter_pos))); // increase the $_ variable by one after successful token match - iter_pos->set_value(iter_pos->get_value() + 1); - return MatchResult(true, match); + iter_pos->set_value(orig_iter + 1); + return MatchResult(match); } else { + iter_pos->set_value(orig_iter); return MatchResult(); } } diff --git a/libwccl/ops/match/matchresult.h b/libwccl/ops/match/matchresult.h index 5b3040d..84cdea5 100644 --- a/libwccl/ops/match/matchresult.h +++ b/libwccl/ops/match/matchresult.h @@ -12,7 +12,7 @@ namespace Wccl { class MatchResult { public: - MatchResult(bool matched, const boost::shared_ptr<Match>& match); + MatchResult(const boost::shared_ptr<Match>& match); MatchResult(); boost::shared_ptr<Match> get_match() const; bool matched() const; @@ -30,8 +30,8 @@ MatchResult::MatchResult() : _matched(false), _match() { } inline -MatchResult::MatchResult(bool matched, const boost::shared_ptr<Match>& match) - : _matched(matched), +MatchResult::MatchResult(const boost::shared_ptr<Match>& match) + : _matched(true), _match(match) { } -- GitLab