From f15b6a32f63b92f5617954da04b460e572cbda05 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(win7-laptop)> Date: Fri, 6 May 2011 12:29:46 +0200 Subject: [PATCH] Return Position relative to current position in last(), first(). It was returning Position based off absolute position, which was no good for operators like orth[first(M)] working in changing sentence contexts. --- libwccl/ops/functions/position/firsttoken.cpp | 4 +++- libwccl/ops/functions/position/lasttoken.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libwccl/ops/functions/position/firsttoken.cpp b/libwccl/ops/functions/position/firsttoken.cpp index 8c90075..b92b66d 100644 --- a/libwccl/ops/functions/position/firsttoken.cpp +++ b/libwccl/ops/functions/position/firsttoken.cpp @@ -21,7 +21,9 @@ FirstToken::BaseRetValPtr FirstToken::apply_internal( if(match->empty()) { return detail::DefaultFunction<Position>()->apply(context); } - return boost::make_shared<Position>(match->first_token(s)); + int abs_pos = match->first_token(s); + int rel_pos = abs_pos - context.sentence_context().get_position(); + return boost::make_shared<Position>(rel_pos); } std::string FirstToken::to_string(const Corpus2::Tagset &tagset) const diff --git a/libwccl/ops/functions/position/lasttoken.cpp b/libwccl/ops/functions/position/lasttoken.cpp index 6d4ca00..6b4f43e 100644 --- a/libwccl/ops/functions/position/lasttoken.cpp +++ b/libwccl/ops/functions/position/lasttoken.cpp @@ -14,13 +14,15 @@ LastToken::BaseRetValPtr LastToken::apply_internal( if (!s) { throw InvalidArgument( "context", - "Supplied context does not have valid Corpus2::AnnotatedSentence."); + "Supplied context does not have a valid Corpus2::AnnotatedSentence."); } const Function<Match>::RetValPtr match = match_expr_->apply(context); if(match->empty()) { return detail::DefaultFunction<Position>()->apply(context); } - return boost::make_shared<Position>(match->last_token(s)); + int abs_pos = match->last_token(s); + int rel_pos = abs_pos - context.sentence_context().get_position(); + return boost::make_shared<Position>(rel_pos); } std::string LastToken::to_string(const Corpus2::Tagset &tagset) const -- GitLab