Feed and generalize (cpp)

Do the birds fly ?

Make our agent proactive

In the previous part, our program has realized its generalizations without telling us, and the only way for us to realize this was to ask the right questions at the right time.

So we will use the topic 'ontologenius/reasoner_notifications' which is a topic Ontologenius publishes when it realizes some reasoning including the generalization.

The messages published on this topic are always in the form: "[NEW]concept>property:type#value ". So we will use a regex to extract the information easily as below:

std::regex proactive("\\[NEW\\](\\w+)>can_(\\w+):bool#(\\w+)");

Here is the callback function:

void proactiveCallback(const std_msgs::String::ConstPtr& msg)
{
std::smatch match;
if(std::regex_match(msg->data, match, proactive))
{
if(match[3].str() == "true")
std::cout << "I think that a " << match[1].str() << " can " << match[2].str() << std::endl;
else
std::cout << "I think that a " << match[1].str() << " can not " << match[2].str() << std::endl;
}
}

And finally, the new ros subscriber:

ros::Subscriber proactive_sub = n.subscribe("ontologenius/reasoner_notifications", 1000 , proactiveCallback);

You can now delete the internal file and learn again to your program that birds can fly (or something else).

This tutorial is already finished. I let you imagine everything you could do with it. Do not hesitate to look at all the classes made available by the API to discover all the features offered by Ontologenius.