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

Tweak some code.

MatchResult - change constructor so when you provide Match it defaults to matched = true.
TokenCondition - be a bit defensive about possibility of inner predicates changing $_
parent 26401e18
Branches
No related merge requests found
......@@ -3,10 +3,10 @@
namespace Wccl {
TokenCondition::TokenCondition(const boost::shared_ptr<Function<Bool> >& predicate)
: _predicate(predicate)
{
BOOST_ASSERT(_predicate);
}
std::string TokenCondition::name() const
......@@ -21,14 +21,15 @@ std::string TokenCondition::to_string(const Corpus2::Tagset& tagset) const
MatchResult TokenCondition::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const
{
int orig_iter = iter_pos->get_value();
if (_predicate->apply(context)->get_value()) {
boost::shared_ptr<Match> match = boost::shared_ptr<Match>(new TokenMatch(
context.sentence_context().get_abs_position(*iter_pos)));
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(iter_pos->get_value() + 1);
return MatchResult(true, match);
iter_pos->set_value(orig_iter + 1);
return MatchResult(match);
}
else {
iter_pos->set_value(orig_iter);
return MatchResult();
}
}
......
......@@ -12,7 +12,7 @@ namespace Wccl {
class MatchResult
{
public:
MatchResult(bool matched, const boost::shared_ptr<Match>& match);
MatchResult(const boost::shared_ptr<Match>& match);
MatchResult();
boost::shared_ptr<Match> get_match() const;
bool matched() const;
......@@ -30,8 +30,8 @@ MatchResult::MatchResult() : _matched(false), _match() {
}
inline
MatchResult::MatchResult(bool matched, const boost::shared_ptr<Match>& match)
: _matched(matched),
MatchResult::MatchResult(const boost::shared_ptr<Match>& match)
: _matched(true),
_match(match) {
}
......
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