Manage multiple ontologies (cpp)

Sally & Anne test

Detect divergence of belief

We now consider that Sally is absent and Anne moves the ball from Container 1 to Container 2. Replace the previous code with this new one.

#include <iostream>
#include <string>

#include "ontologenius/OntologiesManipulator.h"

int main(int argc, char** argv)
{
ros::init(argc, argv, "multiple_ontologies");

onto::OntologiesManipulator onto;

onto.waitInit();

onto.add("sally");
onto.add("anne");

onto["sally"]->close();
onto["anne"]->close();

std::vector<std::string> result = onto["sally"]->individuals.getOn("ball_1", "isIn");
std::cout << "for sally, ball_1 is in:" << std::endl;
for(auto& in : result)
std::cout << "- " << in << std::endl;

result = onto["anne"]->individuals.getOn("ball_1", "isIn");
std::cout << "for anne, ball_1 is in:" << std::endl;
for(auto& in : result)
std::cout << "- " << in << std::endl;

onto["anne"]->feeder.waitConnected();

onto["anne"]->feeder.removeProperty("ball_1", "isIn", "container_1");
onto["anne"]->feeder.addProperty("ball_1", "isIn", "container_2");

onto["anne"]->feeder.waitUpdate(500);

std::vector<std::string> differences = onto.waitUpdate("sally", "anne", "ball_1");
std::cout << "The difference of belief regarding the ball_1 is:" << std::endl;
for(auto& diff : differences)
std::cout << "- " << diff << std::endl;

onto.del("sally");
onto.del("anne");

return 0;
}

First of all a small trick.

onto["anne"]->feeder.waitConnected();

If you know ROS, you should know that subscribers may take a few moments to connect to listeners. Because, again, our program is a bit too fast, this connection may not be effective immediately. To avoid this problem, you can use the previous line to make sure that our feeder is connected to at least one listener.

onto["anne"]->feeder.removeProperty("ball_1", "isIn", "container_1");
onto["anne"]->feeder.addProperty("ball_1", "isIn", "container_2");

Here are really the two lines that represent the fact that Anne removes the ball from the first container and puts it in the second container. You see here that these changes are applied only to Anne.

onto["anne"]->feeder.waitUpdate(500);

With the waitUpdate function, we will wait until the previous changes are applied. For security reasons, we set a timeout of 500 ms.

std::vector<std::string> differences = onto.waitUpdate("sally", "anne", "ball_1");
std::cout << "The difference of belief regarding the ball_1 is:" << std::endl;
for(auto& diff : differences)
std::cout << "- " << diff << std::endl;

The OntologiesManipulator object directly provides functionality to get all the belief divergence between two ontologies about a specific concept.

Compile this code and run it with the launcher created previously. You should have this result at the end:

for sally, ball_1 is in:
- container_1
for anne, ball_1 is in:
- container_1
The difference of belief regarding the ball_1 is:
- [-]ball_1|isIn|container_2
- [+]ball_1|isIn|container_1

You can see from this display that the result of the getDifference function is really a difference, as in the mathematical sense. This can be read as the fact that "ball_1 isIn container_1" is present in Sally's base and not in Anne's and that the fact that "ball_1 isIn container_2" is not present in Sally's base then that it is in Anne's.

Now kill the previous process and restart it. This time, you should have this:

for sally, ball_1 is in:
- container_1
for anne, ball_1 is in:
- container_2
The difference of belief regarding the ball_1 is:
- [-]ball_1|isIn|container_2
- [+]ball_1|isIn|container_1

You can see two things here. First, the ball was already in the second container for Anne at first. Secondly, even though we added the fact that the ball_1 is in the second container when it was already the case, the fact only appears once.

If you open the ontologenius_tutorial folder, you should have two new files, multi_anne.owl and multi_sally.owl. These two files are Ontologenius internal files. Remember that the intern_file argument has been set to multi.owl. In fact, multi can simply be considered a namespace that will be used to create the names of internal files.