ObjectProprerty Restrictions not generating in RDFXML

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

ObjectProprerty Restrictions not generating in RDFXML

MartyStache
I've been adding as indicated in the documentation ObjectProperty Restrictions and I don't see them coming out in the RDF XML. I do an example in Protege post export and see that they do then appear when I export from it.

What am I doing incorrectly??? Any help is greatly appreciated!

Here's example code of how I am capturing them:

class has_Equipments(ObjectProperty):
  domain = [EquipmentContainer]
  range = [Equipment]
has_Equipments.comment = ["Contained equipment."]
has_Equipments.min(0,Equipment)
has_Equipments.max(n,Equipment)

class EquipmentContainer_of(ObjectProperty):
  domain = [Equipment]
  range = [EquipmentContainer]
  inverse_property = has_Equipments
EquipmentContainer_of.comment = ["Container of this equipment."]
EquipmentContainer_of.min(0,EquipmentContainer)
EquipmentContainer_of.max(1,EquipmentContainer)
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

cknoll
Can you post an minimal example which allows to reproduce the behavior?
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

MartyStache
from owlready2 import *

onto = get_ontology("http://test.org/test.owl")

with onto:
        class EquipmentContainer(Thing):
                pass
        EquipmentContainer.comment = ["Something that contains equipment."]

        class Equipment(Thing):
                pass
        Equipment.comment = ["A necessary item for a particular purpose."]

        class has_Equipments(ObjectProperty):
                domain = [EquipmentContainer]
                range = [Equipment]
        has_Equipments.comment = ["Contained equipment."]
        has_Equipments.min(0,Equipment)
        has_Equipments.max(25,Equipment)

        class EquipmentContainer_of(ObjectProperty):
                domain = [Equipment]
                range = [EquipmentContainer]
                inverse_property = has_Equipments
        EquipmentContainer_of.comment = ["Container of this equipment."]
        EquipmentContainer_of.min(0,EquipmentContainer)
        EquipmentContainer_of.max(1,EquipmentContainer)

onto.save(file = "ExampleWithNoCardinality.xml", format = "rdfxml")

I would expect the output of this is supposed to look something like this:

<owl:Class rdf:about="http://test.org/test.owl#EquipmentContainer">
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://test.org/test.owl#has_Equipments"/>
            <owl:minQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">0</owl:minQualifiedCardinality>
            <owl:onClass rdf:resource="http://test.org/test.owl#Equipment/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://test.org/test.owl#has_Equipments"/>
            <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">25</owl:maxQualifiedCardinality>
            <owl:onClass rdf:resource="http://test.org/test.owl#Equipment"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"></rdfs:comment>
</owl:Class>

<owl:Class rdf:about="http://test.org/test.owl#Equipment">
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://test.org/test.owl#EquipmentContainer_of"/>
            <owl:minQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">0</owl:minQualifiedCardinality>
            <owl:onClass rdf:resource="http://test.org/test.owl#EquipmentContainer"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://test.org/test.owl#EquipmentContainer_of"/>
            <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxQualifiedCardinality>
            <owl:onClass rdf:resource="http://test.org/test.owl#EquipmentContainer"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"></rdfs:comment>
</owl:Class>
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

cknoll
I am not sure but this adaption of your example might help:
https://nbviewer.jupyter.org/github/cknoll/demo-material/blob/main/expertise_system/cardinality_restriction_demo.ipynb


Main difference: Instead of just creating the restriction object by `has_Equipments.max(25, Equipment) ` it is now added to the list `EquipmentContainer.is_a` via `EquipmentContainer.is_a.append(has_Equipments.max(25, Equipment))`.

Actually, I set the max-value to 1 to simplify the test whether the reasoner detects an violation to this restriction. This works as expected.

The restriction also shows up in the XML-Code.

Note that I simplified the example by considering only one of the original four restrictions...


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

RE: ObjectProprerty Restrictions not generating in RDFXML

MartyStache

This is exactly what I needed! Thanks a TON!

 

From: cknoll [via Owlready] <[hidden email]>
Sent: Monday, November 30, 2020 6:33 PM
To: Tim Duval <[hidden email]>
Subject: Re: ObjectProprerty Restrictions not generating in RDFXML

 

I am not sure but this adaption of your example might help:
https://nbviewer.jupyter.org/github/cknoll/demo-material/blob/main/expertise_system/cardinality_restriction_demo.ipynb


Main difference: Instead of just creating the restriction object by `has_Equipments.max(25, Equipment) ` it is now added to the list `EquipmentContainer.is_a` via `EquipmentContainer.is_a.append(has_Equipments.max(25, Equipment))`.

Actually, I set the max-value to 1 to simplify the test whether the reasoner detects an violation to this restriction. This works as expected.

The restriction also shows up in the XML-Code.

Note that I simplified the example by considering only one of the original four restrictions...


Best regards,
Carsten


If you reply to this email, your message will be added to the discussion below:

http://owlready.8326.n8.nabble.com/ObjectProprerty-Restrictions-not-generating-in-RDFXML-tp2124p2129.html

To unsubscribe from ObjectProprerty Restrictions not generating in RDFXML, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

MartyStache
In reply to this post by cknoll
What do I enter rather than 25 for max if is unlimited? Forgot to ask.

Is typically * or n but not sure which OWLReady2 accepts.

From: cknoll [via Owlready] <[hidden email]>
Sent: Monday, November 30, 2020 6:32:49 PM
To: Tim Duval <[hidden email]>
Subject: Re: ObjectProprerty Restrictions not generating in RDFXML
 
I am not sure but this adaption of your example might help:
https://nbviewer.jupyter.org/github/cknoll/demo-material/blob/main/expertise_system/cardinality_restriction_demo.ipynb


Main difference: Instead of just creating the restriction object by `has_Equipments.max(25, Equipment) ` it is now added to the list `EquipmentContainer.is_a` via `EquipmentContainer.is_a.append(has_Equipments.max(25, Equipment))`.

Actually, I set the max-value to 1 to simplify the test whether the reasoner detects an violation to this restriction. This works as expected.

The restriction also shows up in the XML-Code.

Note that I simplified the example by considering only one of the original four restrictions...


Best regards,
Carsten


If you reply to this email, your message will be added to the discussion below:
http://owlready.8326.n8.nabble.com/ObjectProprerty-Restrictions-not-generating-in-RDFXML-tp2124p2129.html
To unsubscribe from ObjectProprerty Restrictions not generating in RDFXML, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

cknoll
I am not sure but using `None` leads to

    <owl:Restriction>
      <owl:onProperty rdf:resource="#has_Equipments"/>
      <owl:onClass rdf:resource="#Equipment"/>
    </owl:Restriction>

which seems to "disable" the max-restriction.

On the other hand you could pass any string e.g. "inf" or "foobar" or "*". This string value ends up in the XML (without the quotes). So it depends what the program with which you will open the xml expects. (I do not know what the standard is for such case.)

Example: `EquipmentContainer.is_a.append(has_Equipments.max("*", Equipment))` leads to

<owl:Restriction>
      <owl:onProperty rdf:resource="#has_Equipments"/>
      <owl:onClass rdf:resource="#Equipment"/>
      <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">*</owl:maxQualifiedCardinality>
</owl:Restriction>

Best,
Carsten
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

MartyStache
Maybe safest bet is to only enter a min?
Then there is a restriction on min, but none on max?


From: cknoll [via Owlready] <[hidden email]>
Sent: Tuesday, December 1, 2020 5:42:55 AM
To: Tim Duval <[hidden email]>
Subject: Re: ObjectProprerty Restrictions not generating in RDFXML
 
I am not sure but using `None` leads to

    <owl:Restriction>
      <owl:onProperty rdf:resource="#has_Equipments"/>
      <owl:onClass rdf:resource="#Equipment"/>
    </owl:Restriction>

which seems to "disable" the max-restriction.

On the other hand you could pass any string e.g. "inf" or "foobar" or "*". This string value ends up in the XML (without the quotes). So it depends what the program with which you will open the xml expects. (I do not know what the standard is for such case.)

Example: `EquipmentContainer.is_a.append(has_Equipments.max("*", Equipment))` leads to

<owl:Restriction>
      <owl:onProperty rdf:resource="#has_Equipments"/>
      <owl:onClass rdf:resource="#Equipment"/>
      <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">*</owl:maxQualifiedCardinality>
</owl:Restriction>

Best,
Carsten


If you reply to this email, your message will be added to the discussion below:
http://owlready.8326.n8.nabble.com/ObjectProprerty-Restrictions-not-generating-in-RDFXML-tp2124p2132.html
To unsubscribe from ObjectProprerty Restrictions not generating in RDFXML, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: ObjectProprerty Restrictions not generating in RDFXML

Jiba
Administrator
Hi,

If the maximum is unlimited, you don't need a "max" restriction at all. I'm not sure that OWL accepts a "max" restriction without a maximum.

Jiba