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

MatchOperator to act more like a function (FunExecContext).

parent f886a617
Branches
No related tags found
No related merge requests found
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
namespace Wccl { namespace Wccl {
const char* MatchOperator::IterationPosVarName = "$_"; boost::shared_ptr<Match> MatchOperator::apply(
boost::shared_ptr<MatchVector> MatchOperator::execute(
boost::shared_ptr<Position> iter_pos, boost::shared_ptr<Position> iter_pos,
const ActionExecContext &context) const const FunExecContext& context) const
{ {
boost::shared_ptr<MatchVector> matches(new MatchVector()); boost::shared_ptr<MatchVector> matches(new MatchVector());
int orig_iter_pos = iter_pos->get_value(); int orig_iter_pos = iter_pos->get_value();
......
...@@ -12,8 +12,6 @@ namespace Wccl { ...@@ -12,8 +12,6 @@ namespace Wccl {
class MatchOperator : public Expression class MatchOperator : public Expression
{ {
public: public:
static const char* IterationPosVarName;
MatchOperator(const std::vector< boost::shared_ptr<const MatchCondition> >& conditions) MatchOperator(const std::vector< boost::shared_ptr<const MatchCondition> >& conditions)
: _conditions(conditions) { : _conditions(conditions) {
} }
...@@ -30,6 +28,20 @@ public: ...@@ -30,6 +28,20 @@ public:
*/ */
std::string to_string(const Corpus2::Tagset& tagset) const; 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: protected:
/** /**
* Writes string representation of the operator to * Writes string representation of the operator to
...@@ -39,19 +51,6 @@ protected: ...@@ -39,19 +51,6 @@ protected:
*/ */
std::ostream& write_to(std::ostream& ostream) const; 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: private:
const std::vector<boost::shared_ptr<const MatchCondition> > _conditions; const std::vector<boost::shared_ptr<const MatchCondition> > _conditions;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment