Skip to content
Snippets Groups Projects
Commit 6a037360 authored by Adam Wardyński's avatar Adam Wardyński
Browse files

Predicate that checks if one set intersects with another

parent 8790f71f
Branches
No related merge requests found
#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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment