本文整理汇总了C++中Answer::GetVariableMap方法的典型用法代码示例。如果您正苦于以下问题:C++ Answer::GetVariableMap方法的具体用法?C++ Answer::GetVariableMap怎么用?C++ Answer::GetVariableMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Answer
的用法示例。
在下文中一共展示了Answer::GetVariableMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAnswer
std::list<Argument*> KnowledgeBase::Ask(const Argument& arg,
bool checkForDoubles)
{
std::list<Argument*> out;
// get answer
Answer *ans = GetAnswer(arg, VariableMap(), std::set<size_t>());
// get all the valid substitution and add them to list
if(!checkForDoubles)
{
while(ans->next())
{
Argument* temp = Unify::GetSubstitutedArgument(&arg, ans->GetVariableMap());
out.push_back(temp);
}
}
else
{
std::set<std::string> str_ans;
while(ans->next())
{
Argument* temp = Unify::GetSubstitutedArgument(&arg, ans->GetVariableMap());
std::stringstream stream;
stream << *temp;
//SymbolDecodeStream sds(symbol_table);
//sds << *temp << endl;
if(str_ans.find(stream.str()) == str_ans.end())
{
out.push_back(temp);
str_ans.insert(stream.str());
}
else delete temp;
}
}
// delete answer
delete ans;
return out;
}
示例2: FlattenRelation
void KIFFlattener::FlattenRelation(const DGraphNode* n,
const KnowledgeBase& all_kb,
const std::set<size_t>& state_independent,
KnowledgeBase& m_kb,
std::list<Clause>& f_clauses,
std::list<Fact>& f_facts)
{
//compute signature of relation
const size_t& sig = n->id;
// get all the facts and clauses associated with this signature
const KnowledgeBase::FactList* facts = all_kb.GetFacts(sig);
const KnowledgeBase::ClauseList* p_clauses = all_kb.GetClauses(sig);
if(p_clauses == NULL)
{
if(facts != NULL)
for(KnowledgeBase::FactList::const_iterator it = facts->begin();
it != facts->end();it++)
{
f_facts.push_back(*it);
m_kb.Tell(*it);
}
return;
}
const KnowledgeBase::ClauseList& clauses = *p_clauses;
// to store the heads of the flattened clauses
// these will be added later to temporary knowledge base
list<Argument*> f_heads;
// start flattening clauses
for(list<Clause>::const_iterator it = clauses.begin();it != clauses.end();it++)
{
// if the clause is already ground add it directly
// add its head to heads list
if((*it).IsGround())
{
Clause* to_add = new Clause(*it);
f_clauses.push_back(*to_add);
f_heads.push_back(to_add->head);
to_add->head = NULL;
delete to_add;
continue;
}
// pre-process the clause
// adjust the extra variables which are present in body but not head
// adjust 'not' relation appropriately
Clause* p_clause = ProcessClause(*it, state_independent);
// add the processed clause temporarily to knowledge base
size_t c_index = m_kb.Tell(*p_clause);
VariableMap h_v_map;
Argument* question = SpecialArgCopy2(p_clause->head, h_v_map);
// after adding the head of the clause will be the question to ask
Answer* ans = m_kb.GetAnswer(*question, VariableMap(), set<size_t>());
while(ans->next())
{
VariableMap ans_v_map = ans->GetVariableMap();
for(auto va : h_v_map)
ans_v_map.insert(va);
// compute the answer with substitution
Clause* to_add = Unify::GetSubstitutedClause(&(*it), ans_v_map);
// remove all the occurrences of data relations
Clause* temp = RemoveDataFromClause(to_add, state_independent);
// check whether clause can be converted to fact after data relations removal
if(temp == NULL)
{
Argument* h = to_add->head;
to_add->head = NULL;
delete to_add;
f_facts.push_back(*h);
f_facts.back().loc = (*it).loc;
f_facts.back().isLocation = (*it).isLocation;
f_heads.push_back(h);
}
else
{
f_clauses.push_back(*temp);
f_clauses.back().loc = (*it).loc;
f_clauses.back().isLocation = (*it).isLocation;
f_heads.push_back(temp->head);
temp->head = NULL;
delete temp;
}
}
// delete answer
delete ans;
// erase the temporary knowledge from knowledge base
//.........这里部分代码省略.........