biolink / ontobio

python library for working with ontologies and ontology associations
https://ontobio.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
119 stars 30 forks source link

question about owl:DatatypeProperty #507

Open saramsey opened 3 years ago

saramsey commented 3 years ago

Hello Ontobio team,

I have a simple RDF Turtle file test.ttl that I want to load using Ontobio:

@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://foo.com/bar> a owl:Class ;
        skos:prefLabel """some node"""@en ;
        <http://foo.com/baz> """test property"""^^xsd:string ;
.

<http://foo.com/baz> a owl:DatatypeProperty ;
    rdfs:label """test label""";
    rdfs:comment """test comment""" .

When I convert it to OWL using robot,

./robot convert --input test.ttl --output test.owl

I get something reasonable, including my "test property" as shown here:

    <NamedIndividual rdf:about="http://foo.com/bar">
        <foo:baz rdf:datatype="http://www.w3.org/2001/XMLSchema#string">test property</foo:baz>
    </NamedIndividual>

But when I load that test.owl file into ontobio 2.1.2,

rm  -r -f ~/.cachier
python3
import ontobio
ont = ontobio.ontol_factory.OntologyFactory().create("test.owl", ignore_cache=True)

I don't see the property in the node:

>>> ont = ontobio.ontol_factory.OntologyFactory().create("test.owl", ignore_cache=True)
>>> ont
test.owl handle: test.owl meta: {'subsets': [], 'xrefs': [], 'basicPropertyValues': []}
>>> ont.nodes()
NodeView(('http://foo.com/baz', 'http://foo.com/bar'))
>>> import pprint
>>> pprint.pprint(ont.node("http://foo.com/bar"))
{'id': 'http://foo.com/bar',
 'meta': {'basicPropertyValues': [{'pred': 'http://www.w3.org/2004/02/skos/core#prefLabel',
                                   'val': 'some node'}]},
 'type': 'INDIVIDUAL'}

Is there a way to load an OWL file into Ontobio and to programmatically access a owl:DatatypeProperty field of a class?

saramsey commented 3 years ago

My setup:

saramsey commented 3 years ago

tagging @cmungall and @deepakunni3

deepakunni3 commented 3 years ago

@saramsey This is an interesting observation.

One thing to note here is that Ontobio uses owltools to parse OWL to create a JSON representation.

While technically owltools and robot should be the same, but there is something else at play here.

Using Robot, if I were to convert the test.ttl to test.json (a form Ontobio recognizes), I get an error.

robot convert -vvv --input test.ttl --output test.json -f json

2021-01-11 13:30:10,064 DEBUG org.obolibrary.robot.IOHelper - Saving ontology Ontology(OntologyID(Anonymous-2)) [Axioms: 6 Logical Axioms: 1] First 20 axioms: {AnnotationAssertion(rdfs:label <http://foo.com/baz> "test label") AnnotationAssertion(rdfs:comment <http://foo.com/baz> "test comment") AnnotationAssertion(<http://www.w3.org/2004/02/skos/core#prefLabel> <http://foo.com/bar> "some node"@en) DataPropertyAssertion(<http://foo.com/baz> <http://foo.com/bar> "test property"^^xsd:string) Declaration(Class(<http://foo.com/bar>)) Declaration(DataProperty(<http://foo.com/baz>)) } as OboGraphs JSON Syntax with to IRI file:/Users/deepak.unni3/GIT/ontobio-master/test.json
2021-01-11 13:30:10,070 DEBUG org.obolibrary.robot.ExceptionHelper - {} missing exception message.
java.lang.NullPointerException
    at org.geneontology.obographs.owlapi.FromOwl.getNodeId(FromOwl.java:717)
    at org.geneontology.obographs.owlapi.FromOwl.generateGraph(FromOwl.java:515)
    at org.geneontology.obographs.owlapi.FromOwl.generateGraphDocument(FromOwl.java:110)
    at org.obolibrary.robot.IOHelper.saveOntologyFile(IOHelper.java:1121)
    at org.obolibrary.robot.IOHelper.saveOntology(IOHelper.java:583)
    at org.obolibrary.robot.IOHelper.saveOntology(IOHelper.java:524)
    at org.obolibrary.robot.ConvertCommand.execute(ConvertCommand.java:167)
    at org.obolibrary.robot.CommandManager.executeCommand(CommandManager.java:248)
    at org.obolibrary.robot.CommandManager.execute(CommandManager.java:192)
    at org.obolibrary.robot.CommandManager.main(CommandManager.java:139)
    at org.obolibrary.robot.CommandLineInterface.main(CommandLineInterface.java:55)
null
java.lang.NullPointerException
    at org.geneontology.obographs.owlapi.FromOwl.getNodeId(FromOwl.java:717)
    at org.geneontology.obographs.owlapi.FromOwl.generateGraph(FromOwl.java:515)
    at org.geneontology.obographs.owlapi.FromOwl.generateGraphDocument(FromOwl.java:110)
    at org.obolibrary.robot.IOHelper.saveOntologyFile(IOHelper.java:1121)
    at org.obolibrary.robot.IOHelper.saveOntology(IOHelper.java:583)
    at org.obolibrary.robot.IOHelper.saveOntology(IOHelper.java:524)
    at org.obolibrary.robot.ConvertCommand.execute(ConvertCommand.java:167)
    at org.obolibrary.robot.CommandManager.executeCommand(CommandManager.java:248)
    at org.obolibrary.robot.CommandManager.execute(CommandManager.java:192)
    at org.obolibrary.robot.CommandManager.main(CommandManager.java:139)
    at org.obolibrary.robot.CommandLineInterface.main(CommandLineInterface.java:55)

Now if I were to convert test.ttl to test.owl then it works as demonstrated above by @saramsey

And when I convert this derived test.owl to test.json,

robot convert --input test.owl --output test.json -f json

I get the following:

{
  "graphs" : [ {
    "nodes" : [ {
      "id" : "http://foo.com/baz",
      "meta" : {
        "comments" : [ "test comment" ]
      },
      "type" : "PROPERTY",
      "lbl" : "test label"
    }, {
      "id" : "http://foo.com/bar",
      "meta" : {
        "basicPropertyValues" : [ {
          "pred" : "http://www.w3.org/2004/02/skos/core#prefLabel",
          "val" : "some node"
        } ]
      },
      "type" : "INDIVIDUAL"
    } ],
    "edges" : [ ],
    "meta" : {
      "subsets" : [ ],
      "xrefs" : [ ],
      "basicPropertyValues" : [ ]
    },
    "equivalentNodesSets" : [ ],
    "logicalDefinitionAxioms" : [ ],
    "domainRangeAxioms" : [ ],
    "propertyChainAxioms" : [ ]
  } ]
}

While I see the owl:DatatypeProperty, it ends up as a node in the graph instead of a property on the node with IRI http://foo.com/bar.

@cmungall Thoughts?

dougli1sqrd commented 3 years ago

It's correct for http://foo.com/baz to show up as a "node", since in this graph view, all entities are nodes, even properties. But I'm not sure how the triple should show up. Normally if you're linking objects, like with subClassOf, you would see an entry in the edges list: {'a', 'subClassOf, 'b'}` or similar, for example. It may be different because this is a datatype property.

saramsey commented 3 years ago

Thanks, @dougli1sqrd and @deepakunni3. Is the current behavior of ontobio on this example input (i.e., not showing any edge in the resulting ontobio object, corresponding to the datatype property) expected?

deepakunni3 commented 3 years ago

@dougli1sqrd Agreed. We expect to see the dataTypeProperty as a node.

@saramsey No, the behavior is definitely not expected.

What we should be seeing is a proper edge that links http://foo.com/bar to test_property where the predicate is http://foo.com/baz. But "test property" is a string, having a direct edge doesn't make sense. So this should be a node property on node http://foo.com/bar.

dougli1sqrd commented 3 years ago

Yeah should this be in one of the meta fields?

saramsey commented 3 years ago

Thanks for your replies, @deepakunni3 and @dougli1sqrd!

Great, a node property (in the ontobio object model) would be ideal for us. Any sense of how light or heavy a lift it will be, to make this change to owltools/ontobio?

saramsey commented 3 years ago

Hi ontobio team, just checking back on this-- do you think this is a feasible fix? Would the fix be in owltools or in ontobio?

deepakunni3 commented 3 years ago

@cmungall Any recommendations on this?

Are only a selected set of properties end up in meta field of a node in OBOGraphs?

kvarforl commented 3 years ago

Hi @deepakunni3 @cmungall, do you have any updates on the status / feasibility of this fix? a few more issues that stem from this have cropped up on our end, so I thought I'd check back in :)

cmungall commented 3 years ago

a few things going on here. Looks like something unrelated to ontobio for ttl->rdfxml conversion? both owltools and robot are wrappers to the owlapi, but they may use different versions? if there is a bug it should be reported on the appropriate tracker.

but I think the question here is about the obograph spec. yes, this should be clarified, and yes we should make DPs nodes as we do for OPs. Can you add to obographs?

saramsey commented 3 years ago

a few things going on here. Looks like something unrelated to ontobio for ttl->rdfxml conversion? both owltools and robot are wrappers to the owlapi, but they may use different versions? if there is a bug it should be reported on the appropriate tracker.

but I think the question here is about the obograph spec. yes, this should be clarified, and yes we should make DPs nodes as we do for OPs. Can you add to obographs?

Thank you @cmungall ! For DPs, can there also be a triple (or alternately, a property on the DP node) that indicates the "parent" node for which it is a owlDatatypeProperty ?

cmungall commented 3 years ago

yes, it should have these edges

On Wed, Mar 10, 2021 at 12:16 PM Stephen A. Ramsey @.***> wrote:

a few things going on here. Looks like something unrelated to ontobio for ttl->rdfxml conversion? both owltools and robot are wrappers to the owlapi, but they may use different versions? if there is a bug it should be reported on the appropriate tracker.

but I think the question here is about the obograph spec. yes, this should be clarified, and yes we should make DPs nodes as we do for OPs. Can you add to obographs?

Thank you @cmungall https://github.com/cmungall ! For DPs, can there also be a triple (or alternately, a property on the DP node) that indicates the "parent" node that it is associated with?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/biolink/ontobio/issues/507#issuecomment-796027525, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMMONVSDDGITF74R2NZGTTC7AR5ANCNFSM4VZ7BICA .