Skip to content
Snippets Groups Projects
Commit f15b6a32 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

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.
parent 6264ff5a
Branches
No related merge requests found
......@@ -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
......
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment