Feed and generalize (python)

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 in our case in the form: "[NEW]concept>property:type#value ". So we will use again a regex to extract the information easily.

Here is the callback function:

def proactiveCallback(msg):
match = re.search(r"^\[NEW\](\w+)>can_(\w+):bool#(\w+)$", msg)
if match != None:
if match.group(3) == 'True':
say('I think that a ' + match.group(1) + ' can ' + match.group(2))
else:
say('I think that a ' + match.group(1) + ' can not ' + match.group(2))

And finally, in the main function, we subscribe to the notification topic using the OntologyManipulator:

_onto.feeder.registerNotificationCallback(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.