Discussion:
How to create restrictions that range on singleton collections or singleton datatypes
Jos Lehmann
2016-11-08 14:02:57 UTC
Permalink
Hi there



I am new to jena and I'm trying the write the two following restrictions into an owl (rdf/xml) ontology:



- in_category property should range over a singleton (Collection) containing only #Bo,

- is_XXX_type should range over a singleton containing only the Boolean value "true"



My code (below) cannot write the parts of the desired output (below) marked with ==>.



So far, I have been working to achieve the second part of the desired output (i.e. the #is_XXX_type part), and that's my priority, but suggestions on the first part would be welcome.





DESIRED OUTPUT



<owl:Class rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">

<rdfs:subClassOf rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"/>

<rdfs:subClassOf rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"/>

<rdfs:subClassOf>

<owl:Restriction>

<owl:onProperty rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in_category"/>

<owl:allValuesFrom>

==> <owl:Class>

==> <owl:oneOf rdf:parseType="Collection">

==> <rdf:Description rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>

==> </owl:oneOf>

==> </owl:Class>

</owl:allValuesFrom>

</owl:Restriction>

</rdfs:subClassOf>

<rdfs:subClassOf>

<owl:Restriction>

<owl:onProperty rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>

<owl:allValuesFrom>

==> <rdfs:Datatype>

==> <owl:oneOf>

==> <rdf:Description>

==> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>

==> <rdf:first rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:first>

==> <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>

==> </rdf:Description>

==> </owl:oneOf>

</rdfs:Datatype>

</owl:allValuesFrom>

</owl:Restriction>

</rdfs:subClassOf>

</owl:Class>





MY CODE (note: the new class is derived from an existing individual)



OntClass newClass = model2.createClass(thisInstance.toString());



DatatypeProperty is_XXX_type = model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");



is_XXX_type.setRange(XSD.xboolean);



Restriction restriction = model2.createAllValuesFromRestriction(null, is_ XXX_type, XSD.xboolean);



newClass.addSuperClass(restriction);







MY PRESENT OUTPUT FOR THE is_XXX_type CASE:



<owl:Class rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">

<rdfs:subClassOf>

<owl:Restriction>

<owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>

<owl:onProperty>

<owl:DatatypeProperty rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>

</owl:onProperty>

</owl:Restriction>

</rdfs:subClassOf>

</owl:Class>









Thank you in advance for the advice.



Jos Lehmann



Knowledge Management

Bauhaus Luftfahrt e.V.

GERMANY
Dave Reynolds
2016-11-09 08:42:28 UTC
Permalink
Post by Jos Lehmann
Hi there
- in_category property should range over a singleton (Collection) containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the allValuesFrom
restriction.
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous instance
of rdfs:Datatype, create a RDFList containing boolean true then link
them with an owl:oneOf property, then again pass that to the allValuesFrom.

Dave
Post by Jos Lehmann
My code (below) cannot write the parts of the desired output (below) marked with ==>.
So far, I have been working to achieve the second part of the desired output (i.e. the #is_XXX_type part), and that's my priority, but suggestions on the first part would be welcome.
DESIRED OUTPUT
<owl:Class rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"/>
<rdfs:subClassOf rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in_category"/>
<owl:allValuesFrom>
==> <owl:Class>
==> <owl:oneOf rdf:parseType="Collection">
==> <rdf:Description rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>
==> </owl:oneOf>
==> </owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
<owl:allValuesFrom>
==> <rdfs:Datatype>
==> <owl:oneOf>
==> <rdf:Description>
==> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
==> <rdf:first rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:first>
==> <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
==> </rdf:Description>
==> </owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
MY CODE (note: the new class is derived from an existing individual)
OntClass newClass = model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type = model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Restriction restriction = model2.createAllValuesFromRestriction(null, is_ XXX_type, XSD.xboolean);
newClass.addSuperClass(restriction);
<owl:Class rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf>
<owl:Restriction>
<owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
<owl:onProperty>
<owl:DatatypeProperty rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Thank you in advance for the advice.
Jos Lehmann
Knowledge Management
Bauhaus Luftfahrt e.V.
GERMANY
Lorenz B.
2016-11-09 09:17:29 UTC
Permalink
Hello Dave,

my question would be whether he ask how to set this singleton enumeration as

a) the range of the property or

b) used in a class expression with

b1) owl:hasValue or

b2) like you suggested to use owl:allValuesFrom



Cheers,
Lorenz
Post by Dave Reynolds
Post by Jos Lehmann
Hi there
I am new to jena and I'm trying the write the two following
- in_category property should range over a singleton (Collection) containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to the
allValuesFrom.
Dave
Post by Jos Lehmann
My code (below) cannot write the parts of the desired output (below) marked with ==>.
So far, I have been working to achieve the second part of the desired
output (i.e. the #is_XXX_type part), and that's my priority, but
suggestions on the first part would be welcome.
DESIRED OUTPUT
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"/>
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in_category"/>
<owl:allValuesFrom>
==> <owl:Class>
==> <owl:oneOf rdf:parseType="Collection">
==> <rdf:Description
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>
==> </owl:oneOf>
==> </owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
<owl:allValuesFrom>
==> <rdfs:Datatype>
==> <owl:oneOf>
==> <rdf:Description>
==> <rdf:type
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
==> <rdf:first
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:first>
==> <rdf:rest
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
==> </rdf:Description>
==> </owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
MY CODE (note: the new class is derived from an existing individual)
OntClass newClass =
model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type =
model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Restriction restriction =
model2.createAllValuesFromRestriction(null, is_ XXX_type, XSD.xboolean);
newClass.addSuperClass(restriction);
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf>
<owl:Restriction>
<owl:allValuesFrom
rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
<owl:onProperty>
<owl:DatatypeProperty
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Thank you in advance for the advice.
Jos Lehmann
Knowledge Management
Bauhaus Luftfahrt e.V.
GERMANY
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Dave Reynolds
2016-11-09 09:58:34 UTC
Permalink
Hi Lorenz,
Post by Lorenz B.
Hello Dave,
my question would be whether he ask how to set this singleton enumeration as
a) the range of the property or
b) used in a class expression with
b1) owl:hasValue or
b2) like you suggested to use owl:allValuesFrom
The example "desired output" RDF/XML seemed fairly clear that the goal
is to create an allValuesFrom restriction.

Cheers,
Dave
Post by Lorenz B.
Cheers,
Lorenz
Post by Dave Reynolds
Post by Jos Lehmann
Hi there
I am new to jena and I'm trying the write the two following
- in_category property should range over a singleton (Collection) containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to the
allValuesFrom.
Dave
Post by Jos Lehmann
My code (below) cannot write the parts of the desired output (below) marked with ==>.
So far, I have been working to achieve the second part of the desired
output (i.e. the #is_XXX_type part), and that's my priority, but
suggestions on the first part would be welcome.
DESIRED OUTPUT
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"/>
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in_category"/>
<owl:allValuesFrom>
==> <owl:Class>
==> <owl:oneOf rdf:parseType="Collection">
==> <rdf:Description
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>
==> </owl:oneOf>
==> </owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
<owl:allValuesFrom>
==> <rdfs:Datatype>
==> <owl:oneOf>
==> <rdf:Description>
==> <rdf:type
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
==> <rdf:first
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:first>
==> <rdf:rest
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
==> </rdf:Description>
==> </owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
MY CODE (note: the new class is derived from an existing individual)
OntClass newClass =
model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type =
model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Restriction restriction =
model2.createAllValuesFromRestriction(null, is_ XXX_type, XSD.xboolean);
newClass.addSuperClass(restriction);
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf>
<owl:Restriction>
<owl:allValuesFrom
rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
<owl:onProperty>
<owl:DatatypeProperty
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Thank you in advance for the advice.
Jos Lehmann
Knowledge Management
Bauhaus Luftfahrt e.V.
GERMANY
Lorenz B.
2016-11-09 10:14:11 UTC
Permalink
Ah, I didn't look at the RDF/XML snippet. Yes, then it's clear and your
solution should work perfectly.

Cheers,
Lorenz
Post by Dave Reynolds
Hi Lorenz,
Post by Lorenz B.
Hello Dave,
my question would be whether he ask how to set this singleton
enumeration as
a) the range of the property or
b) used in a class expression with
b1) owl:hasValue or
b2) like you suggested to use owl:allValuesFrom
The example "desired output" RDF/XML seemed fairly clear that the goal
is to create an allValuesFrom restriction.
Cheers,
Dave
Post by Lorenz B.
Cheers,
Lorenz
Post by Dave Reynolds
Post by Jos Lehmann
Hi there
I am new to jena and I'm trying the write the two following
- in_category property should range over a singleton (Collection)
containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to the
allValuesFrom.
Dave
Post by Jos Lehmann
My code (below) cannot write the parts of the desired output (below) marked with ==>.
So far, I have been working to achieve the second part of the desired
output (i.e. the #is_XXX_type part), and that's my priority, but
suggestions on the first part would be welcome.
DESIRED OUTPUT
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"/>
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in_category"/>
<owl:allValuesFrom>
==> <owl:Class>
==> <owl:oneOf rdf:parseType="Collection">
==> <rdf:Description
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>
==> </owl:oneOf>
==> </owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
<owl:allValuesFrom>
==> <rdfs:Datatype>
==> <owl:oneOf>
==> <rdf:Description>
==> <rdf:type
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
==> <rdf:first
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:first>
==> <rdf:rest
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
==> </rdf:Description>
==> </owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
MY CODE (note: the new class is derived from an existing individual)
OntClass newClass =
model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type =
model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Restriction restriction =
model2.createAllValuesFromRestriction(null, is_ XXX_type,
XSD.xboolean);
newClass.addSuperClass(restriction);
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf>
<owl:Restriction>
<owl:allValuesFrom
rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
<owl:onProperty>
<owl:DatatypeProperty
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Thank you in advance for the advice.
Jos Lehmann
Knowledge Management
Bauhaus Luftfahrt e.V.
GERMANY
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Jos Lehmann
2016-11-09 16:02:17 UTC
Permalink
Hi Dave & Lorenzo

thank you very much for your replies. I am still struggling with the code of the case with a singleton with "true" (CASE B below).

As in my code below, I (think I) can create the list with "true" as well an anonymous datatype. But then I can't link them by OWL.oneOf. In the code I am stalling from the lines marked ==>.

My intention would have been to define a link before the anonymous datatype and replace " OntClass.class " with " link " in the datatype definition. But that's not working.


CASE A
Post by Dave Reynolds
Post by Lorenz B.
Post by Dave Reynolds
Post by Jos Lehmann
- in_category property should range over a singleton (Collection)
containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
CASE B
Post by Dave Reynolds
Post by Lorenz B.
Post by Dave Reynolds
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to
the allValuesFrom.
CODE

Individual thisInstance = (Individual) instances.next();

OntClass newClass = model2.createClass(thisInstance.toString());

DatatypeProperty is_XXX_type = model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");

is_XXX_type.setRange(XSD.xboolean);

Literal tV = model2.createTypedLiteral(true);

RDFList list = model2.createList(); /* create a RDFList containing boolean true */
list = list.cons(tV); /* create a RDFList containing boolean true */

OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null); /* create an anonymous instance of rdfs:Datatype */

==> RDFNode link = list.getPropertyResourceValue(OWL.oneOf).as(RDFList.class); /* then link them with an owl:oneOf property */

==> Restriction restriction = model2.createAllValuesFromRestriction(null, is_XXX_type, test); /* then again pass that to the allValuesFrom. */

newClass.addSuperClass(restriction);




Suggestions welcome.

Cheers, Jos


-----Ursprüngliche Nachricht-----
Von: Lorenz B. [mailto:***@informatik.uni-leipzig.de]
Gesendet: Mittwoch, 9. November 2016 11:14
An: ***@jena.apache.org
Betreff: Re: How to create restrictions that range on singleton collections or singleton datatypes

Ah, I didn't look at the RDF/XML snippet. Yes, then it's clear and your solution should work perfectly.

Cheers,
Lorenz
Post by Dave Reynolds
Hi Lorenz,
Post by Lorenz B.
Hello Dave,
my question would be whether he ask how to set this singleton
enumeration as
a) the range of the property or
b) used in a class expression with
b1) owl:hasValue or
b2) like you suggested to use owl:allValuesFrom
The example "desired output" RDF/XML seemed fairly clear that the goal
is to create an allValuesFrom restriction.
Cheers,
Dave
Post by Lorenz B.
Cheers,
Lorenz
Post by Dave Reynolds
Post by Jos Lehmann
Hi there
I am new to jena and I'm trying the write the two following
- in_category property should range over a singleton (Collection)
containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to
the allValuesFrom.
Dave
Post by Jos Lehmann
My code (below) cannot write the parts of the desired output (below) marked with ==>.
So far, I have been working to achieve the second part of the
desired output (i.e. the #is_XXX_type part), and that's my
priority, but suggestions on the first part would be welcome.
DESIRED OUTPUT
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B"
/>
<rdfs:subClassOf
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#T"
/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#in
_category"/>
<owl:allValuesFrom>
==> <owl:Class>
==> <owl:oneOf rdf:parseType="Collection">
==> <rdf:Description
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#Bo"/>
==> </owl:oneOf>
==> </owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is
_XXX_type"/>
<owl:allValuesFrom>
==> <rdfs:Datatype>
==> <owl:oneOf>
==> <rdf:Description>
==> <rdf:type
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
==> <rdf:first
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</rdf:f
irst>
==> <rdf:rest
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
==> </rdf:Description>
==> </owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
MY CODE (note: the new class is derived from an existing
individual)
OntClass newClass =
model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type =
model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXX
s_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Restriction restriction =
model2.createAllValuesFromRestriction(null, is_ XXX_type,
XSD.xboolean);
newClass.addSuperClass(restriction);
<owl:Class
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#B7">
<rdfs:subClassOf>
<owl:Restriction>
<owl:allValuesFrom
rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
<owl:onProperty>
<owl:DatatypeProperty
rdf:about="http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XX
X_type"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Thank you in advance for the advice.
Jos Lehmann
Knowledge Management
Bauhaus Luftfahrt e.V.
GERMANY
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Dave Reynolds
2016-11-10 10:34:42 UTC
Permalink
Hi,
Post by Jos Lehmann
Hi Dave & Lorenzo
thank you very much for your replies. I am still struggling with the code of the case with a singleton with "true" (CASE B below).
As in my code below, I (think I) can create the list with "true" as well an anonymous datatype. But then I can't link them by OWL.oneOf. In the code I am stalling from the lines marked ==>.
My intention would have been to define a link before the anonymous datatype and replace " OntClass.class " with " link " in the datatype definition. But that's not working.
CASE A
Post by Dave Reynolds
Post by Jos Lehmann
- in_category property should range over a singleton (Collection)
containing only #Bo,
You need to create an enumerated class (oneOf) containing #Bo (see
OntModel#createEnumeratedClass) and pass that class to the
allValuesFrom restriction.
CASE B
Post by Dave Reynolds
Post by Jos Lehmann
- is_XXX_type should range over a singleton containing only the
Boolean value "true"
That's OWL2 which is not supported by Jena's convenience OntAPI. So
you'll need top do this at the RDF level - create an anonymous
instance of rdfs:Datatype, create a RDFList containing boolean true
then link them with an owl:oneOf property, then again pass that to
the allValuesFrom.
CODE
Individual thisInstance = (Individual) instances.next();
OntClass newClass = model2.createClass(thisInstance.toString());
DatatypeProperty is_XXX_type = model2.createDatatypeProperty("http://www._.net/ontologies/2016/XXXs_Ontology.owl#is_XXX_type");
is_XXX_type.setRange(XSD.xboolean);
Literal tV = model2.createTypedLiteral(true);
RDFList list = model2.createList(); /* create a RDFList containing boolean true */
list = list.cons(tV); /* create a RDFList containing boolean true */
OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null); /* create an anonymous instance of rdfs:Datatype */
==> RDFNode link = list.getPropertyResourceValue(OWL.oneOf).as(RDFList.class); /* then link them with an owl:oneOf property */
Not sure I understand what you are trying to do with that link. I think
you just want something like (untested):

test.addProperty(OWL.oneOf, list);

Dave
Jos Lehmann
2016-11-10 13:38:02 UTC
Permalink
Hi Dave
Post by Dave Reynolds
Not sure I understand what you are trying to do with that link.
Yeah... I was just modifying preexisting code.
Post by Dave Reynolds
test.addProperty(OWL.oneOf, list);
That's what I was trying to do & it works.

Thanks, Jos

Continue reading on narkive:
Search results for 'How to create restrictions that range on singleton collections or singleton datatypes' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 2006-10-11 00:02:47 UTC
software
Loading...