Use inheritance for my first program (python)

Who is the intruder ?

Find the most relevant intruder

Our program works pretty well but let's question it with the words: pr2, kevin, and bob

You should have this:

[SAY]on pr2 kevin bob
[SAY]the intruder is pr2 because it is the only one that is not: human
[SAY]the intruder is pr2 because it is the only one that is not: man
[SAY]Let's play!

We can represent this part of the ontology as follow:

tutorial 2 map of the city

The result is not false but only one of these two answers would be enough given that one induces the other. We will use Ontologenius to try to give only the most relevant answer in such cases.

To do this we will use a new function: getDown

As you can imagine, the getDown function is the exact opposite of the getUp function, that is to say, that it returns the concepts inheriting from the one passed in the parameters of the function.

We will use this function on classes because no concept can inherit an individual but especially because our goal is to find the reasons (which are classes) that overlap.

def refine(intruders):
refine_intruders = []
for i in range(len(intruders)):
down = _onto.classes.getDown(intruders[i][1])

is_most_relevant = True
for j in range(len(intruders)):
if i != j and intruders[i][0] == intruders[j][0]:
if intruders[j][1] in down:
is_most_relevant = False

if is_most_relevant:
refine_intruders.insert(1, intruders[i])

return refine_intruders

So we notice that we are going to look for the object classes of the ontology manipulator instead of the object individuals.

down = _onto.classes.getDown(intruders[i][1])

The getUp function is available for individuals, classes, and properties while the getDown function is only available for classes and properties.

We can call our refining function in our main function just after the function to find intruders

intruders = find_intruder(_names, inheritances)
intruders = refine(intruders)

Re-interrogating our program with the words pr2, kevin, and bob, we now have the following result:

[SAY]on pr2 kevin bob
[SAY]the intruder is pr2 because it is the only one that is not: man
[SAY]Let's play!

If you want this to be the concept "human" that explains the intruder, you just have to modify the algorithm above using the getUp function rather than the getDown function. It is your turn!