ontodev / robot

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

BUG: robot template with class expressions duplicates classes as datatypes #1203

Open daniwelter opened 3 weeks ago

daniwelter commented 3 weeks ago

From the ROBOT Slack channel:

I'm having a weird issue with robot template since the last release. It's probably user error but since I upgraded to v1.9.6, any classes used in class expressions become duplicated as datatypes. This is an extract from my template file:

ID  Type    Label   Parent
ID  TYPE    A rdfs:label    SC %
AfPO:0000277    class   Western African HANCESTRO:0010
AfPO:0000410    class   Adele   (RO:0000086 some HANCESTRO:0599)
AfPO:0000325    class   Afrikaner   (RO:0000086 some HANCESTRO:0599)

HANCESTRO:0010 turns out fine but HANCESTRO:0599is now both a class and a datatype. I've tried various permutations, e.g. having a column header of

Ethicity Descriptor
SC RO:0000086 some %

and then just HANCESTRO:0599 in the cell, but the outcome is the same. I also double-checked some components that have been around for a while, and the problem occurs for these as well when it hasn't before (comparing with the current release version from April 2024).

As per @jamesaoverton's suggestion, I then replaced RO:0000086 with 'has quality' (and the same for any other object properties in my templates) and this fixed the issue.

Problem replicated in release v1.9.6, 1.9.5 and 1.9.4. Last successful version uncertain but may have been 1.9.2 or 1.9.3.

matentzn commented 3 weeks ago

I bet this PR is somehow related to this issue: https://github.com/ontodev/robot/pull/1104, but I am not sure. Timeline fits.

ramonawalls commented 1 week ago

I am having the same problem. See https://github.com/PlantPhenoOntology/ppo/blob/odk-conversion/src/ontology/components/PPO_plant_structures.owl. The template is at https://github.com/PlantPhenoOntology/ppo/blob/odk-conversion/src/templates/PPO_plant_structures.tsv

I am using the latest ODK.

I can't replace RO:0000086 with 'has quality' as @daniwelter was able to do, because of the problem described in #1053.

Feeling sad.

jamesaoverton commented 6 days ago

Hi @ramonawalls. You should not need to use CURIEs everywhere in your templates. ROBOT is much happier if you use labels. And you should not need to quote labels most of the time -- only when they occur inside a logical expression. OBI has many examples: https://github.com/obi-ontology/obi/tree/master/src/ontology/templates.

In order to parse templates (whether labels or CURIEs) ROBOT needs to know that you're using Object Properties or Data Properties or Annotation Properties or Classes, etc. That's why the --input foo.owl option is important.

ramonawalls commented 4 days ago

Thank you again! I'm noting issue #442 so the examples only have to be in one place.

@jamesaoverton, could you please provide links to the corresponding input files used in the OBI examples?

jamesaoverton commented 4 days ago

This command runs the various OBI templates: https://github.com/obi-ontology/obi/blob/master/Makefile#L92. It imports obi-edit.owl, which imports most of OBI, including previous template results. @matentzn can also provide many examples.

ramonawalls commented 4 days ago

@matentzn here is an example of a template that generates duplicate datatypes and the corresponding OWL file:

https://github.com/PlantPhenoOntology/ppo/blob/odk-conversion/src/templates/PPO_plant_structures.tsv

https://github.com/PlantPhenoOntology/ppo/blob/odk-conversion/src/ontology/components/PPO_plant_structures.owl

ramonawalls commented 4 days ago

A couple more points.

  1. I did try to use my edit file as input, but I couldn't get it to work after a few tries. It would be really nice to have an example (maybe in the ODK documentation) on how to specify a robot input file in the yaml template for the ontology repo. I am familiar with the ODK schema, but it can be a little hard to follow.
  2. I see that OBI uses their edit file for input. I can do the same for PPO now that is has been built, but if one is trying to build an ontology for the first time using only templates, there would be no source for inputs. This is especially problematic if you are creating the ontology's properties in a template and want to use them in another template and run the whole build at one time. In that case, one would have to built a supporting ontology first with the properties.
  3. An edge case I know, but what if the property used in a class expression in part of the same template that contains the class expression? Would robot then recognize it as a property?
ramonawalls commented 4 days ago

I updated my ppo-odk.yaml to include

    - filename: PPO_plant_structures.owl
      use_template: TRUE
      template_options: --add-prefixes config/context.json --input https://raw.githubusercontent.com/PlantPhenoOntology/ppo/master/releases/2019-01-16/ppo.owl
      templates:
        - PPO_plant_structures.tsv

which generated the following robot command in my makefile

$(COMPONENTSDIR)/PPO_plant_structures.owl: $(TEMPLATEDIR)/PPO_plant_structures.tsv
    if [ $(COMP) = true ] ; then $(ROBOT) template --add-prefixes config/context.json --input https://raw.githubusercontent.com/PlantPhenoOntology/ppo/master/releases/2019-01-16/ppo.owl \
        $(patsubst %, --template %, $^) \
        $(ANNOTATE_CONVERT_FILE); fi

.PRECIOUS: $(COMPONENTSDIR)/PPO_plant_structures.owl

but when I ran make all_components nothing changed in PPO_plant_structures.owl.

ramonawalls commented 4 days ago

I also tried copying the latest release of the file to my src/ontology directory and pointing at it

if [ true = true ] ; then robot --catalog catalog-v001.xml template --add-prefixes config/context.json --input ppo-input.owl \
     --template ../templates/PPO_plant_structures.tsv \
    annotate --ontology-iri http://purl.obolibrary.org/obo/ppo/components/PPO_plant_structures.owl annotate -V http://purl.obolibrary.org/obo/ppo/releases/2024-07-04/components/PPO_plant_structures.owl --annotation owl:versionInfo 2024-07-04 convert -f ofn --output components/PPO_plant_structures.owl.tmp.owl && mv components/PPO_plant_structures.owl.tmp.owl components/PPO_plant_structures.owl; fi

but it didn't make a difference.

matentzn commented 3 days ago

There are good and bad news.

The bad news, the problem seems real:

robot template --input ontology.owl --template template.tsv -o out.owl

With:

template.tsv:

ID  TYPE    Subclass of
ID  TYPE    SC %
PPO:0001012 class   (PPO:0000010 some PPO:0001004)

ontology.owl:

Prefix(:=<http://purl.obolibrary.org/obo/ppo.owl#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)

Ontology(<http://purl.obolibrary.org/obo/robot-issue-1203.owl>
Declaration(ObjectProperty(<http://purl.obolibrary.org/obo/PPO_0000010>))
)

results in:

<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="http://www.w3.org/2002/07/owl"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <Ontology/>

    <rdfs:Datatype rdf:about="http://purl.obolibrary.org/obo/PPO_0001004"/>
    <DatatypeProperty rdf:about="http://purl.obolibrary.org/obo/PPO_0000010"/>

 { REST OMITTED FOR BREVITY }....

It appears that the "oracle" (--input) does not work as intended.

Fortunately there is an easy fix, by simply asserting the type of the object property in the same template:

ID  TYPE    Subclass of
ID  TYPE    SC %
PPO:0000010 object property 
PPO:0001012 class   (PPO:0000010 some PPO:0001004)

It does not matter then wether you are using the --input parameter or not:

robot template --template template.tsv -o out.owl

Works as well.

ramonawalls commented 3 days ago

Thank you, @matentzn! I'll give it a try.

ramonawalls commented 2 days ago

It worked! Woohoo!