ontodev / robot

ROBOT is an OBO Tool
http://robot.obolibrary.org
BSD 3-Clause "New" or "Revised" License
261 stars 74 forks source link

Some strange SPARQL behaviour: missing object properties #509

Closed matentzn closed 5 years ago

matentzn commented 5 years ago

Its probably not a ROBOT issues, but important enough for someone to investigate.

Goal: Get all object properties in signature. Symptom: SPARQL queries using ?x a owl:ObjectProperty fail for an unknown reason to retrieve all existing object properties.

I have developed a unit test here:

git clone https://github.com/monarch-ebi-dev/robot_test.git
cd robot_test
make cl_seed_test

This will execute two sparql queries. works_seed_by_entity_type_cl.txt is the result of an alternative SPARQL query exploiting the presence of existential restrictions for retrieving object properties (successfully). fail_seed_by_entity_type_cl.txt contains the seed using the ?x a owl:ObjectProperty. As you can see, most importantly, BFO:0000050 is missing from that seed!

As we rely on this a lot in the ODK (many SPARQL queries with this kind of selector), it would be good to figure out what is going wrong. The only thing I noticed is this: If I drop the imports, it appears to work again (deleting the import statements I mean).

balhoff commented 5 years ago

I see you use --use-graphs false. Are these declarations in an import? In that case you need --use-graphs true, and then have your SPARQL query run over the default graph (no FROM statement).

matentzn commented 5 years ago

The use case is: give me all the object properties used in the edit file.. What do you mean by:

then have your SPARQL query run over the default graph (no FROM statement)

balhoff commented 5 years ago

The only thing I noticed is this: If I drop the imports, it appears to work again (deleting the import statements I mean).

When you delete imports, property declarations will be inserted into the main ontology by OWL API as needed.

matentzn commented 5 years ago

There must be a robust way to get all object properties used in the signature with --use-graphs false, no?

balhoff commented 5 years ago
  1. Query all declared object properties: use --use-graphs true and query for ?x a owl:ObjectProperty
  2. Query for object properties that just happen to be declared within the main ontology (probably not useful for this): use --use-graphs false and query for ?x a owl:ObjectProperty
  3. Query for object properties used in axioms in the main ontology: use --use-graphs false and create SPARQL query for specific syntactic situations, like owl:onProperty.
  4. Query for object properties used in axioms in the main ontology: remove imports first and then chain with (2).

I think that covers it? If I understand it correctly I don't think there is a bug here.

matentzn commented 5 years ago
  1. returns all object properties, which is not what I want.
  2. misses properties that are used and are not declared
  3. Requires a massive sparql query with a dozen variations (used in existential restriction, used in role chain, used in role hierarchy, used in annotation assertion, etc etc, so unless we write a massive query, it will be likely incomplete!)
  4. Is probably the only way. I will close this now; But I think the SPARQL engine should be a bit smarter with regards to OWL types at least.. It cant be IMHO that if you have an ontology:
imports: o.owl
A sub B

and both A and B are declared in o.owl, that the sparql query ?a a owl:Class returns A and B when the import statement is there and nothing when it is not. You dont think this is counter intuitive? Our users dont really care whether something is declared. They just want a nice overview of all the used classes, and they want to use robots query function to do so...