Reasoning with data properties

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

Reasoning with data properties

liam
Dear Jean-Baptiste,

I have been enjoying using Owlready2 to reason with ontologies generated using Protégé. However, I haven’t fully understood how to create an instance with data properties that gets properly classified. Unfortunately, I’ve been unable to find any documentation or trouble shooting help in the forum, etc.

In the below example, the "LabValue1" instance "TestLabValue1Increased" does not get classified into the class "IncreasedLabValue1" (which it does in Protege, as expected).

Please find the Python script and ontology (in RDF/OWL format) below the signature.

Any advice or help would be appreciated.

Yours sincerely,
Nicolai


Script for classification
```
import owlready2

ontology = owlready2.get_ontology("file:///home/liam/Documents/test.owl").load()
lab_value = ontology['LabValue1']()
lab_value.isOfValue = 5.
owlready2.sync_reasoner()
print(lab_value.__class__)
```

Ontology for classification
```
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/liamchilds/test#"
     xml:base="http://www.semanticweb.org/liamchilds/test"
     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:disease_onto="http://www.gotthardt.com/nicolaischoch/disease_onto#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/liamchilds/test"/>
    <owl:DatatypeProperty rdf:about="http://www.gotthardt.com/nicolaischoch/disease_onto#isOfValue">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
    </owl:DatatypeProperty>
    <owl:Class rdf:about="http://www.semanticweb.org/liamchilds/test#IncreasedLabValue1">
        <owl:equivalentClass>
            <owl:Class>
                <owl:intersectionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="http://www.semanticweb.org/liamchilds/test#LabValue1"/>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://www.gotthardt.com/nicolaischoch/disease_onto#isOfValue"/>
                        <owl:someValuesFrom>
                            <rdfs:Datatype>
                                <owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
                                <owl:withRestrictions rdf:parseType="Collection">
                                    <rdf:Description>
                                        <xsd:minExclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#float">4.0</xsd:minExclusive>
                                    </rdf:Description>
                                </owl:withRestrictions>
                            </rdfs:Datatype>
                        </owl:someValuesFrom>
                    </owl:Restriction>
                </owl:intersectionOf>
            </owl:Class>
        </owl:equivalentClass>
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/liamchilds/test#LabValue1"/>
    </owl:Class>
    <owl:Class rdf:about="http://www.semanticweb.org/liamchilds/test#LabValue"/>
    <owl:Class rdf:about="http://www.semanticweb.org/liamchilds/test#LabValue1">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/liamchilds/test#LabValue"/>
    </owl:Class>
    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/liamchilds/test#TestLabValue1Increased">
        <rdf:type rdf:resource="http://www.semanticweb.org/liamchilds/test#LabValue1"/>
        <disease_onto:isOfValue rdf:datatype="http://www.w3.org/2001/XMLSchema#float">5.0</disease_onto:isOfValue>
    </owl:NamedIndividual>
</rdf:RDF>
```
Reply | Threaded
Open this post in threaded view
|

Re: Reasoning with data properties

Jiba
Administrator
Hello,

I've investigated the problem; it is caused by the fact that your ontology is using xsd:float. On the contrary, Owlready use xsd:decimal for representing Python's float, and not xsd:float (because xsd:integer can be used in place of decimal, but not in place of float).

Therefore, you need to use the following in your ontology :

    LabValue1 and (isOfValue some decimal[> "4.0"^^decimal])

instead of :

    LabValue1 and (isOfValue some float[> 4.0f])

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Reasoning with data properties

Jiba
Administrator
Alternatively, you can also force Owlready to save float as xsd:float, by adding this line at the beginning :

owlready2.set_datatype_iri(float, "http://www.w3.org/2001/XMLSchema#float")

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Reasoning with data properties

liam
Dear Jean-Baptiste,

I'm a developer working with Nicolai. The solution you proposed worked perfectly! Thanks!

Cheers,
Liam
Reply | Threaded
Open this post in threaded view
|

Re: Reasoning with data properties

Nicolai
Dear Jean-Baptiste,

thanks for your help! This solved our problem!

With best wishes
Nicolai