From c79a05b8a56fcb9b1c4d02eac7eb2abdba2fbef8 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(win7-laptop)> Date: Mon, 4 Apr 2011 13:30:00 +0200 Subject: [PATCH] Finishing up change $_ -> current sentence pos (internal changes). --- libwccl/ops/match/applyoperator.cpp | 16 ++++++---------- libwccl/ops/match/conditions/conjconditions.cpp | 8 ++++---- libwccl/ops/match/conditions/conjconditions.h | 4 ++-- libwccl/ops/match/conditions/optionalmatch.cpp | 8 ++++---- libwccl/ops/match/conditions/optionalmatch.h | 4 ++-- libwccl/ops/match/conditions/repeatedmatch.cpp | 10 +++++----- libwccl/ops/match/conditions/repeatedmatch.h | 4 ++-- libwccl/ops/match/conditions/tokencondition.cpp | 12 ++++++------ libwccl/ops/match/conditions/tokencondition.h | 4 ++-- libwccl/ops/match/matchcondition.h | 6 +++--- libwccl/ops/match/matchoperator.cpp | 10 ++++------ libwccl/ops/match/matchoperator.h | 11 ++++------- 12 files changed, 44 insertions(+), 53 deletions(-) diff --git a/libwccl/ops/match/applyoperator.cpp b/libwccl/ops/match/applyoperator.cpp index cfecd52..a24ce26 100644 --- a/libwccl/ops/match/applyoperator.cpp +++ b/libwccl/ops/match/applyoperator.cpp @@ -20,14 +20,14 @@ ApplyOperator::ApplyOperator( void ApplyOperator::execute(const ActionExecContext &context) const { - boost::shared_ptr<Position> iter_pos(new Position(0)); boost::shared_ptr<MatchVector> matches = boost::dynamic_pointer_cast<MatchVector>(context.variables()->get_fast(_matches)); + context.sentence_context().goto_start(); while(context.sentence_context().is_current_inside()) { - // Set initial values of $_ and $m:_M variables for this iteration and launch the match: - iter_pos->set_value(0); + int orig_pos = context.sentence_context().get_position(); + // Set initial value for $m:_M variable for this iteration and launch the match: matches->clear(); - boost::shared_ptr<Match> match = _match_op->apply(iter_pos, context); + boost::shared_ptr<Match> match = _match_op->apply(context); // Execute the actions only if match isn't empty and all post-conditions are met: bool should_act = !match->empty(); for(size_t i = 0; should_act && i < _conditions->size(); ++i) { @@ -40,12 +40,8 @@ void ApplyOperator::execute(const ActionExecContext &context) const } } // Inner operators (match and its conditions) are responsible for properly - // advancing $_ variable. - // After an iteration, we increase current sentence position by the value of $_ - // and repeat until current sentence position goes outside. - BOOST_ASSERT(iter_pos->get_value() > 0); - context.sentence_context().set_position( - context.sentence_context().get_position() + iter_pos->get_value()); + // advancing current sentence position. + BOOST_ASSERT(context.sentence_context().get_position() > orig_pos); } } diff --git a/libwccl/ops/match/conditions/conjconditions.cpp b/libwccl/ops/match/conditions/conjconditions.cpp index 7dd80eb..11b1c14 100644 --- a/libwccl/ops/match/conditions/conjconditions.cpp +++ b/libwccl/ops/match/conditions/conjconditions.cpp @@ -11,17 +11,17 @@ ConjConditions::ConjConditions(const std::vector< boost::shared_ptr<const MatchC BOOST_ASSERT(_conditions.size() > 0); } -MatchResult ConjConditions::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const +MatchResult ConjConditions::apply(const ActionExecContext& context) const { boost::shared_ptr<MatchVector> matches(new MatchVector()); - int orig_iter_pos = iter_pos->get_value(); + int orig_pos = context.sentence_context().get_position(); foreach (const boost::shared_ptr<const MatchCondition>& cond, _conditions) { - MatchResult res = cond->apply(iter_pos, context); + MatchResult res = cond->apply(context); if(res.matched()) { matches->append(res.get_match()); } else { - iter_pos->set_value(orig_iter_pos); + context.sentence_context().set_position(orig_pos); return MatchResult(); } } diff --git a/libwccl/ops/match/conditions/conjconditions.h b/libwccl/ops/match/conditions/conjconditions.h index 38d0a14..d2df5c4 100644 --- a/libwccl/ops/match/conditions/conjconditions.h +++ b/libwccl/ops/match/conditions/conjconditions.h @@ -22,10 +22,10 @@ public: } /** * Applies the condition to the given execution context. - * If match is found, the current iter Position "$_" is increased + * If match is found, the current position in sentence is increased * by one (the size of token match, which is always one). */ - MatchResult apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const; + MatchResult apply(const ActionExecContext& context) const; /** * @returns String representation of the MatchCondition diff --git a/libwccl/ops/match/conditions/optionalmatch.cpp b/libwccl/ops/match/conditions/optionalmatch.cpp index bbc99ae..0311689 100644 --- a/libwccl/ops/match/conditions/optionalmatch.cpp +++ b/libwccl/ops/match/conditions/optionalmatch.cpp @@ -10,14 +10,14 @@ OptionalMatch::OptionalMatch(const boost::shared_ptr<ConjConditions>& conditions BOOST_ASSERT(_conditions); } -MatchResult OptionalMatch::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const +MatchResult OptionalMatch::apply(const ActionExecContext& context) const { - int orig_pos = iter_pos->get_value(); - MatchResult res = _conditions->apply(iter_pos, context); + int orig_pos = context.sentence_context().get_position(); + MatchResult res = _conditions->apply(context); if (res.matched()) { return res; } - iter_pos->set_value(orig_pos); + context.sentence_context().set_position(orig_pos); return MatchResult(boost::make_shared<Match>()); } diff --git a/libwccl/ops/match/conditions/optionalmatch.h b/libwccl/ops/match/conditions/optionalmatch.h index d9f3c1d..97dfb07 100644 --- a/libwccl/ops/match/conditions/optionalmatch.h +++ b/libwccl/ops/match/conditions/optionalmatch.h @@ -25,11 +25,11 @@ public: * If the match, was successfull the result consists of "true" * and the match. * If there was no match, "true" is returned anyway, but with a default Match. - * If match is found, the current iter Position "$_" is increased + * If match is found, the current sentence Position is increased * as to point one token after all the matched tokens, otherwise * it stays unchanged. */ - MatchResult apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const; + MatchResult apply(const ActionExecContext& context) const; /** * @returns String representation of the MatchCondition diff --git a/libwccl/ops/match/conditions/repeatedmatch.cpp b/libwccl/ops/match/conditions/repeatedmatch.cpp index a43fb47..f2fad5b 100644 --- a/libwccl/ops/match/conditions/repeatedmatch.cpp +++ b/libwccl/ops/match/conditions/repeatedmatch.cpp @@ -10,20 +10,20 @@ RepeatedMatch::RepeatedMatch(const boost::shared_ptr<ConjConditions>& conditions BOOST_ASSERT(_conditions); } -MatchResult RepeatedMatch::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const +MatchResult RepeatedMatch::apply(const ActionExecContext& context) const { boost::shared_ptr<MatchVector> match(new MatchVector()); - int orig_pos = iter_pos->get_value(); - MatchResult res = _conditions->apply(iter_pos, context); + int orig_pos = context.sentence_context().get_position(); + MatchResult res = _conditions->apply(context); if (res.matched()) { do { match->append(res.get_match()); - res = _conditions->apply(iter_pos, context); + res = _conditions->apply(context); } while (res.matched()); return MatchResult(match); } else { - iter_pos->set_value(orig_pos); + context.sentence_context().set_position(orig_pos); return MatchResult(); } } diff --git a/libwccl/ops/match/conditions/repeatedmatch.h b/libwccl/ops/match/conditions/repeatedmatch.h index 0454373..1d8764e 100644 --- a/libwccl/ops/match/conditions/repeatedmatch.h +++ b/libwccl/ops/match/conditions/repeatedmatch.h @@ -26,11 +26,11 @@ public: * and the MatchVector constructed out of individual match vectors coming * from each successful repetition. * If there was no match, "false" is returned along with a default Match. - * If match is found, the current iter Position "$_" is increased + * If match is found, the current sentence Position is increased * as to point one token after all the matched tokens, otherwise * it stays unchanged. */ - MatchResult apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const; + MatchResult apply(const ActionExecContext& context) const; /** * @returns String representation of the MatchCondition diff --git a/libwccl/ops/match/conditions/tokencondition.cpp b/libwccl/ops/match/conditions/tokencondition.cpp index 51604e6..e7f670f 100644 --- a/libwccl/ops/match/conditions/tokencondition.cpp +++ b/libwccl/ops/match/conditions/tokencondition.cpp @@ -19,17 +19,17 @@ std::string TokenCondition::to_string(const Corpus2::Tagset& tagset) const return _predicate->to_string(tagset); } -MatchResult TokenCondition::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const +MatchResult TokenCondition::apply(const ActionExecContext& context) const { - int orig_iter = iter_pos->get_value(); + int orig_iter = context.sentence_context().get_position(); if (_predicate->apply(context)->get_value()) { - 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(orig_iter + 1); + boost::shared_ptr<Match> 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 { - iter_pos->set_value(orig_iter); + context.sentence_context().set_position(orig_iter); return MatchResult(); } } diff --git a/libwccl/ops/match/conditions/tokencondition.h b/libwccl/ops/match/conditions/tokencondition.h index 94f0bf2..cc86a27 100644 --- a/libwccl/ops/match/conditions/tokencondition.h +++ b/libwccl/ops/match/conditions/tokencondition.h @@ -20,10 +20,10 @@ public: std::string name() const; /** * Applies the condition to the given execution context. - * If match is found, the current iter Position "$_" is increased + * If match is found, the current sentence Position is increased * by one (the size of token match, which is always one). */ - MatchResult apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const; + MatchResult apply(const ActionExecContext& context) const; /** * @returns String representation of the Action diff --git a/libwccl/ops/match/matchcondition.h b/libwccl/ops/match/matchcondition.h index 6e8fddf..3b48506 100644 --- a/libwccl/ops/match/matchcondition.h +++ b/libwccl/ops/match/matchcondition.h @@ -1,7 +1,7 @@ #ifndef LIBWCCL_OPS_MATCH_MATCHCONDITION_H #define LIBWCCL_OPS_MATCH_MATCHCONDITION_H -#include <libwccl/ops/funexeccontext.h> +#include <libwccl/ops/actionexeccontext.h> #include <libwccl/ops/expression.h> #include <libwccl/ops/match/matchresult.h> @@ -19,10 +19,10 @@ public: virtual std::string name() const = 0; /** * Applies the condition to the given execution context. - * If match is found, the current iter position "$_" is + * If match is found, the current sentence position is * set to position right after the match. */ - virtual MatchResult apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const = 0; + virtual MatchResult apply(const ActionExecContext& context) const = 0; }; } /* end ns Wccl */ diff --git a/libwccl/ops/match/matchoperator.cpp b/libwccl/ops/match/matchoperator.cpp index 4cb8ec9..26a46e0 100644 --- a/libwccl/ops/match/matchoperator.cpp +++ b/libwccl/ops/match/matchoperator.cpp @@ -3,16 +3,14 @@ namespace Wccl { -boost::shared_ptr<Match> MatchOperator::apply( - boost::shared_ptr<Position> iter_pos, - const FunExecContext& context) const +boost::shared_ptr<Match> MatchOperator::apply(const ActionExecContext& context) const { - int orig_iter_pos = iter_pos->get_value(); - MatchResult res = _conditions->apply(iter_pos, context); + int orig_pos = context.sentence_context().get_position(); + MatchResult res = _conditions->apply(context); if(res.matched()) { return res.get_match(); } - iter_pos->set_value(orig_iter_pos + 1); + context.sentence_context().set_position(orig_pos + 1); return boost::make_shared<Match>(); } diff --git a/libwccl/ops/match/matchoperator.h b/libwccl/ops/match/matchoperator.h index dd6745b..000c38c 100644 --- a/libwccl/ops/match/matchoperator.h +++ b/libwccl/ops/match/matchoperator.h @@ -31,16 +31,13 @@ public: /** * Applies the operator to the given context. * @returns Vector of matches corresponding to match conditions, - * if all conditions were met. In such case position $_ points one position - * ahead of matched tokens. + * if all conditions were met. In such case current sentence position + * points to one position ahead of matched tokens. * Empty MatchVector is returned if any of the conditions was not met. - * In such case Position $_ is advanced by 1. - * @param iter_pos Pointer to the variable $_ from context's Variables + * In such case current Position in sentence is advanced by 1. * @param context Execution context - current sentence and Variables to operate on */ - boost::shared_ptr<Match> apply( - boost::shared_ptr<Position> iter_pos, - const FunExecContext& context) const; + boost::shared_ptr<Match> apply(const ActionExecContext& context) const; protected: /** -- GitLab