Skip to content
Snippets Groups Projects
Commit 50606d90 authored by ilor's avatar ilor
Browse files

Merge branch 'master' of nlp.pwr.wroc.pl:wccl

parents 5a14e741 1a999453
Branches
No related merge requests found
...@@ -18,20 +18,26 @@ void MarkMatch::execute(const ActionExecContext& context) const ...@@ -18,20 +18,26 @@ void MarkMatch::execute(const ActionExecContext& context) const
boost::shared_ptr<const Match> match_from = match_from_->apply(context); boost::shared_ptr<const Match> match_from = match_from_->apply(context);
boost::shared_ptr<const Match> match_to = boost::shared_ptr<const Match> match_to =
(match_from_.get() == match_to_.get()) ? match_from : match_to_->apply(context); (match_from_.get() == match_to_.get()) ? match_from : match_to_->apply(context);
boost::shared_ptr<const Match> head_match =
(match_from_.get() == head_match_.get()) ? match_from : head_match_->apply(context);
int abs_left = match_from->first_token(as).get_value(); int abs_left = match_from->first_token(as).get_value();
int abs_right = match_to->last_token(as).get_value();
if (abs_left < 0) { if (abs_left < 0) {
throw WcclError("Received starting match that points outside sentence."); throw WcclError("Received starting match that points outside sentence.");
} }
int abs_right = match_to->last_token(as).get_value();
if (abs_right >= sc.size()) { if (abs_right >= sc.size()) {
throw WcclError("Received ending match that points outside sentence."); throw WcclError("Received ending match that points outside sentence.");
} }
if (abs_left > abs_right) { if (abs_left > abs_right) {
throw WcclError("Received starting match points after the received ending match."); throw WcclError("Received starting match points after the received ending match.");
} }
// TODO: what about head in this mark from match actions? Mark from tag actions does have it.
int abs_head = abs_left; int abs_head = head_match->first_token(as).get_value();
if (abs_head < abs_left || abs_head > abs_right) {
throw WcclError("Received head match points outside range defined by start and end matches.");
}
if (!as->has_channel(chan_name_)) { if (!as->has_channel(chan_name_)) {
as->create_channel(chan_name_); as->create_channel(chan_name_);
......
...@@ -12,13 +12,30 @@ public: ...@@ -12,13 +12,30 @@ public:
MarkMatch( MarkMatch(
const boost::shared_ptr<Function<Match> >& match_from, const boost::shared_ptr<Function<Match> >& match_from,
const boost::shared_ptr<Function<Match> >& match_to, const boost::shared_ptr<Function<Match> >& match_to,
const boost::shared_ptr<Function<Match> >& head_match,
const std::string& annotation_name) const std::string& annotation_name)
: match_from_(match_from), : match_from_(match_from),
match_to_(match_to), match_to_(match_to),
head_match_(head_match),
chan_name_(annotation_name) chan_name_(annotation_name)
{ {
BOOST_ASSERT(match_from_); BOOST_ASSERT(match_from_);
BOOST_ASSERT(match_to_); BOOST_ASSERT(match_to_);
BOOST_ASSERT(head_match_);
}
MarkMatch(
const boost::shared_ptr<Function<Match> >& match_from,
const boost::shared_ptr<Function<Match> >& match_to,
const std::string& annotation_name)
: match_from_(match_from),
match_to_(match_to),
head_match_(match_from),
chan_name_(annotation_name)
{
BOOST_ASSERT(match_from_);
BOOST_ASSERT(match_to_);
BOOST_ASSERT(head_match_);
} }
MarkMatch( MarkMatch(
...@@ -26,10 +43,12 @@ public: ...@@ -26,10 +43,12 @@ public:
const std::string& annotation_name) const std::string& annotation_name)
: match_from_(match_from_to), : match_from_(match_from_to),
match_to_(match_from_to), match_to_(match_from_to),
head_match_(match_from_to),
chan_name_(annotation_name) chan_name_(annotation_name)
{ {
BOOST_ASSERT(match_from_); BOOST_ASSERT(match_from_);
BOOST_ASSERT(match_to_); BOOST_ASSERT(match_to_);
BOOST_ASSERT(head_match_);
} }
/** /**
* @returns Name of the action. * @returns Name of the action.
...@@ -59,6 +78,7 @@ protected: ...@@ -59,6 +78,7 @@ protected:
private: private:
const boost::shared_ptr<Function<Match> >& match_from_; const boost::shared_ptr<Function<Match> >& match_from_;
const boost::shared_ptr<Function<Match> >& match_to_; const boost::shared_ptr<Function<Match> >& match_to_;
const boost::shared_ptr<Function<Match> >& head_match_;
const std::string chan_name_; const std::string chan_name_;
}; };
......
...@@ -1947,10 +1947,13 @@ match_mark_action ...@@ -1947,10 +1947,13 @@ match_mark_action
{ {
boost::shared_ptr<Function<Match> > match_to; boost::shared_ptr<Function<Match> > match_to;
boost::shared_ptr<Function<Match> > match_from; boost::shared_ptr<Function<Match> > match_from;
boost::shared_ptr<Function<Match> > head_match;
} }
: "mark" LPAREN : "mark" LPAREN
match_from = match_fit[tagset, vars] COMMA match_from = match_fit[tagset, vars] COMMA
(match_to = match_fit[tagset, vars] COMMA) ? ( match_to = match_fit[tagset, vars] COMMA
( head_match = match_fit[tagset, vars] COMMA )?
)?
annotation_name : STRING annotation_name : STRING
RPAREN { RPAREN {
if (!match_to) { if (!match_to) {
...@@ -1959,11 +1962,20 @@ match_mark_action ...@@ -1959,11 +1962,20 @@ match_mark_action
match_from, match_from,
((antlr::Token*)annotation_name)->getText())); ((antlr::Token*)annotation_name)->getText()));
} else { } else {
m_act.reset( if (!head_match) {
new MarkMatch( m_act.reset(
match_from, new MarkMatch(
match_to, match_from,
((antlr::Token*)annotation_name)->getText())); match_to,
((antlr::Token*)annotation_name)->getText()));
} else {
m_act.reset(
new MarkMatch(
match_from,
match_to,
head_match,
((antlr::Token*)annotation_name)->getText()));
}
} }
} }
; ;
......
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