#ifndef PSEARCHINFER_H_
#define PSEARCHINFER_H_
#include "psearch_db.h"
#include "psearch_query.h"
namespace psearch {
struct less_psc
{
inline bool operator()(psc_ptr_type const& lhs, psc_ptr_type const& rhs)const
{
return lhs->get_pattern_index()->get_weight() < rhs->get_pattern_index()->get_weight();
};
};
typedef std::priority_queue<psc_ptr_type, std::vector<psc_ptr_type>, less_psc> psc_queue_type;
typedef std::tr1::unordered_multimap<node_index_type, psc_ptr_type> negate_pattern_map_type;
/////////////////////////////////////////////////////////////////////////////////////////
// class infer_execution_state
//
/////////////////////////////////////////////////////////////////////////////////////////
struct infer_execution_state
{
node_set_type inferred_node_set;
pattern_set_type visited_pattern_set;
psc_queue_type psc_queue;
psc_list_type negated_psc_list;
negate_pattern_map_type negate_pattern_map;
// patterns that would otherwise be inferred but were filtered out by their negated nodes
// and may be reconsidered if the node that negate them is retracted
negate_pattern_map_type filtered_pattern_map;
};
/////////////////////////////////////////////////////////////////////////////////////////
// class PSearchInfer
//
/////////////////////////////////////////////////////////////////////////////////////////
class PSearchInfer
{
protected:
void
initialize_query_state(infer_execution_state & query_state);
bool
is_c1_match(pattern_index_type patern_index);
void
select_relevant_patterns(infer_execution_state & query_state);
bool
is_negated_by_has_not_nodes(pattern_index_type pattern_index);
bool
is_negated_by_has_nodes(infer_execution_state & query_state, psc_ptr_type psc_p);
void
infer_pattern(infer_execution_state & query_state, psc_ptr_type psc_p);
void
retract_pattern(infer_execution_state & query_state, psc_ptr_type psc_p);
public:
PSearchInfer(PSearchDB const* db_p, PSearchSession * psession_p, unsigned int max_loop=1000):
m_db_p(db_p),
m_psession_p(psession_p),
m_result_p(),
m_max_loop(max_loop)
{
m_result_p = psresult_ptr_type(new PSResult(db_p, psession_p));
};
~PSearchInfer(){};
void printQuery();
psresult_ptr_type
infer(bool verbose);
inline psresult_ptr_type
get_result()
{
return m_result_p;
};
private:
PSearchDB const* m_db_p;
PSearchSession * m_psession_p;
psresult_ptr_type m_result_p;
unsigned int m_max_loop;
};
}; /* psearch namespace */
#endif /*PSEARCHINFER_H_*/