Skip to content
Snippets Groups Projects
Select Git revision
  • ef241c447870fc344a2cdebabcc3066e047c43dc
  • master default protected
  • fix-words-ann
  • wccl-rules-migration
  • develop
5 results

annotationmatch.cpp

Blame
  • 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 */