From 7838cf572f9c0f015dcb39490a85914756b1ec83 Mon Sep 17 00:00:00 2001
From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl>
Date: Mon, 7 May 2012 16:29:23 +0200
Subject: [PATCH] fix match token-level condition: immediately terminate and
 return empty match result when curr pos is outside sent

---
 .../ops/match/conditions/tokencondition.cpp   | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libwccl/ops/match/conditions/tokencondition.cpp b/libwccl/ops/match/conditions/tokencondition.cpp
index 6dedf2e..dac85cc 100644
--- a/libwccl/ops/match/conditions/tokencondition.cpp
+++ b/libwccl/ops/match/conditions/tokencondition.cpp
@@ -40,16 +40,18 @@ std::string TokenCondition::to_string(const Corpus2::Tagset& tagset) const
 MatchResult TokenCondition::apply(const ActionExecContext& context) const
 {
 	int orig_iter = context.sentence_context().get_position();
-	if (_predicate->apply(context)->get_value()) {
-		boost::shared_ptr<TokenMatch> match(new TokenMatch(context.sentence_context().get_position()));
-		// increase current sentence position by one after successful token match
-		context.sentence_context().set_position(orig_iter + 1);
-		return MatchResult(match);
-	}
-	else {
-		context.sentence_context().set_position(orig_iter);
-		return MatchResult();
+	if (context.sentence_context().is_current_inside()) {
+		if (_predicate->apply(context)->get_value()) {
+			boost::shared_ptr<TokenMatch> match(new TokenMatch(context.sentence_context().get_position()));
+			// increase current sentence position by one after successful token match
+			context.sentence_context().set_position(orig_iter + 1);
+			return MatchResult(match);
+		}
 	}
+
+	// else
+	context.sentence_context().set_position(orig_iter);
+	return MatchResult();
 }
 
 std::ostream& TokenCondition::write_to(std::ostream& os) const
-- 
GitLab