Object Properties not updating after SPARQL Update queries if accessed previously

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Object Properties not updating after SPARQL Update queries if accessed previously

Stefan
Hi,

I found a bug where object properties are not properly updated in python.
Reproduction steps:
1. Access a property in python
2. Change property using SPARQL Update, either by adding more relations or removing relations
3. Access property again in python

- The property will still be the same as before the SPARQL Update query
- When performing a SPARQL query to output the property instead of using the python attribute, the expected/correct result will be given
- When not accessing the property before the Update query, it will also give the correct result

Example:
Python code:

import owlready2 as or2
ontology = or2.get_ontology("file://bug.owl").load()
graph = or2.default_world.as_rdflib_graph()
graph.bind("ontology", "http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#")

# Comment out this print statement to fix
print(ontology.I1.O)
with ontology:
    graph.update("""
    DELETE {
        ontology:I1 ontology:O ontology:I2 .
    } WHERE {}
    """)


print(ontology.I1.O)
print(list(graph.query("""SELECT ?x WHERE {ontology:I1 ontology:O ?x }""")))


Ontology:

<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#"
     xml:base="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210"
     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#"
     xmlns:untitled-ontology-210="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210"/>
   


   

   


   

    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#O"/>
   


   

   


   

    <owl:Class rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#A"/>
   


   

   


   

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I1">
        <rdf:type rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#A"/>
        <O rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I2"/>
        <O rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I3"/>
    </owl:NamedIndividual>
   


   

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I2">
        <rdf:type rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#A"/>
    </owl:NamedIndividual>
   


   

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I3">
        <rdf:type rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#A"/>
    </owl:NamedIndividual>
   


   

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#I4">
        <rdf:type rdf:resource="http://www.semanticweb.org/stlu/ontologies/2019/5/untitled-ontology-210#A"/>
    </owl:NamedIndividual>
</rdf:RDF>





Reply | Threaded
Open this post in threaded view
|

Re: Object Properties not updating after SPARQL Update queries if accessed previously

Stefan
Also, when saving the ontology using the .save() method of the python object, it will save the correct result either way (i.e. with the Update changes)
Reply | Threaded
Open this post in threaded view
|

Re: Object Properties not updating after SPARQL Update queries if accessed previously

Jiba
Administrator
In reply to this post by Stefan
Hi,

This was a known limit: SPARQL queries update the quadstore but the previously loaded Python objects were not updated.

In the development version, I've added basic update support. It works on object and data properties, on hierarchical relations (type/subclassof) and equivalence relations. However, do not expect it to work yet on more complex changes, such as modifying the blank nodes defining a restriction (but I'm not sure SPARQL allows that).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Object Properties not updating after SPARQL Update queries if accessed previously

Stefan
That's more than enough for me right now. Thanks!