Skip to content
Snippets Groups Projects
Select Git revision
  • cd1e0c1124efb8a94cf2f264bf47d6b8ba54e00d
  • master default protected
  • develop protected
  • feat_remove_attr
  • python2.7
  • python3.8
6 results

lexer.h

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