From 6a0373608d2709e87fcf444b996008958e16e71d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wardy=C5=84ski?= <no@email> Date: Mon, 8 Nov 2010 15:01:02 +0100 Subject: [PATCH] Predicate that checks if one set intersects with another --- libwccl/ops/intersects.h | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 libwccl/ops/intersects.h diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h new file mode 100644 index 0000000..25cc2cb --- /dev/null +++ b/libwccl/ops/intersects.h @@ -0,0 +1,58 @@ +#ifndef INTERSECTS_H +#define INTERSECTS_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 intersects with another + */ +template <class T> +class Intersects : public SetPredicate<T> +{ +public: + typedef typename SetPredicate<T>::SetFunctionPtr SetFunctionPtr; + + Intersects(const SetFunctionPtr& set1_expr, const SetFunctionPtr& set2_expr) + : SetPredicate<T>(set1_expr, set2_expr) + { + } + + virtual const std::string raw_operator_name() const { + return "inter"; + } + +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> set1 = this->set1_expr_->apply(context); + boost::shared_ptr<T> set2 = this->set2_expr_->apply(context); + if(set1->is_subset_of(*set2)) { + return Predicate::True->apply(context); + } + return Predicate::False->apply(context); + } + +}; + +} /* end ns Wccl */ + + +#endif // INTERSECTS_H -- GitLab