ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

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

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

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

#!/usr/bin/env python

import roslib
import rospy
import json_prolog


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

for sol in
    print sol 


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
import rospy
import 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
    print sol 


The solution I got is {'A': ''}

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

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

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="".

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

prolog.query("owl_subclass_of(A, '')")

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

edit flag offensive delete link more


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 image Po-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, abbreviated as knowrob: Your pizza.owl probably uses a different namespace that needs to be used here.

moritz gravatar image moritz  ( 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 image Po-Jen Lai  ( 2012-11-01 20:36:11 -0500 )edit

Question Tools

1 follower


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

Seen: 729 times

Last updated: Nov 01 '12