From 9dbd4bef76650c47c6f98223d9b076c3ac6d244b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wardy=C5=84ski?= <no@email> Date: Mon, 8 Nov 2010 14:49:52 +0100 Subject: [PATCH] Template class for set predicate "IsSubsetOf" --- libwccl/ops/issubsetof.h | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libwccl/ops/issubsetof.h diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h new file mode 100644 index 0000000..46a7423 --- /dev/null +++ b/libwccl/ops/issubsetof.h @@ -0,0 +1,60 @@ +#ifndef ISSUBSETOF_H +#define ISSUBSETOF_H + +#include <boost/shared_ptr.hpp> + +#include <libcorpus2/tagset.h> + +#include <libwccl/values/strset.h> +#include <libwccl/values/tset.h> +#include <libwccl/values/bool.h> +#include <libwccl/ops/setpredicate.h> +#include <libwccl/ops/formatters.h> + +namespace Wccl { + +/** + * Class that realises a predicate checking if one set is a subset of another + */ +template <class T> +class IsSubsetOf : public SetPredicate<T> +{ +public: + typedef typename SetPredicate<T>::SetFunctionPtr SetFunctionPtr; + + IsSubsetOf(const SetFunctionPtr& subset_expr, const SetFunctionPtr& set_expr) + : SetPredicate<T>(subset_expr, set_expr) + { + } + + virtual const std::string raw_operator_name() const { + return "in"; + } + +protected: + + typedef typename SetPredicate<T>::BaseRetValPtr BaseRetValPtr; + + /** + * Take value of possible subset in question. If it is an empty set, return False. + * Otherwise, take value of the set that is being compared to. + * Return True if the possible subset is indeed a subset of the compared set, + * otherwise return False. + */ + virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + boost::shared_ptr<T> possible_subset = this->set1_expr_->apply(context); + if(!possible_subset->empty()) { + boost::shared_ptr<T> set_compared_to = this->set2_expr_->apply(context); + if(possible_subset->is_subset_of(*set_compared_to)) { + return Predicate::True->apply(context); + } + } + return Predicate::False->apply(context); + } + +}; + +} /* end ns Wccl */ + + +#endif // ISSUBSETOF_H -- GitLab