ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
0

How to add statements through json_prolog?

asked 2012-11-01 20:15:22 -0500

I ran tutorial.launch in knowrob_tutorial to start services that accept knowrob queries

<launch>
    <node name="json_prolog" pkg="rosprolog" type="run_with_prolog_env"
    args="ias_semantic_map $(find json_prolog)/bin/json_prolog knowrob_tutorial" />
</launch>

And now I can query knowrob from my program like this:

#!/usr/bin/env python

import roslib
roslib.load_manifest('json_prolog')
import rospy
import json_prolog

rospy.init_node('query_json_prolog')

prolog = json_prolog.Prolog()
query = prolog.query("owl_has(knowrob:'Drawer1',P,O)")

for sol in query.solutions():
    print sol 

query.finish()
rospy.spin()

However, I want to make use of the power of knowrob, that is, I want to add statements to knowrob knowledge base and make use of the reasoning mechanisms in knowrob. But I found there's only query I can use in json_prolog client libraries.

If I want to use pizza.owl I generated somewhere:

#!/usr/bin/env python

import roslib
roslib.load_manifest('json_prolog')
import rospy
import json_prolog

rospy.init_node('test_json_prolog')
prolog = json_prolog.Prolog()

query = prolog.query("owl_parser:owl_parse('/rosfuerte/home/project/test/owl/pizza.owl', false, false, true)")
query2 = prolog.query("owl_subclass_of(A, knowrob:'PizzaTopping')")

for sol in query2.solutions():
    print sol 

query.finish()

The solution I got is {'A': 'http://ias.cs.tum.edu/kb/knowrob.owl#PizzaTopping'}

But I want to get

{'A': 'xxx#PizzaTopping'}
{'A': 'xxx#CheeseTopping'}
{'A': 'xxx#MeatTopping'}
{'A': 'xxx#SeafoodTopping'}
{'A': 'xxx#VegetableTopping'}

since the subclasses are defined in pizza.owl image description

How can I achieve that?

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-11-01 20:20:43 -0500

moritz gravatar image

updated 2012-11-01 20:45:57 -0500

Are you sure that PizzaTopping is in the KnowRob namespace?

You query for knowrob:'PizzaTopping', but probably want to ask for http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#PizzaTopping.

Edit: In your query, you need to set the correct IRI of the OWL class you are asking for. You find the base IRI of your ontology in the head of your OWL file in the line that looks like xmlns="http://ias.cs.tum.edu/kb/knowrob.owl#".

Assuming you used the standard pizza.owl, you therefore need to query for:

prolog.query("owl_subclass_of(A, 'http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#PizzaTopping')")

If you would like to abbreviate the long IRIs, you can define a namespace, e.g. in one of your init.pl using the rdf_db:rdf_register_ns directive. Have a look at the init.pl in ias_knowledge_base for an example.

edit flag offensive delete link more

Comments

The pizza.owl is generated by Protege by myself, in this situation how can I add this owl file to knowrob knowledge base?

Po-Jen Lai gravatar imagePo-Jen Lai ( 2012-11-01 20:22:43 -0500 )edit

If you ask for OWL information, you need to specify the correct IRI, i.e. the same that is used in your OWL file. The KnowRob core concepts have the base IRI http://ias.cs.tum.edu/kb/knowrob.owl#, abbreviated as knowrob: Your pizza.owl probably uses a different namespace that needs to be used here.

moritz gravatar imagemoritz ( 2012-11-01 20:28:40 -0500 )edit

Yeah I think the problem is on prolog.query("owl_subclass_of(A, knowrob:'PizzaTopping')"), I should change knowrob to another namespace. But since I don't know what should I use to replace knowrob, is there any functions I can check namespaces? Or is there default namespace for the parsed pizza.owl?

Po-Jen Lai gravatar imagePo-Jen Lai ( 2012-11-01 20:36:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-11-01 20:15:22 -0500

Seen: 575 times

Last updated: Nov 01 '12