Skip to content
Snippets Groups Projects
match.h 1.81 KiB
Newer Older
#ifndef LIBWCCL_VALUES_MATCH_H
#define LIBWCCL_VALUES_MATCH_H

#include <libwccl/values/position.h>
#include <libcorpus2/ann/annotatedsentence.h>
#include <libwccl/values/matchvector.h>
#include <libwccl/values/annotationmatch.h>
#include <libwccl/values/tokenmatch.h>

namespace Wccl {

class Match : public Value
{
public:
	WCCL_VALUE_PREAMBLE

	typedef MatchData value_type;

	/**
	 * The default data held is an empty MatchVector
	 */
		: match_(new MatchVector())
	{
	}

	Match(const boost::shared_ptr<MatchData>& data)
		: match_(data)
	{
	}

	Match(const boost::shared_ptr<TokenMatch>& data)
		: match_(data)
	{
	}

	Match(const boost::shared_ptr<AnnotationMatch>& data)
		: match_(data)
	Match(const boost::shared_ptr<MatchVector>& data)
		: match_(data)
	{
	}

	Match(const MatchData& data)
		: match_(data.clone())
	{
	}

	const MatchData& get_value() const {
		return *match_;
	}

	void set_value(const MatchData& m) {
		match_ = m.clone();
	}

	/**
	 * Check if the match is empty (matches nothing). Match objects themselves
	 * are by definition empty, child classes are sometimes or always non-empty.
	 */
	virtual bool empty() const {
		return match_->empty();
	}

	/**
	 * Getter for the first token matched. If the match is empty, must return
	 * Nowhere.
	 */
	virtual Position first_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const {
		return match_->first_token(s);
	}

	/**
	 * Getter for the last token matched. If the match is empty, must return
	 * Nowhere.
	 */
	virtual Position last_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const {
		return match_->last_token(s);
	std::string to_raw_string() const {
		return match_->to_raw_string();
	}

private:
	boost::shared_ptr<MatchData> match_;
};

} /* end ns Wccl */

#endif // LIBWCCL_VALUES_MATCH_H