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

Rewrite MatchOperator to use ConjConditions.

parent 679dd99a
No related branches found
No related tags found
No related merge requests found
#include <libwccl/ops/match/applyoperator.h>
#include <libwccl/values/matchvector.h>
#include <libpwrutils/foreach.h>
namespace Wccl {
......@@ -35,7 +36,7 @@ void ApplyOperator::execute(const ActionExecContext &context) const
should_act = _conditions[i]->apply(context)->get_value();
}
if (should_act) {
matches->append(match);
matches->append(match); // the match goes to $m:_M[0]
foreach (const boost::shared_ptr<const MatchAction>& action, _actions) {
action->execute(context);
}
......
#include <libwccl/ops/match/matchoperator.h>
#include <libpwrutils/foreach.h>
#include <sstream>
namespace Wccl {
......@@ -8,47 +7,25 @@ boost::shared_ptr<Match> MatchOperator::apply(
boost::shared_ptr<Position> iter_pos,
const FunExecContext& context) const
{
boost::shared_ptr<MatchVector> matches(new MatchVector());
int orig_iter_pos = iter_pos->get_value();
foreach (const boost::shared_ptr<const MatchCondition>& cond, _conditions) {
MatchResult res = cond->apply(iter_pos, context);
MatchResult res = _conditions->apply(iter_pos, context);
if(res.matched()) {
matches->append(res.get_match());
} else {
matches.reset(new MatchVector());
iter_pos->set_value(orig_iter_pos + 1);
return matches;
return res.get_match();
}
}
return matches;
iter_pos->set_value(orig_iter_pos + 1);
return boost::make_shared<Match>();
}
std::string MatchOperator::to_string(const Corpus2::Tagset& tagset) const
{
std::ostringstream ostream;
ostream << name() << "(";
for(size_t i = 0; i < _conditions.size(); ++i) {
if (i != 0) {
ostream << ", ";
}
ostream << _conditions[i]->to_string(tagset);
}
ostream << ")";
ostream << name() << _conditions->to_string(tagset);
return ostream.str();
}
std::ostream& MatchOperator::write_to(std::ostream &ostream) const
{
ostream << name() << "(";
for(size_t i = 0; i < _conditions.size(); ++i) {
if (i != 0) {
ostream << ", ";
}
ostream << *_conditions[i];
}
ostream << ")";
return ostream;
return ostream << name() << *_conditions;
}
} /* end ns Wccl */
#ifndef LIBWCCL_OPS_MATCH_MATCHOPERATOR_H
#define LIBWCCL_OPS_MATCH_MATCHOPERATOR_H
#include <libwccl/ops/match/matchcondition.h>
#include <libwccl/values/matchvector.h>
#include <libwccl/ops/match/conditions/conjconditions.h>
namespace Wccl {
......@@ -12,8 +11,9 @@ namespace Wccl {
class MatchOperator : public Expression
{
public:
MatchOperator(const std::vector< boost::shared_ptr<const MatchCondition> >& conditions)
MatchOperator(const boost::shared_ptr<ConjConditions>& conditions)
: _conditions(conditions) {
BOOST_ASSERT(_conditions);
}
/**
......@@ -52,7 +52,7 @@ protected:
std::ostream& write_to(std::ostream& ostream) const;
private:
const std::vector<boost::shared_ptr<const MatchCondition> > _conditions;
const boost::shared_ptr<ConjConditions> _conditions;
};
} /* end ns Wccl */
......
......@@ -70,6 +70,7 @@ header {
// Match operators
#include <libwccl/values/tokenmatch.h>
#include <libwccl/values/annotationmatch.h>
#include <libwccl/values/matchvector.h>
#include <libwccl/ops/match/applyoperator.h>
// Unicode String
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment