本文整理汇总了C++中Agent::addBelief方法的典型用法代码示例。如果您正苦于以下问题:C++ Agent::addBelief方法的具体用法?C++ Agent::addBelief怎么用?C++ Agent::addBelief使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent
的用法示例。
在下文中一共展示了Agent::addBelief方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleSpeech
bool AdaptiveLayer::handleSpeech()
{
bool gotSignal = false;
Bottle* speechCmd = iCub->getSpeechClient()->STT(false);
if (speechCmd)
{
if (speechCmd->size() != 2)
{
std::cout << "in adaptativeLayer::handleSpeech | error: bottle received size !=2" << std::endl;
return false;
}
gotSignal = true;
std::cout << speechCmd->toString() << std::endl;
std::cout << speechCmd->toString() << std::endl;
cout<<"Raw sentence: |"<<speechCmd->get(0).toString()<<"|"<<endl;
//cout<<"Semantic:"<<speechCmd->get(1).toString();
Bottle* semanticBottle = speechCmd->get(1).asList();
string sentenceType = semanticBottle->get(0).asString();
if (sentenceType == "SUBNODE")
{
Bottle keyBot;
keyBot.addString(semanticBottle->get(1).asList()->check("keyword",Value("none")).asString());
pSpeechRecognizerKeywordOut.write(keyBot);
return true;
}
if (sentenceType == "miscSentences")
{
string rawSentence = speechCmd->get(0).toString();
cout<<"Catched a misc sentence : "<<semanticBottle->toString().c_str()<<endl;
return true;
}
//We trigger a scenario from speech
if (sentenceType == "GAME")
{
Bottle keyBot;
string gameName = semanticBottle->get(1).asList()->find("gameName").asString();
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//Create a relation for information exchange
Bottle bRelation;
Relation relationForm = this->getRelationFromSemantic(*semanticBottle->get(1).asList());
cout<< "Sentence type : "<<sentenceType<<endl;
cout<< "Relation form : "<<relationForm.toString()<<endl;
string answerFromRobot = "";
if (sentenceType == "IMPERATIVE")
{
//Execute the action
}
else if (sentenceType == "AFFIRMATIVE")
{
if (!iCub->opc->containsRelation(relationForm))
{
iCub->opc->addRelation(relationForm);
answerFromRobot = "Ok, I will know that " + relationForm.toString();
}
else
{
answerFromRobot = "I already knew that.";
}
//Update the other model to reflect his knowledge
Agent* partner = dynamic_cast<Agent*>(iCub->opc->getEntity("partner"));
partner->addBelief(relationForm);
iCub->opc->commit(partner);
}
else //interrogative
{
if (sentenceType == "INTERROGATIVE_WHO")
relationForm.m_subject = "?";
if (sentenceType == "INTERROGATIVE_WHAT")
relationForm.m_object = "?";
if (sentenceType == "INTERROGATIVE_WHEN")
relationForm.m_complement_time = "?";
if (sentenceType == "INTERROGATIVE_WHERE")
relationForm.m_complement_place = "?";
if (sentenceType == "INTERROGATIVE_HOW")
relationForm.m_complement_manner = "?";
Relation relationReturn(relationForm);
//Retrieve from OPC
string matchingSubject;
string matchingObject;
string matchingVerb;
string matchingPlace;
string matchingTime;
string matchingManner;
relationForm.subject() != "?" && relationForm.subject() != "none" ? matchingSubject = relationForm.subject() : matchingSubject = "any";
relationForm.verb() != "?" && relationForm.verb() != "none" ? matchingVerb = relationForm.verb() : matchingVerb = "any";
relationForm.object() != "?" && relationForm.object() != "none" ? matchingObject = relationForm.object() : matchingObject = "any";
relationForm.complement_place() != "?" && relationForm.complement_place() != "none" ? matchingPlace = relationForm.complement_place() : matchingPlace = "any" ;
relationForm.complement_time() != "?" && relationForm.complement_time() != "none" ? matchingTime = relationForm.complement_time() : matchingTime = "any" ;
//.........这里部分代码省略.........
示例2: updateBelief
//.........这里部分代码省略.........
else
mentalOPC->addRelation(*it_E, is, present, time_relation);
listRelations.push_back(Relation(*it_E, is, present));
}
// get the Agents present
vector<Relation> vRelToAdd,
vRelToRemove;
list<Entity*> PresentAgents;
if (bReal)
PresentAgents = (realOPC->Entities(conditionAgent));
else
PresentAgents = (mentalOPC->Entities(conditionAgent));
for (list<Entity*>::iterator it_E = PresentAgents.begin(); it_E != PresentAgents.end(); it_E++)
{
Agent* TempAgent = dynamic_cast<Agent*>(*it_E);
list<Relation> AgentBeliefs = TempAgent->beliefs();
vRelToAdd.clear();
vRelToRemove.clear();
bool bRelPresent = false;
// Searching the relations to Remove
// for each previous beliefs of an agent
for (list<Relation>::iterator it_RAg = AgentBeliefs.begin(); it_RAg != AgentBeliefs.end(); it_RAg++)
{
// search is the relation is present in the world
bRelPresent = false;
//for each relation in the world
for (list<Relation>::iterator it_RWorl = listRelations.begin(); it_RWorl != listRelations.end(); it_RWorl++)
{
if (!bRelPresent)
{
// is the new relation is already known
if (it_RAg->toString() == it_RWorl->toString())
{
bRelPresent = true;
}
}
}
// if the previous relation is no more present
if (!bRelPresent)
vRelToRemove.push_back(*it_RAg);
}
// Searching the relations to Add
//for each relation in the world
for (list<Relation>::iterator it_RWorl = listRelations.begin(); it_RWorl != listRelations.end(); it_RWorl++)
{
bRelPresent = false;
// for each previous beliefs of an agent
for (list<Relation>::iterator it_RAg = AgentBeliefs.begin(); it_RAg != AgentBeliefs.end(); it_RAg++)
{
// search is the relation has to be added
if (!bRelPresent)
{
// is the new relation is already known
if (it_RAg->toString() == it_RWorl->toString())
bRelPresent = true;
}
}
// if the previous relation is no more present
if (!bRelPresent)
vRelToAdd.push_back(*it_RWorl);
}
// Removing the old relations :
for (vector<Relation>::iterator it_R = vRelToRemove.begin(); it_R != vRelToRemove.end(); it_R++)
{
TempAgent->removeBelief(*it_R);
}
// Adding the new relations :
for (vector<Relation>::iterator it_R = vRelToAdd.begin(); it_R != vRelToAdd.end(); it_R++)
{
TempAgent->addBelief(*it_R);
}
if (bReal)
realOPC->commit(*it_E);
else
mentalOPC->commit(*it_E);
}
if (bReal)
realOPC->commit();
else
mentalOPC->commit();
cout << "done" << endl << endl;
return bOutput;
}