diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h new file mode 100644 index 0000000000000000000000000000000000000000..984e80913676f3e77c7f31d0f49b047aae7d7f7a --- /dev/null +++ b/libwccl/ops/equals.h @@ -0,0 +1,62 @@ +#ifndef EQUALS_H +#define EQUALS_H + +#include <boost/shared_ptr.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/count.hpp> +#include <libwccl/ops/predicate.h> +#include <libwccl/ops/formatters.h> + +namespace Wccl { + +/** + * Predicate that checks for equality of values + */ +template <class T> +class Equals : public Predicate { +public: + typedef boost::shared_ptr<Function<T> > ArgFunctionPtr; + + Equals(const ArgFunctionPtr& arg1_expr, const ArgFunctionPtr& arg2_expr) + : arg1_expr_(arg1_expr), arg2_expr_(arg2_expr) + { + BOOST_ASSERT(arg1_expr_); + BOOST_ASSERT(arg2_expr_); + } + + virtual std::string to_string(const Corpus2::Tagset& tagset) const { + return BinaryFunctionFormatter::to_string(tagset, *this, *arg1_expr_, *arg2_expr_); + } + + virtual std::string to_raw_string() const { + return BinaryFunctionFormatter::to_raw_string(*this, *arg1_expr_, *arg2_expr_); + } + + virtual const std::string raw_operator_name() const { + return "equals"; + } + +protected: + const ArgFunctionPtr arg1_expr_; + const ArgFunctionPtr arg2_expr_; + + typedef FunctionBase::BaseRetValPtr BaseRetValPtr; + + /** + * Take values of arguments from expressions and return True if they are equal, + * False otherwise. + */ + virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + boost::shared_ptr<T> arg1 = this->arg1_expr_->apply(context); + boost::shared_ptr<T> arg2 = this->arg2_expr_->apply(context); + if(arg1->equals(*arg2)) { + return Predicate::True->apply(context); + } + return Predicate::False->apply(context); + } +}; + +} /* end ns Wccl */ + +#endif // EQUALS_H