From f88f97eb62ffc9f0257349e586ee34ae86e6c8dc Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(B-4.4.46a)> Date: Fri, 11 Mar 2011 19:49:11 +0100 Subject: [PATCH] MatchOperator to act more like a function (FunExecContext). --- libwccl/ops/match/matchoperator.cpp | 6 ++---- libwccl/ops/match/matchoperator.h | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/libwccl/ops/match/matchoperator.cpp b/libwccl/ops/match/matchoperator.cpp index f18a8e2..af29636 100644 --- a/libwccl/ops/match/matchoperator.cpp +++ b/libwccl/ops/match/matchoperator.cpp @@ -4,11 +4,9 @@ namespace Wccl { -const char* MatchOperator::IterationPosVarName = "$_"; - -boost::shared_ptr<MatchVector> MatchOperator::execute( +boost::shared_ptr<Match> MatchOperator::apply( boost::shared_ptr<Position> iter_pos, - const ActionExecContext &context) const + const FunExecContext& context) const { boost::shared_ptr<MatchVector> matches(new MatchVector()); int orig_iter_pos = iter_pos->get_value(); diff --git a/libwccl/ops/match/matchoperator.h b/libwccl/ops/match/matchoperator.h index 348b416..ff679ca 100644 --- a/libwccl/ops/match/matchoperator.h +++ b/libwccl/ops/match/matchoperator.h @@ -12,8 +12,6 @@ namespace Wccl { class MatchOperator : public Expression { public: - static const char* IterationPosVarName; - MatchOperator(const std::vector< boost::shared_ptr<const MatchCondition> >& conditions) : _conditions(conditions) { } @@ -30,6 +28,20 @@ public: */ std::string to_string(const Corpus2::Tagset& tagset) const; + /** + * 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. + * 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 + * @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; + protected: /** * Writes string representation of the operator to @@ -39,19 +51,6 @@ protected: */ std::ostream& write_to(std::ostream& ostream) const; - /** - * Executes the operator on given context. - * @returns Vector of matches corresponding to match conditions, - * if all conditions were met. In such case position $_ is advanced past matched tokens. - * Empty MatchVector is returned if any of conditions was not met. - * In such case Position $_ is advanced by 1. - * @param iter_pos Pointer to the variable $_ from context's Variables - * @param context Execution context - current sentence and Variables to operate on - */ - boost::shared_ptr<MatchVector> execute( - boost::shared_ptr<Position> iter_pos, - const ActionExecContext &context) const; - private: const std::vector<boost::shared_ptr<const MatchCondition> > _conditions; }; -- GitLab