Manage multiple ontologies (python)

Sally & Anne test

Create multiple ontologies

We will first write a program that will create an ontology for Anne and an ontology for Sally.

Create a main file and paste the following inside it:

#!/usr/bin/env python

import rospy

from ontologenius import OntologiesManipulator

def main():
rospy.init_node('multiple_ontologies')

onto = OntologiesManipulator()
onto.waitInit()

onto.add('sally')
onto.add('anne')

onto.get('sally').close()
onto.get('anne').close()

result = onto.get('sally').individuals.getOn('ball_1', 'isIn')
print('for sally, ball_1 is in : ' + str(result))

result = onto.get('anne').individuals.getOn('ball_1', 'isIn')
print('for anne, ball_1 is in : ' + str(result))

if __name__ == '__main__':
main()

Now, let's break the code down.

from ontologenius import OntologiesManipulator

In previous tutorials, we imported the OntologyManipulator object. This time, we need to handle several ontologies and that's why we import the OntologiesManipulator object this time. This object allows us to dynamically create an OntologyManipulator per agent.

onto = OntologiesManipulator()
onto.waitInit()

We start by creating an OntologiesManipulator in the same way that we previously created an OntologyManipulator. This time, we simply call waitInit to make sure that all ROS services have been created before starting.

onto.add('sally')
onto.add('anne')

We create here two ontologies, one for Sally and one for Anne. For the rest of the program, we will use these identifiers to get the specific ontology we want to work on.

onto.get('sally').close()
onto.get('anne').close()

As usual, we must close the ontology before exploring it. Here we use the get function that returns an OntologyManipulator object for a specific instance.

result = onto.get('sally').individuals.getOn('ball_1', 'isIn')

From there, you can use Ontologenius as usual.

Launch the program. You should have the result that the ball is in the first container for Sally and Anne.