Skip to content
Snippets Groups Projects
isinside.h 1.44 KiB
#ifndef LIBWCCL_OPS_FUNCTIONS_BOOL_PREDICATES_ISINSIDE_H
#define LIBWCCL_OPS_FUNCTIONS_BOOL_PREDICATES_ISINSIDE_H

#include <libwccl/ops/functions/bool/predicate.h>
#include <libwccl/values/position.h>

namespace Wccl {

/**
 * Predicate that checks if a position is within sentence boundaries
 */
class IsInside : public Predicate
{
public:
	typedef boost::shared_ptr<Function<Position> > PosFunctionPtr;

	IsInside(const PosFunctionPtr& pos_expr)
		: pos_expr_(pos_expr)
	{
		BOOST_ASSERT(pos_expr_);
	}

	/**
	 * @returns String representation of the function in the form of:
	 * "inside(arg_expr_string)"
	 */
	std::string to_string(const Corpus2::Tagset& tagset) const;

	/**
	 * @returns Name of the function: "inside"
	 */
	std::string raw_name() const {
		return "inside";
	}

protected:
	const PosFunctionPtr pos_expr_;

	/**
	 * Takes values of position from argument, and checks if it is inside sentence
	 * boundaries.
	 * @returns True value if position is within sentence boundaries, False otherwise.
	 */
	BaseRetValPtr apply_internal(const FunExecContext& context) const;

	/**
	 * Writes raw string representation of the function in the form of:
	 * "inside(arg_expr_raw_string)"
	 * @note This version doesn't require a tagset, but may be incomplete
	 * and/or contain internal info.
	 * @returns Stream written to.
	 */
	std::ostream& write_to(std::ostream& os) const;
};

} /* end ns Wccl */

#endif // LIBWCCL_OPS_FUNCTIONS_BOOL_PREDICATES_ISINSIDE_H