ontodev / robot

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

SPARQL update vs query different results #967

Closed matentzn closed 2 years ago

matentzn commented 2 years ago

Not sure this is an "issue" in the strict sense. I two SPARQL queries with identical WHERE clauses. However, while the select query works as expected:

robot --catalog catalog-v001.xml query --use-graphs true -i mondo-edit.obo --query disorders-conformsTo-location.sparql report.txt

The update query does not do anything:

robot --catalog catalog-v001.xml query --use-graphs true -i mondo-edit.obo --update fix-disorders-conformsTo-location.ru convert -f obo --check false -o mondo-edit.obo

I don't know exactly how --use-graphs interacts with update (some of the triples in the matching pattern are in imports).

SELECT:

SELECT distinct *
WHERE {
  ?term rdfs:label ?label .
  ?term dcterms:conformsTo mondoPatterns:location.yaml .
  FILTER NOT EXISTS { ?term owl:deprecated "true"^^xsd:boolean . }
  FILTER (isIRI(?term) && regex(str(?term), "^http://purl.obolibrary.org/obo/MONDO_"))
  FILTER(regex(str(?label),"disease"))
  BIND(REPLACE(str(?label), "disease", "disorder") as ?new_label )
}

UPDATE:

DELETE {
  ?term rdfs:label ?label .
}
WHERE {
  ?term rdfs:label ?label .
  ?term dcterms:conformsTo mondoPatterns:location.yaml .
  FILTER NOT EXISTS { ?term owl:deprecated "true"^^xsd:boolean . }
  FILTER (isIRI(?term) && regex(str(?term), "^http://purl.obolibrary.org/obo/MONDO_"))
  FILTER(regex(str(?label),"disease"))
  BIND(REPLACE(str(?label), "disease", "disorder") as ?new_label )
}
balhoff commented 2 years ago

You probably need to specify the graph in your DELETE. Otherwise you're just deleting from the default graph. You could capture the graph in the WHERE if you don't know it.

matentzn commented 2 years ago

Oh wow, really? I never knew that.. What would I do without you :D

However, this does not work:

DELETE {
  GRAPH <http://purl.obolibrary.org/obo/mondo.owl> 
  { 
    ?term rdfs:label ?label .
  }
}
INSERT {
  GRAPH <http://purl.obolibrary.org/obo/mondo.owl> 
  { 
    ?term rdfs:label ?new_label .
  }
}
WHERE {
  ?term rdfs:label ?label .
  ?term dcterms:conformsTo mondoPatterns:location.yaml .
  FILTER NOT EXISTS { ?term owl:deprecated "true"^^xsd:boolean . }
  FILTER (isIRI(?term) && regex(str(?term), "^http://purl.obolibrary.org/obo/MONDO_"))
  FILTER(regex(str(?label),"disease"))
  BIND(REPLACE(str(?label), "disease", "disorder") as ?new_label )
}

Despite:

SELECT DISTINCT ?g 
WHERE {
  GRAPH ?g { ?s ?p ?o }
}

resulting in

?g
<http://purl.obolibrary.org/obo/mondo/imports/ecto_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/chr_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/so_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/ro_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/ncbitaxon_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/pato_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/mfomd_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/uberon_import.owl>
<http://purl.obolibrary.org/obo/mondo.owl>
<http://purl.obolibrary.org/obo/mondo/imports/envo_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/oba_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/nbo_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/maxo_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/omo_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/hp_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/mf_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/go_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/foodon_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/chebi_import.owl>
<http://purl.obolibrary.org/obo/mondo/components/mondo-tags.owl>
<http://purl.obolibrary.org/obo/mondo/imports/hgnc_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/hsapdv_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/cl_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/ncit_import.owl>
<http://purl.obolibrary.org/obo/mondo/imports/axioms.owl>
jamesaoverton commented 2 years ago

Can we close this?

matentzn commented 2 years ago

Yes, not really a robot issue.