Thanks Lorenz,

that was helpful for me, I solved it using your advice with the following code:


Individual male = model.createIndividual(baseURI + "male", OWL.Thing);
Individual female = model.createIndividual(baseURI + "female", OWL.Thing);
RDFList enums = model.createList();
enums = enums.cons(male);
enums = enums.cons(female);

OntClass newItemClass = model.createClass(baseURI + "TestClass");
ObjectProperty objectProperty = model.createObjectProperty(baseURI + "TestObjectProperty");

Resource resurs = model.createResource();
resurs.addProperty(OWL2.oneOf, enums);

MaxCardinalityRestriction restriction = model.createMaxCardinalityRestriction(null, objectProperty, 1);
restriction.removeAll(OWL.cardinality);
restriction.addLiteral(OWL2.maxQualifiedCardinality, 1);
restriction.addProperty(OWL2.onClass, resurs);

newItemClass.addSuperClass(restriction);

Best regards,

Darko


On 17.10.2016. 11:18, Lorenz B. wrote:
Hello Darko,

from the W3C recommendation [1]:


to generate a class expression for qualified max. cardinality
restriction on object property OPE:

_:x rdf:type owl:Restriction .
_:x owl:onProperty T(OPE) .
_:x owl:maxQualifiedCardinality "n"^^xsd:nonNegativeInteger .
_:x owl:onClass T(CE) .

And the CE would be an enumeration aka. owl:oneOf, which in RDF is
expressed by

_:x rdf:type owl:Class .
_:x owl:oneOf T(SEQ a1 ... an) .

where T denotes an RDF list.



[1] https://www.w3.org/TR/owl2-mapping-to-rdf/

Cheers,
Lorenz

Hi Lorenz,

do you know which RDF triples I need to manually add to achieve
manually the wanted format?

Thanks,

Darko


On 16.10.2016. 20:18, Lorenz Buehmann wrote:
@Dave: Yes, that's also what I understand:

He wants to get a qualified cardinality restriction on an object
property such that the restriction is of type owl:oneOf.

But as he already noticed, this is OWL 2, thus no convenience methods in
the ontology layer of Jena exists so far.


Cheers,

Lorenz


On 16.10.2016 20:09, Dave Reynolds wrote:
On 15/10/16 22:32, Darko Androcec wrote:
My aim is to get the following enumerated restriction using Apache
Jena:

   <SubClassOf>
          <Class IRI="http://www.equixonline.com/Grainger#TestClass"/>

          <ObjectMaxCardinality cardinality="1">

              <ObjectProperty
IRI="http://www.equixonline.com/Grainger#TestObjectProperty"/>

              <ObjectOneOf>
                  <NamedIndividual
IRI="http://www.equixonline.com/Grainger#male"/>
                  <NamedIndividual
IRI="http://www.equixonline.com/Grainger#female"/>
              </ObjectOneOf>

          </ObjectMaxCardinality>

</SubClassOf>
That doesn't make sense as a piece of RDF/XML let alone a piece of OWL.

I tried different codes, but can't get the above restriction. If I use
the following code:

OntClass newItemClass = model.createClass(baseURI + "TestClass");
ObjectProperty objectProperty = model.createObjectProperty(baseURI +
"TestObjectProperty");
MaxCardinalityRestriction restriction =
model.createMaxCardinalityRestriction(null, objectProperty, 1);

newItemClass.addSuperClass(restriction);

I get max cardinality restriction without enumeration:

   <SubClassOf>
          <Class IRI="http://www.equixonline.com/Grainger#TestClass"/>
          <ObjectMaxCardinality cardinality="1">
              <ObjectProperty
IRI="http://www.equixonline.com/Grainger#TestObjectProperty"/>
          </ObjectMaxCardinality>
      </SubClassOf>
You shouldn't, you should get:

<owl:Class rdf:about="http://www.equixonline.com/Grainger#TestClass";>
      <rdfs:subClassOf>
        <owl:Restriction>
          <owl:maxCardinality
rdf:datatype="http://www.w3.org/2001/XMLSchema#int";
          >1</owl:maxCardinality>
          <owl:onProperty>
            <owl:ObjectProperty
rdf:about="http://www.equixonline.com/Grainger#TestObjectProperty"/>
          </owl:onProperty>
        </owl:Restriction>
      </rdfs:subClassOf>
    </owl:Class>

When I add the following code:

Individual male = model.createIndividual(baseURI + "male", OWL.Thing);
Individual female = model.createIndividual(baseURI + "female",
OWL.Thing);
RDFList enums = model.createList();
enums = enums.cons(male);
enums = enums.cons(female);

OntClass newItemClass = model.createClass(baseURI + "TestClass");
ObjectProperty objectProperty = model.createObjectProperty(baseURI +
"TestObjectProperty");
MaxCardinalityRestriction restriction =
model.createMaxCardinalityRestriction(null, objectProperty, 1);

restriction.addProperty(OWL.oneOf, enums);

newItemClass.addSuperClass(restriction);

I only get enumeration, but max cardinality restriction is nowhere to
find:

<SubClassOf>
          <Class IRI="http://www.equixonline.com/Grainger#TestClass"/>
          <ObjectOneOf>
              <NamedIndividual
IRI="http://www.equixonline.com/Grainger#male"/>
              <NamedIndividual
IRI="http://www.equixonline.com/Grainger#female"/>
          </ObjectOneOf>
</SubClassOf>
No, you won't get that. Among other things your above code does not
create an owl:NamedIndividual type. If I run your code I get:

    <owl:Class
rdf:about="http://www.equixonline.com/Grainger#TestClass";>
      <rdfs:subClassOf>
        <owl:Restriction>
          <owl:oneOf rdf:parseType="Collection">
            <owl:Thing
rdf:about="http://www.equixonline.com/Grainger#female"/>
            <owl:Thing
rdf:about="http://www.equixonline.com/Grainger#male"/>
          </owl:oneOf>
          <owl:maxCardinality
rdf:datatype="http://www.w3.org/2001/XMLSchema#int";
          >1</owl:maxCardinality>
          <owl:onProperty>
            <owl:ObjectProperty
rdf:about="http://www.equixonline.com/Grainger#TestObjectProperty"/>
          </owl:onProperty>
        </owl:Restriction>
      </rdfs:subClassOf>
    </owl:Class>


Which doesn't make sense as OWL (the oneOf and maxCardinality should
be separate) but at least the maxCardinality hasn't disappeared.

Do you maybe know what I am doing wrong and how to get format
(enumerated restriction) described at the beginning of this message?
An enumeration is created as you've done it but use addSuperClass
again to add it to your class, don't patch it into the existing
restriction.

However, perhaps you mean that you want a qualified cardinality
restriction where testObjectProperty is restricted to at most one out
of the set #male and #female?  The RDF for that is quite different.

Dave



Reply via email to