Select Git revision
annotationmatch.cpp
annotationmatch.cpp 1.06 KiB
#include <libwccl/values/annotationmatch.h>
#include <libwccl/values/position.h>
#include <boost/lexical_cast.hpp>
namespace Wccl {
std::string AnnotationMatch::to_raw_string() const
{
return "ANN[" + boost::lexical_cast<std::string>(abs_pos_) + "," + channel_ + "]";
}
int AnnotationMatch::first_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const
{
const Corpus2::AnnotationChannel& chan = s->get_channel(channel_);
int seg = chan.get_segment_at(abs_pos_);
if (seg > 0) {
for (int i = 0; i < abs_pos_; ++i) {
if (chan.get_segment_at(i) == seg) {
return i;
}
}
return abs_pos_;
} else {
return Position::Nowhere;
}
}
int AnnotationMatch::last_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const
{
const Corpus2::AnnotationChannel& chan = s->get_channel(channel_);
int seg = chan.get_segment_at(abs_pos_);
if (seg > 0) {
for (int i = s->size() - 1; i > abs_pos_; --i) {
if (chan.get_segment_at(i) == seg) {
return i;
}
}
return abs_pos_;
} else {
return Position::Nowhere;
}
}
} /* end ns Wccl */