#ifndef KNOWLEDGE_EXPRESSION_H_
#define KNOWLEDGE_EXPRESSION_H_
namespace rule {
class knowledge_base;
class knowledge_rule;
namespace internal {
typedef std::set<std::string> var_set_t;
typedef std::map<std::string, std::string> var_map_t;
// Utility function to rename variables
inline std::string
get_new_name_for(std::string const& name, var_map_t & map, int & ivar)
{
var_map_t::iterator itor = map.find(name);
if(itor != map.end()) return itor->second;
std::string new_name = "?x" + boost::lexical_cast<std::string>(++ivar);
map.insert(var_map_t::value_type(name, new_name));
return new_name;
};
/////////////////////////////////////////////////////////////////////////////////////////
// class match_result
//
/////////////////////////////////////////////////////////////////////////////////////////
class match_result
{
enum argument_type {
vaa, aav, ava, vav, avv, vva, vvv, unknown
};
public:
match_result():
m_type(unknown),
m_match(0){};
match_result(var_set_t const& idx_map, index_type const& u, index_type const& v, index_type const& w):
m_type(unknown),
m_match(0){};
match_result(var_set_t const& idx_map, index_type const& u, index_type const& v, std::string const& w):
m_type(aav),
m_match(0)
{
if(std::find(idx_map.begin(), idx_map.end(), w) != idx_map.end()) set_match(false, false, true);
};
match_result(var_set_t const& idx_map, index_type const& u, std::string const& v, index_type const& w):
m_type(ava),
m_match(0)
{
if(std::find(idx_map.begin(), idx_map.end(), v) != idx_map.end()) set_match(false, true, false);
};
match_result(var_set_t const& idx_map, index_type const& u, std::string const& v, std::string const& w):
m_type(avv),
m_match(0)
{
bool is_v=false, is_w=false;
var_set_t::const_iterator end = idx_map.end();
if(idx_map.find(v) != end) is_v = true;
if(idx_map.find(w) != end) is_w = true;
set_match(false, is_v, is_w);
};
match_result(var_set_t const& idx_map, std::string const& u, index_type const& v, index_type const& w):
m_type(vaa),
m_match(0)
{
if(std::find(idx_map.begin(), idx_map.end(), u) != idx_map.end()) set_match(true, false, false);
};
match_result(var_set_t const& idx_map, std::string const& u, index_type const& v, std::string const& w):
m_type(vav),
m_match(0)
{
bool is_u=false, is_v=false, is_w=false;
var_set_t::const_iterator end = idx_map.end();
if(idx_map.find(u) != end) is_u = true;
if(idx_map.find(w) != end) is_w = true;
set_match(is_u, is_v, is_w);
};
match_result(var_set_t const& idx_map, std::string const& u, std::string const& v, index_type const& w):
m_type(vva),
m_match(0)
{
bool is_u=false, is_v=false, is_w=false;
var_set_t::const_iterator end = idx_map.end();
if(idx_map.find(u) != end) is_u = true;
if(idx_map.find(v) != end) is_v = true;
set_match(is_u, is_v, is_w);
};
match_result(var_set_t const& idx_map, std::string const& u, std::string const& v, std::string const& w):
m_type(vvv),
m_match(0)
{
bool is_u=false, is_v=false, is_w=false;
var_set_t::const_iterator end = idx_map.end();
if(idx_map.find(u) != end) is_u = true;
if(idx_map.find(v) != end) is_v = true;
if(idx_map.find(w) != end) is_w = true;
set_match(is_u, is_v, is_w);
};
int get_argument_type()const{return m_type;};
unsigned int get_match_count()const{return m_match;};
private:
void set_match(bool is_u, bool is_v, bool is_w)
{
if(is_u) ++m_match;
if(is_v) ++m_match;
if(is_w) ++m_match;
};
argument_type m_type;
unsigned int m_match;
};
/////////////////////////////////////////////////////////////////////////////////////////
// class expression_base
//
/////////////////////////////////////////////////////////////////////////////////////////
class expression_base;
typedef std::tr1::shared_ptr<expression_base> expression_term_ptr_type;
class expression_base
{
public:
expression_base()
{};
virtual ~expression_base(){};
virtual
expression_rule_term_ptr_type create_expression_term(rule_term_ptr_type const& left_term)=0;
virtual void
extract_vars(var_set_t & vars)const=0;
virtual bool
has_all_vars(rule_term_ptr_type const& left_term)const=0;
virtual void
rename_variables(var_map_t & map, int & ivar)=0;
virtual std::string
to_string()const=0;
protected:
inline void rename_var(expression_term_ptr_type & f, var_map_t & map, int & ivar){f->rename_variables(map, ivar);};
inline void rename_var(literal const& , var_map_t & map, int & ivar){};
inline void rename_var(index_type const& , var_map_t & map, int & ivar){};
inline void rename_var(std::string & v, var_map_t & map, int & ivar){v = get_new_name_for(v, map, ivar);};
inline void put_var(var_set_t & vars, expression_term_ptr_type const& f)const{f->extract_vars(vars);};
inline void put_var(var_set_t & vars, literal const&)const{};
inline void put_var(var_set_t & vars, index_type const&)const{};
inline void put_var(var_set_t & vars, std::string const& v)const{vars.insert(v);};
inline bool has_var(rule_term_ptr_type const& left_term, expression_term_ptr_type const& f)const{return f->has_all_vars(left_term);};
inline bool has_var(rule_term_ptr_type const& left_term, literal const&)const{return true;};
inline bool has_var(rule_term_ptr_type const& left_term, index_type const&)const{return true;};
inline bool has_var(rule_term_ptr_type const& left_term, std::string const& v)const{return left_term->has_index(v);};
friend std::ostream & operator<<(std::ostream &, expression_base const&);
};
inline std::ostream & operator<<(std::ostream & sout, expression_base const& x)
{
sout << x.to_string();
return sout;
};
// utility functions for printing out stuff (see operator<<)
inline std::string to_string(expression_term_ptr_type const& f){return f->to_string();};
// unary terms
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, index_type const& x);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, std::string const& x);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x);
// binary terms
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, index_type const& x, index_type const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, index_type const& x, std::string const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, index_type const& x, expression_term_ptr_type const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, std::string const& x, index_type const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, std::string const& x, std::string const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, std::string const& x, expression_term_ptr_type const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, index_type const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, std::string const& y);
template<class Oper>expression_rule_term_ptr_type create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, expression_term_ptr_type const& y);
/////////////////////////////////////////////////////////////////////////////////////////
// class binary_expression_term
//
/////////////////////////////////////////////////////////////////////////////////////////
template<class Oper, class X, class Y>
class binary_expression_term: public expression_base
{
public:
binary_expression_term(Oper const& oper, X const& x, Y const& y):
expression_base(),
m_oper(oper),
m_x(x),
m_y(y) {};
~binary_expression_term(){};
inline expression_rule_term_ptr_type create_expression_term(rule_term_ptr_type const& left_term)
{
return create_expr(left_term, m_oper, m_x, m_y);
};
inline void extract_vars(var_set_t & vars)const
{
put_var(vars, m_x);
put_var(vars, m_y);
};
inline bool has_all_vars(rule_term_ptr_type const& left_term)const
{
if(!has_var(left_term, m_x)) return false;
return has_var(left_term, m_y);
};
void rename_variables(var_map_t & map, int & ivar)
{
rename_var(m_x, map, ivar);
rename_var(m_y, map, ivar);
};
inline std::string to_string()const
{
std::ostringstream sout;
sout << "("
<< rule::internal::to_string(m_x) << " "
<< m_oper.name() << " "
<< rule::internal::to_string(m_y) << ")";
return sout.str();
};
private:
Oper m_oper;
X m_x;
Y m_y;
};
/////////////////////////////////////////////////////////////////////////////////////////
// class unary_expression_term
//
/////////////////////////////////////////////////////////////////////////////////////////
template<class Oper, class X>
class unary_expression_term: public expression_base
{
public:
inline unary_expression_term(Oper const& oper, X const& x):
expression_base(),
m_oper(oper),
m_x(x) {};
~unary_expression_term(){};
inline expression_rule_term_ptr_type create_expression_term(rule_term_ptr_type const& left_term)
{
return create_expr(left_term, m_oper, m_x);
};
inline void extract_vars(var_set_t & vars)const
{
put_var(vars, m_x);
};
inline bool has_all_vars(rule_term_ptr_type const& left_term)const
{
return has_var(left_term, m_x);
};
void rename_variables(var_map_t & map, int & ivar)
{
rename_var(m_x, map, ivar);
};
inline std::string to_string()const
{
std::ostringstream sout;
sout << "("
<< m_oper.name() << " "
<< rule::internal::to_string(m_x) << ")";
return sout.str();
};
private:
Oper m_oper;
X m_x;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// create_expr
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x)
{
if(!x->is_literal()) {
std::string msg("create_expr_operant_type[1]: Expecting argument of type literal, it looks like it's a resource not a literal");
std::cout << msg << x << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
fa_ptr_type fx_p(new fa(rdf::internal::to_literal(x)));
return expression_rule_term_ptr_type(new expression_unary_rule_term<Oper, fa_ptr_type>(fx_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x)
{
fa_ptr_type fx_p(new fa(x));
return expression_rule_term_ptr_type(new expression_unary_rule_term<Oper, fa_ptr_type>(fx_p));
};
// F_a
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, index_type const& x)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x)
{
fi_literal_ptr_type fx_p(new fi_literal(left_term->get_index(x).first));
return expression_rule_term_ptr_type(new expression_unary_rule_term<Oper, fi_literal_ptr_type>(fx_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x)
{
fi_index_type_ptr_type fx_p(new fi_index_type(left_term->get_index(x).first));
return expression_rule_term_ptr_type(new expression_unary_rule_term<Oper, fi_index_type_ptr_type>(fx_p));
};
// F_i
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, std::string const& x)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// F_x
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x)
{
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_unary_rule_term<Oper, expression_rule_term_ptr_type>(fx_p));
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, index_type const& y)
{
if(!x->is_literal() or !y->is_literal()) {
std::string msg("create_expr_operant_type[2]: Expecting arguments of type literal, it looks like at least one of them is a resource not a literal");
std::cout << msg << x << ", " << y << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
fa_ptr_type fx_p(new fa(rdf::internal::to_literal(x)));
fa_ptr_type fy_p(new fa(rdf::internal::to_literal(y)));
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, index_type const& y)
{
fa_ptr_type fx_p(new fa(x));
fa_ptr_type fy_p(new fa(y));
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// F_aa
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, index_type const& x, index_type const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, std::string const& y)
{
if(!x->is_literal()) {
std::string msg("create_expr_operant_type[3]: Expecting argument of type literal, it looks like it's a resource not a literal");
std::cout << msg << x << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
fa_ptr_type fx_p(new fa(rdf::internal::to_literal(x)));
fi_literal_ptr_type fy_p(new fi_literal(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, fi_literal_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, std::string const& y)
{
fa_ptr_type fx_p(new fa(x));
fi_index_type_ptr_type fy_p(new fi_index_type(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, fi_index_type_ptr_type>(fx_p, fy_p));
};
// F_ai
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, index_type const& x, std::string const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, expression_term_ptr_type const& y)
{
if(!x->is_literal()) {
std::string msg("create_expr_operant_type[4]: Expecting argument of type literal, it looks like it's a resource not a literal");
std::cout << msg << x << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
fa_ptr_type fx_p(new fa(rdf::internal::to_literal(x)));
expression_rule_term_ptr_type fy_p = y->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, expression_rule_term_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, index_type const& x, expression_term_ptr_type const& y)
{
fa_ptr_type fx_p(new fa(x));
expression_rule_term_ptr_type fy_p = y->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_rule_term<fa_ptr_type, Oper, expression_rule_term_ptr_type>(fx_p, fy_p));
};
// F_ax
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, index_type const& x, expression_term_ptr_type const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, index_type const& y)
{
if(!y->is_literal()) {
std::string msg("create_expr_operant_type[5]: Expecting argument of type literal, it looks like it's a resource not a literal");
std::cout << msg << y << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
fi_literal_ptr_type fx_p(new fi_literal(left_term->get_index(x).first));
fa_ptr_type fy_p(new fa(rdf::internal::to_literal(y)));
return expression_rule_term_ptr_type(new expression_rule_term<fi_literal_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, index_type const& y)
{
fi_index_type_ptr_type fx_p(new fi_index_type(left_term->get_index(x).first));
fa_ptr_type fy_p(new fa(y));
return expression_rule_term_ptr_type(new expression_rule_term<fi_index_type_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// F_ia
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, std::string const& x, index_type const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, std::string const& y)
{
fi_literal_ptr_type fx_p(new fi_literal(left_term->get_index(x).first));
fi_literal_ptr_type fy_p(new fi_literal(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<fi_literal_ptr_type, Oper, fi_literal_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, std::string const& y)
{
fi_index_type_ptr_type fx_p(new fi_index_type(left_term->get_index(x).first));
fi_index_type_ptr_type fy_p(new fi_index_type(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<fi_index_type_ptr_type, Oper, fi_index_type_ptr_type>(fx_p, fy_p));
};
// F_ii - the operator Oper need to indicate if the operants are literals or index_type (see create_expr_operant_type function)
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, std::string const& x, std::string const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, expression_term_ptr_type const& y)
{
fi_literal_ptr_type fx_p(new fi_literal(left_term->get_index(x).first));
expression_rule_term_ptr_type fy_p = y->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_rule_term<fi_literal_ptr_type, Oper, expression_rule_term_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, std::string const& x, expression_term_ptr_type const& y)
{
fi_index_type_ptr_type fx_p(new fi_index_type(left_term->get_index(x).first));
expression_rule_term_ptr_type fy_p = y->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_rule_term<fi_index_type_ptr_type, Oper, expression_rule_term_ptr_type>(fx_p, fy_p));
};
// F_ix
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, std::string const& x, expression_term_ptr_type const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, index_type const& y)
{
if(!y->is_literal()) {
std::string msg("create_expr_operant_type[6]: Expecting argument of type literal, it looks like it's a resource not a literal");
std::cout << msg << y << std::endl;
throw rdf::rdf_exception(rdf::invalid_index, msg);
}
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
fa_ptr_type fy_p(new fa(rdf::internal::to_literal(y)));
return expression_rule_term_ptr_type(new expression_rule_term<expression_rule_term_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, index_type const& y)
{
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
fa_ptr_type fy_p(new fa(y));
return expression_rule_term_ptr_type(new expression_rule_term<expression_rule_term_ptr_type, Oper, fa_ptr_type>(fx_p, fy_p));
};
// F_xa
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, expression_term_ptr_type const& x, index_type const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// helper function using literal as a flag in argument - case where the index is for a literal
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(literal_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, std::string const& y)
{
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
fi_literal_ptr_type fy_p(new fi_literal(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<expression_rule_term_ptr_type, Oper, fi_literal_ptr_type>(fx_p, fy_p));
};
// helper function using literal as a flag in argument - case where the index is for a index_type
template<class Oper>
expression_rule_term_ptr_type
create_expr_operant_type(resource_operator_tag const&, rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, std::string const& y)
{
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
fi_index_type_ptr_type fy_p(new fi_index_type(left_term->get_index(y).first));
return expression_rule_term_ptr_type(new expression_rule_term<expression_rule_term_ptr_type, Oper, fi_index_type_ptr_type>(fx_p, fy_p));
};
// F_xi
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const& o, expression_term_ptr_type const& x, std::string const& y)
{
return create_expr_operant_type(typename Oper::operant_type(), left_term, o, x, y);
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// F_xx
template<class Oper>
expression_rule_term_ptr_type
create_expr(rule_term_ptr_type const& left_term, Oper const&, expression_term_ptr_type const& x, expression_term_ptr_type const& y)
{
expression_rule_term_ptr_type fx_p = x->create_expression_term(left_term);
expression_rule_term_ptr_type fy_p = y->create_expression_term(left_term);
return expression_rule_term_ptr_type(new expression_rule_term<expression_rule_term_ptr_type, Oper, expression_rule_term_ptr_type>(fx_p, fy_p));
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}; /* internal namespace */
}; /* rule namespace */
#endif /*KNOWLEDGE_EXPRESSION_H_*/