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

LogicalPredicate, abstract base class for predicates that are logical...

LogicalPredicate, abstract base class for predicates that are logical functions taking any number of arguments
parent cb2f2f8c
Branches
No related merge requests found
......@@ -16,6 +16,7 @@ set(LIBS ${LIBS} ${Boost_LIBRARIES})
SET(libwccl_STAT_SRC
exception.cpp
main.cpp
ops/logicalpredicate.cpp
ops/predicate.cpp
sentencecontext.cpp
values/bool.cpp
......
#include <libwccl/ops/logicalpredicate.h>
namespace Wccl {
std::string LogicalPredicate::to_string(const Corpus2::Tagset& tagset) const
{
std::string s(operator_name(tagset));
s.append("(");
BoolFunctionPtrVector::const_iterator it = expressions_->begin();
while(it != expressions_->end()) {
s.append((*it)->to_string(tagset));
if(++it != expressions_->end()) {
s.append(", ");
}
}
s.append(")");
return s;
}
std::string LogicalPredicate::to_raw_string() const
{
std::string s(raw_operator_name());
s.append("(");
BoolFunctionPtrVector::const_iterator it = expressions_->begin();
while(it != expressions_->end()) {
s.append((*it)->to_raw_string());
if(++it != expressions_->end()) {
s.append(", ");
}
}
s.append(")");
return s;
}
} /* end ns Wccl */
#ifndef LOGICALPREDICATE_H
#define LOGICALPREDICATE_H
#include <vector>
#include <boost/shared_array.hpp>
#include <boost/assert.hpp>
#include <libcorpus2/tagset.h>
#include <libwccl/ops/predicate.h>
namespace Wccl {
/**
* Abstract base class for predicates which are logical functions
* (over any number of arguments)
*/
class LogicalPredicate : public Predicate {
public:
typedef boost::shared_ptr<Function<Bool> > BoolFunctionPtr;
typedef std::vector<BoolFunctionPtr> BoolFunctionPtrVector;
LogicalPredicate(const boost::shared_ptr<BoolFunctionPtrVector>& expressions)
: expressions_(expressions)
{
BOOST_ASSERT(expressions_);
BOOST_ASSERT(expressions_->size() > 0);
}
/**
* String representation of the logical predicate, realised by default
* as "operator_name(expr1_string, ..., exprn_string)"
*/
virtual std::string to_string(const Corpus2::Tagset& tagset) const;
/**
* String representation of the logical predicate, realised by default
* as "raw_operator_name(raw_expr1_string, ..., raw_exprn_string)"
* (this version doesn't require tagset, but may be incomplete and/or
* contain internal info)
*/
virtual std::string to_raw_string() const;
protected:
const boost::shared_ptr<BoolFunctionPtrVector> expressions_;
};
} /* end ns Wccl */
#endif // LOGICALPREDICATE_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