You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Jos Lehmann <Jo...@bauhaus-luftfahrt.net> on 2016/12/12 11:55:26 UTC

How to create owl:NamedIndividual in Jena?

Hi there

I am trying to copy a number of classes and their individuals from one model (model) to another (model2)

SITUATION

1. I collect all instances of a given class (thisClass) in model from a RDF/XML file (produced in Protege from an OWL/XML initial version of model)

ExtendedIterator instances = thisClass.listInstances();
while (instances.hasNext()) {
Individual thisInstance = (Individual) instances.next();


2. Then I re-create above instances as instances of a copy of thisClass (newClass) in model2

Individual newInstance = model2.createIndividual(thisInstance.toString(), newClass);


3. I save in RDF/XML

File file= new File(Ontology_output_file);
model2.write(new FileOutputStream(file), "RDF/XML");


PROBLEM

In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?

A.
    <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
        <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
    </owl:NamedIndividual>

B.
<liebherr:af rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>





Thank you in advance for the advice,

Jos Lehmann



Knowledge Management

Bauhaus Luftfahrt e.V.

GERMANY


AW: AW: AW: How to create owl:NamedIndividual in Jena?

Posted by Jos Lehmann <Jo...@bauhaus-luftfahrt.net>.
Hi Lorenz

Thank you for your comments.

Yes to both questions at the beginning of your mail. 

Regarding your questions about the code: the reason why I am using Datatype, is that I adapted the code for a similar case, where though the enumeration contains literals (see the last chunk of my code below). 

I got this code by 
Alooking at the statements for both (i) enumeration of literals and (ii) enumeration of individuals from an RFD/XML version of the ontology, in turn converted from an initial OWL/XML version of the ontology 
B. finding initial code on stackoverflow (sorry I can't find back the link right now) and adapting this code.

I believe The output of the code for Literals is a list while for is a collection. 

Hope you make sense of this rather explanation.
 
Thanks, Jos


-----Ursprüngliche Nachricht-----
Von: Lorenz Buehmann [mailto:buehmann@informatik.uni-leipzig.de] 
Gesendet: Dienstag, 13. Dezember 2016 22:56
An: users@jena.apache.org
Betreff: Re: AW: AW: How to create owl:NamedIndividual in Jena?

Well, the point is that you want to create an enumeration (owl:oneOf) of OWL individuals, right? And use this anonymous class aks OWL class expression as the filler of the owl:allValues restriction on a particluar property, right?

According to what I know about OWL and RDF, and I'll try to use TURTLE format here is tomodel the property restriction on the property OPE by

_:x1 rdf:type owl:Restriction .
_:x1 owl:onProperty T(OPE) .
_:x1 owl:allValuesFrom T(CE) .


where CE is


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

and a1,...,an the list of individuals.

One question regarding the code inline:

On 13.12.2016 17:16, Jos Lehmann wrote:
> Hi Lorenz
>
> The general idea of the following code is to take an individual of class "type" from an input ontology and transform it into a class in the output ontology. in_category properties that the original individual had with some other individuals, should be conserved in the output ontology as in_category properties between the new class and singletons of those instances (instances which btw should have been copied from input to output in a preceding part of the code). The "else" around halfway in the following code (search for FROM HERE  and TO HERE) contains the calls that output II. in my previous email.
>
> Hope this isn't more confusing than helpful...
>
> Thanks, Jos
>
> CODE
>
>
> /*LIST INSTANCES OF CLASS "TYPE" IN INPUT ONTOLOGY*/
>
> 	if 
> (thisClass.toString().equals("http://www.XXX.net/ontologies/2016/Ls_On
> tology.owl#type")) {
>
> 	      ExtendedIterator instances = thisClass.listInstances();
> 	      
> 	      while (instances.hasNext()) {
>
> 	        Individual thisInstance = (Individual) instances.next();
> 	        ExtendedIterator properties = thisInstance.listProperties();
> 	        OntClass newClass = model2.createClass(thisInstance.toString());
> 	        DatatypeProperty is_l_type = model2.createDatatypeProperty("http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#is_l_type");
> 	        is_l_type.setRange(XSD.xboolean);
> 	        
> /*LIST INSTANCE PROPERTIES IN INPUT ONTOLOGY AND CREATE CORRESPONDING 
> PROPERTIES IN OUTPUT ONTOLOGY WITH SUBTYPE ASSERTION*/
> 	        
> 	        while (properties.hasNext())  {
> 	        	Statement thisProperty = (Statement) properties.next();
> 		        
> 		        if ((thisProperty.getPredicate().toString().contains("in_category"))) {		        	
> 		        	RDFList list = model2.createList();
> 		     
>    	if (thisProperty.getObject().toString().contains("R")){
> 		        		newClass.addSuperClass((Resource) thisProperty.getObject());
> 		        	}
> 		        	
> FROM HERE		        	else {
> 		        		list = list.cons(thisProperty.getObject());
> 		        		RDFNode head = list.getHead();
> 		        		RDFNode tail = list.getTail();
> 		        		OntClass test = model2.createOntResource(OntClass.class, 
> RDFS.Datatype,null);
That line is not clear to me. Why do you choose rdfs:Datatype here?
> 		        		test.addProperty(OWL.oneOf, list);
> 		        		Restriction restriction = model2.createAllValuesFromRestriction(null, thisProperty.getPredicate(), test);
> TO HERE              		newClass.addSuperClass(restriction);
> 		        	}
> 		        }
> 		        
> 		        if ((thisProperty.getPredicate().toString().contains("type"))) {
> //		        	System.out.println("SKIPPED TYPE");
> 		        }
> 		        
> 		        else {
> 		        }
> 	        }
> 	        
> /*CREATE PROPERTY RESTRICTIONS IN OUTPUT ONTOLOGY BETWEEN NEWLY 
> CREATED CLASSES AND INDIVIDUALS OF SOME SPECIFIC CLASSES*/
> 	        
> 	        Literal tV = model2.createTypedLiteral(true);
> 	        RDFList list = model2.createList();
> 	        list = list.cons(tV);
> 	        RDFNode head = list.getHead();
> 	        RDFNode tail = list.getTail();
> 	        OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null);
> 	        test.addProperty(OWL.oneOf, list);
>   	        Restriction restriction = model2.createAllValuesFromRestriction(null, is_l_type, test);
> 	        newClass.addSuperClass(restriction);
> 	        
> //	        System.out.println(" New property assigned to new class: " + newClass);
> 	        	    	  
> 		   }
> 		      
> 	      }
>
>
> END OF CODE
>
> -----Ursprüngliche Nachricht-----
> Von: Lorenz Buehmann [mailto:buehmann@informatik.uni-leipzig.de]
> Gesendet: Dienstag, 13. Dezember 2016 16:27
> An: users@jena.apache.org
> Betreff: Re: AW: How to create owl:NamedIndividual in Jena?
>
>
>
>
> On 13.12.2016 13:42, Jos Lehmann wrote:
>> Hi Martynas & Dave, thank for your replies. 
>>
>> I have tried the newInstance.addProperty(RDF.type, OWL2.NamedIndividual) but it does not seem to help with the problem I was trying to solve. 
>>
>> The problem is: having a singleton as range of a property. Maybe you have alternative solutions or at least  explanations of why my RDF/XML serialization (II. below) is not visualized correctly in Protege.
>>
>> I have two versions of the same ontology: I. OWL/XML and II. RDF/XML.
>>
>> In the OWL/XML version, I express the range of the property 
>> in_category for B, as only the singleton containing Bo, i.e.: B in_category only {Bo} This is visualized correctly in Protege.
>>
>> The RDF/XML is not visualized correctly, i.e., the RDF serialization 
>> below, which seems to contain the correct statement, when visualized 
>> in Protégé cannot find the (now owl:Named) Individual #Bo anywhere, 
>> so the curly brackets are left empty, i.e.: B in_category only {}
>>
>> Is there a way of changing II., or the file of which II. is part. to make sure that Bo appears in the curly brackets when II. Is visualized in Protégé?
>>
>> Thanks, Jos
>>
>> I.
>>    
>> OWL/XML serialization
>>
>> <SubClassOf>
>>         <Class IRI="#B"/>
>>         <ObjectAllValuesFrom>
>>             <ObjectProperty IRI="#in_category"/>
>>             <ObjectOneOf>
>>                 <NamedIndividual IRI="#Bo"/>
>>             </ObjectOneOf>
>>         </ObjectAllValuesFrom>
>>     </SubClassOf>
>>
>> II.
>>
>> RDF/XML serialization
>>
>> <owl:Class
>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#B">
>> <rdfs:subClassOf>
>>       <owl:Restriction>
>>         <owl:allValuesFrom>
>>           <rdfs:Datatype>
>>             <owl:oneOf rdf:parseType="Collection">
>>               <owl:NamedIndividual rdf:about="http://www. XXX.net/ontologies/2016/LIEBHERRs_Ontology.owl#Bo"/>
>>             </owl:oneOf>
>>           </rdfs:Datatype>
>>         </owl:allValuesFrom>
>>         <owl:onProperty rdf:resource="http://www.XXX.net/ontologies/2016/PS_Ontology.owl#in_category"/>
>>       </owl:Restriction>
>>     </rdfs:subClassOf>
> How did you generate this? The rdfs:Datatype tag is confusing and wrong.
> It has to result in an owl:oneOf for individuals, i.e. an enumeration of of individuals.
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
>> Gesendet: Montag, 12. Dezember 2016 14:08
>> An: users@jena.apache.org
>> Betreff: Re: How to create owl:NamedIndividual in Jena?
>>
>>
>> On 12/12/16 11:55, Jos Lehmann wrote:
>>> Hi there
>>>
>>> I am trying to copy a number of classes and their individuals from 
>>> one model (model) to another (model2)
>>>
>>> SITUATION
>>>
>>> 1. I collect all instances of a given class (thisClass) in model 
>>> from a RDF/XML file (produced in Protege from an OWL/XML initial 
>>> version of
>>> model)
>>>
>>> ExtendedIterator instances = thisClass.listInstances(); while
>>> (instances.hasNext()) { Individual thisInstance = (Individual) 
>>> instances.next();
>>>
>>>
>>> 2. Then I re-create above instances as instances of a copy of 
>>> thisClass (newClass) in model2
>>>
>>> Individual newInstance =
>>> model2.createIndividual(thisInstance.toString(), newClass);
>>>
>>>
>>> 3. I save in RDF/XML
>>>
>>> File file= new File(Ontology_output_file); model2.write(new 
>>> FileOutputStream(file), "RDF/XML");
>>>
>>>
>>> PROBLEM
>>>
>>> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>>>
>>> A.
>>>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>>>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>>>     </owl:NamedIndividual>
>>>
>>> B.
>>> <liebherr:af
>>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/
>>> >
>> There are a couple of issues here.
>>
>> First, as Martynas says, Jena doesn't support OWL 2 and has no convenience support for named individual. So you would have to explicitly include a statement that your copied resource is a NamedIndividual, e.g.
>>
>>     newInstance.addProperty(RDF.type, OWL2.NamedIndividual)
>>
>> If you only care about the semantics - that the resulting model has the right statements in - then that's enough. However, if you care about the serialization then you may need to tweak the configuration of the RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
>> This may or may not be possible. My advice would be to not care about the particular abbreviation syntax, just worry about having the right statements.
>>
>> Dave
>>
>


Re: AW: AW: How to create owl:NamedIndividual in Jena?

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
Well, the point is that you want to create an enumeration (owl:oneOf) of
OWL individuals, right? And use this anonymous class aks OWL class
expression as the filler of the owl:allValues restriction on a
particluar property, right? According to what I know about OWL and RDF,
and I'll try to use TURTLE format here is tomodel the property
restriction on the property OPE by

_:x1 rdf:type owl:Restriction .
_:x1 owl:onProperty T(OPE) .
_:x1 owl:allValuesFrom T(CE) .


where CE is


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

and a1,...,an the list of individuals.

One question regarding the code inline:

On 13.12.2016 17:16, Jos Lehmann wrote:
> Hi Lorenz
>
> The general idea of the following code is to take an individual of class "type" from an input ontology and transform it into a class in the output ontology. in_category properties that the original individual had with some other individuals, should be conserved in the output ontology as in_category properties between the new class and singletons of those instances (instances which btw should have been copied from input to output in a preceding part of the code). The "else" around halfway in the following code (search for FROM HERE  and TO HERE) contains the calls that output II. in my previous email.
>
> Hope this isn't more confusing than helpful...
>
> Thanks, Jos
>
> CODE
>
>
> /*LIST INSTANCES OF CLASS "TYPE" IN INPUT ONTOLOGY*/
>
> 	if (thisClass.toString().equals("http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#type")) {
>
> 	      ExtendedIterator instances = thisClass.listInstances();
> 	      
> 	      while (instances.hasNext()) {
>
> 	        Individual thisInstance = (Individual) instances.next();
> 	        ExtendedIterator properties = thisInstance.listProperties();
> 	        OntClass newClass = model2.createClass(thisInstance.toString());
> 	        DatatypeProperty is_l_type = model2.createDatatypeProperty("http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#is_l_type");
> 	        is_l_type.setRange(XSD.xboolean);
> 	        
> /*LIST INSTANCE PROPERTIES IN INPUT ONTOLOGY AND CREATE CORRESPONDING PROPERTIES IN OUTPUT ONTOLOGY WITH SUBTYPE ASSERTION*/
> 	        
> 	        while (properties.hasNext())  {
> 	        	Statement thisProperty = (Statement) properties.next();
> 		        
> 		        if ((thisProperty.getPredicate().toString().contains("in_category"))) {		        	
> 		        	RDFList list = model2.createList();
> 		     
>    	if (thisProperty.getObject().toString().contains("R")){
> 		        		newClass.addSuperClass((Resource) thisProperty.getObject());
> 		        	}
> 		        	
> FROM HERE		        	else {
> 		        		list = list.cons(thisProperty.getObject());
> 		        		RDFNode head = list.getHead();
> 		        		RDFNode tail = list.getTail();
> 		        		OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null);
That line is not clear to me. Why do you choose rdfs:Datatype here?
> 		        		test.addProperty(OWL.oneOf, list);
> 		        		Restriction restriction = model2.createAllValuesFromRestriction(null, thisProperty.getPredicate(), test);
> TO HERE              		newClass.addSuperClass(restriction);
> 		        	}
> 		        }
> 		        
> 		        if ((thisProperty.getPredicate().toString().contains("type"))) {
> //		        	System.out.println("SKIPPED TYPE");
> 		        }
> 		        
> 		        else {
> 		        }
> 	        }
> 	        
> /*CREATE PROPERTY RESTRICTIONS IN OUTPUT ONTOLOGY BETWEEN NEWLY CREATED CLASSES AND INDIVIDUALS OF SOME SPECIFIC CLASSES*/
> 	        
> 	        Literal tV = model2.createTypedLiteral(true);
> 	        RDFList list = model2.createList();
> 	        list = list.cons(tV);
> 	        RDFNode head = list.getHead();
> 	        RDFNode tail = list.getTail();
> 	        OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null);
> 	        test.addProperty(OWL.oneOf, list);
>   	        Restriction restriction = model2.createAllValuesFromRestriction(null, is_l_type, test);
> 	        newClass.addSuperClass(restriction);
> 	        
> //	        System.out.println(" New property assigned to new class: " + newClass);
> 	        	    	  
> 		   }
> 		      
> 	      }
>
>
> END OF CODE
>
> -----Ursprngliche Nachricht-----
> Von: Lorenz Buehmann [mailto:buehmann@informatik.uni-leipzig.de] 
> Gesendet: Dienstag, 13. Dezember 2016 16:27
> An: users@jena.apache.org
> Betreff: Re: AW: How to create owl:NamedIndividual in Jena?
>
>
>
>
> On 13.12.2016 13:42, Jos Lehmann wrote:
>> Hi Martynas & Dave, thank for your replies. 
>>
>> I have tried the newInstance.addProperty(RDF.type, OWL2.NamedIndividual) but it does not seem to help with the problem I was trying to solve. 
>>
>> The problem is: having a singleton as range of a property. Maybe you have alternative solutions or at least  explanations of why my RDF/XML serialization (II. below) is not visualized correctly in Protege.
>>
>> I have two versions of the same ontology: I. OWL/XML and II. RDF/XML.
>>
>> In the OWL/XML version, I express the range of the property 
>> in_category for B, as only the singleton containing Bo, i.e.: B in_category only {Bo} This is visualized correctly in Protege.
>>
>> The RDF/XML is not visualized correctly, i.e., the RDF serialization 
>> below, which seems to contain the correct statement, when visualized 
>> in Protg cannot find the (now owl:Named) Individual #Bo anywhere, so 
>> the curly brackets are left empty, i.e.: B in_category only {}
>>
>> Is there a way of changing II., or the file of which II. is part. to make sure that Bo appears in the curly brackets when II. Is visualized in Protg?
>>
>> Thanks, Jos
>>
>> I.
>>    
>> OWL/XML serialization
>>
>> <SubClassOf>
>>         <Class IRI="#B"/>
>>         <ObjectAllValuesFrom>
>>             <ObjectProperty IRI="#in_category"/>
>>             <ObjectOneOf>
>>                 <NamedIndividual IRI="#Bo"/>
>>             </ObjectOneOf>
>>         </ObjectAllValuesFrom>
>>     </SubClassOf>
>>
>> II.
>>
>> RDF/XML serialization
>>
>> <owl:Class 
>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#B">
>> <rdfs:subClassOf>
>>       <owl:Restriction>
>>         <owl:allValuesFrom>
>>           <rdfs:Datatype>
>>             <owl:oneOf rdf:parseType="Collection">
>>               <owl:NamedIndividual rdf:about="http://www. XXX.net/ontologies/2016/LIEBHERRs_Ontology.owl#Bo"/>
>>             </owl:oneOf>
>>           </rdfs:Datatype>
>>         </owl:allValuesFrom>
>>         <owl:onProperty rdf:resource="http://www.XXX.net/ontologies/2016/PS_Ontology.owl#in_category"/>
>>       </owl:Restriction>
>>     </rdfs:subClassOf>
> How did you generate this? The rdfs:Datatype tag is confusing and wrong.
> It has to result in an owl:oneOf for individuals, i.e. an enumeration of of individuals.
>>
>>
>>
>> -----Ursprngliche Nachricht-----
>> Von: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
>> Gesendet: Montag, 12. Dezember 2016 14:08
>> An: users@jena.apache.org
>> Betreff: Re: How to create owl:NamedIndividual in Jena?
>>
>>
>> On 12/12/16 11:55, Jos Lehmann wrote:
>>> Hi there
>>>
>>> I am trying to copy a number of classes and their individuals from 
>>> one model (model) to another (model2)
>>>
>>> SITUATION
>>>
>>> 1. I collect all instances of a given class (thisClass) in model from 
>>> a RDF/XML file (produced in Protege from an OWL/XML initial version 
>>> of
>>> model)
>>>
>>> ExtendedIterator instances = thisClass.listInstances(); while
>>> (instances.hasNext()) { Individual thisInstance = (Individual) 
>>> instances.next();
>>>
>>>
>>> 2. Then I re-create above instances as instances of a copy of 
>>> thisClass (newClass) in model2
>>>
>>> Individual newInstance =
>>> model2.createIndividual(thisInstance.toString(), newClass);
>>>
>>>
>>> 3. I save in RDF/XML
>>>
>>> File file= new File(Ontology_output_file); model2.write(new 
>>> FileOutputStream(file), "RDF/XML");
>>>
>>>
>>> PROBLEM
>>>
>>> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>>>
>>> A.
>>>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>>>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>>>     </owl:NamedIndividual>
>>>
>>> B.
>>> <liebherr:af
>>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>
>> There are a couple of issues here.
>>
>> First, as Martynas says, Jena doesn't support OWL 2 and has no convenience support for named individual. So you would have to explicitly include a statement that your copied resource is a NamedIndividual, e.g.
>>
>>     newInstance.addProperty(RDF.type, OWL2.NamedIndividual)
>>
>> If you only care about the semantics - that the resulting model has the right statements in - then that's enough. However, if you care about the serialization then you may need to tweak the configuration of the RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
>> This may or may not be possible. My advice would be to not care about the particular abbreviation syntax, just worry about having the right statements.
>>
>> Dave
>>
>


AW: AW: How to create owl:NamedIndividual in Jena?

Posted by Jos Lehmann <Jo...@bauhaus-luftfahrt.net>.
Hi Lorenz

The general idea of the following code is to take an individual of class "type" from an input ontology and transform it into a class in the output ontology. in_category properties that the original individual had with some other individuals, should be conserved in the output ontology as in_category properties between the new class and singletons of those instances (instances which btw should have been copied from input to output in a preceding part of the code). The "else" around halfway in the following code (search for FROM HERE  and TO HERE) contains the calls that output II. in my previous email.

Hope this isn't more confusing than helpful...

Thanks, Jos

CODE


/*LIST INSTANCES OF CLASS "TYPE" IN INPUT ONTOLOGY*/

	if (thisClass.toString().equals("http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#type")) {

	      ExtendedIterator instances = thisClass.listInstances();
	      
	      while (instances.hasNext()) {

	        Individual thisInstance = (Individual) instances.next();
	        ExtendedIterator properties = thisInstance.listProperties();
	        OntClass newClass = model2.createClass(thisInstance.toString());
	        DatatypeProperty is_l_type = model2.createDatatypeProperty("http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#is_l_type");
	        is_l_type.setRange(XSD.xboolean);
	        
/*LIST INSTANCE PROPERTIES IN INPUT ONTOLOGY AND CREATE CORRESPONDING PROPERTIES IN OUTPUT ONTOLOGY WITH SUBTYPE ASSERTION*/
	        
	        while (properties.hasNext())  {
	        	Statement thisProperty = (Statement) properties.next();
		        
		        if ((thisProperty.getPredicate().toString().contains("in_category"))) {		        	
		        	RDFList list = model2.createList();
		     
   	if (thisProperty.getObject().toString().contains("R")){
		        		newClass.addSuperClass((Resource) thisProperty.getObject());
		        	}
		        	
FROM HERE		        	else {
		        		list = list.cons(thisProperty.getObject());
		        		RDFNode head = list.getHead();
		        		RDFNode tail = list.getTail();
		        		OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null);
		        		test.addProperty(OWL.oneOf, list);
		        		Restriction restriction = model2.createAllValuesFromRestriction(null, thisProperty.getPredicate(), test);
TO HERE              		newClass.addSuperClass(restriction);
		        	}
		        }
		        
		        if ((thisProperty.getPredicate().toString().contains("type"))) {
//		        	System.out.println("SKIPPED TYPE");
		        }
		        
		        else {
		        }
	        }
	        
/*CREATE PROPERTY RESTRICTIONS IN OUTPUT ONTOLOGY BETWEEN NEWLY CREATED CLASSES AND INDIVIDUALS OF SOME SPECIFIC CLASSES*/
	        
	        Literal tV = model2.createTypedLiteral(true);
	        RDFList list = model2.createList();
	        list = list.cons(tV);
	        RDFNode head = list.getHead();
	        RDFNode tail = list.getTail();
	        OntClass test = model2.createOntResource(OntClass.class, RDFS.Datatype,null);
	        test.addProperty(OWL.oneOf, list);
  	        Restriction restriction = model2.createAllValuesFromRestriction(null, is_l_type, test);
	        newClass.addSuperClass(restriction);
	        
//	        System.out.println(" New property assigned to new class: " + newClass);
	        	    	  
		   }
		      
	      }


END OF CODE

-----Ursprüngliche Nachricht-----
Von: Lorenz Buehmann [mailto:buehmann@informatik.uni-leipzig.de] 
Gesendet: Dienstag, 13. Dezember 2016 16:27
An: users@jena.apache.org
Betreff: Re: AW: How to create owl:NamedIndividual in Jena?




On 13.12.2016 13:42, Jos Lehmann wrote:
> Hi Martynas & Dave, thank for your replies. 
>
> I have tried the newInstance.addProperty(RDF.type, OWL2.NamedIndividual) but it does not seem to help with the problem I was trying to solve. 
>
> The problem is: having a singleton as range of a property. Maybe you have alternative solutions or at least  explanations of why my RDF/XML serialization (II. below) is not visualized correctly in Protege.
>
> I have two versions of the same ontology: I. OWL/XML and II. RDF/XML.
>
> In the OWL/XML version, I express the range of the property 
> in_category for B, as only the singleton containing Bo, i.e.: B in_category only {Bo} This is visualized correctly in Protege.
>
> The RDF/XML is not visualized correctly, i.e., the RDF serialization 
> below, which seems to contain the correct statement, when visualized 
> in Protégé cannot find the (now owl:Named) Individual #Bo anywhere, so 
> the curly brackets are left empty, i.e.: B in_category only {}
>
> Is there a way of changing II., or the file of which II. is part. to make sure that Bo appears in the curly brackets when II. Is visualized in Protégé?
>
> Thanks, Jos
>
> I.
>    
> OWL/XML serialization
>
> <SubClassOf>
>         <Class IRI="#B"/>
>         <ObjectAllValuesFrom>
>             <ObjectProperty IRI="#in_category"/>
>             <ObjectOneOf>
>                 <NamedIndividual IRI="#Bo"/>
>             </ObjectOneOf>
>         </ObjectAllValuesFrom>
>     </SubClassOf>
>
> II.
>
> RDF/XML serialization
>
> <owl:Class 
> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#B">
> <rdfs:subClassOf>
>       <owl:Restriction>
>         <owl:allValuesFrom>
>           <rdfs:Datatype>
>             <owl:oneOf rdf:parseType="Collection">
>               <owl:NamedIndividual rdf:about="http://www. XXX.net/ontologies/2016/LIEBHERRs_Ontology.owl#Bo"/>
>             </owl:oneOf>
>           </rdfs:Datatype>
>         </owl:allValuesFrom>
>         <owl:onProperty rdf:resource="http://www.XXX.net/ontologies/2016/PS_Ontology.owl#in_category"/>
>       </owl:Restriction>
>     </rdfs:subClassOf>
How did you generate this? The rdfs:Datatype tag is confusing and wrong.
It has to result in an owl:oneOf for individuals, i.e. an enumeration of of individuals.
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> Gesendet: Montag, 12. Dezember 2016 14:08
> An: users@jena.apache.org
> Betreff: Re: How to create owl:NamedIndividual in Jena?
>
>
> On 12/12/16 11:55, Jos Lehmann wrote:
>> Hi there
>>
>> I am trying to copy a number of classes and their individuals from 
>> one model (model) to another (model2)
>>
>> SITUATION
>>
>> 1. I collect all instances of a given class (thisClass) in model from 
>> a RDF/XML file (produced in Protege from an OWL/XML initial version 
>> of
>> model)
>>
>> ExtendedIterator instances = thisClass.listInstances(); while
>> (instances.hasNext()) { Individual thisInstance = (Individual) 
>> instances.next();
>>
>>
>> 2. Then I re-create above instances as instances of a copy of 
>> thisClass (newClass) in model2
>>
>> Individual newInstance =
>> model2.createIndividual(thisInstance.toString(), newClass);
>>
>>
>> 3. I save in RDF/XML
>>
>> File file= new File(Ontology_output_file); model2.write(new 
>> FileOutputStream(file), "RDF/XML");
>>
>>
>> PROBLEM
>>
>> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>>
>> A.
>>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>>     </owl:NamedIndividual>
>>
>> B.
>> <liebherr:af
>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>
> There are a couple of issues here.
>
> First, as Martynas says, Jena doesn't support OWL 2 and has no convenience support for named individual. So you would have to explicitly include a statement that your copied resource is a NamedIndividual, e.g.
>
>     newInstance.addProperty(RDF.type, OWL2.NamedIndividual)
>
> If you only care about the semantics - that the resulting model has the right statements in - then that's enough. However, if you care about the serialization then you may need to tweak the configuration of the RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
> This may or may not be possible. My advice would be to not care about the particular abbreviation syntax, just worry about having the right statements.
>
> Dave
>


Re: AW: How to create owl:NamedIndividual in Jena?

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.

On 13.12.2016 13:42, Jos Lehmann wrote:
> Hi Martynas & Dave, thank for your replies. 
>
> I have tried the newInstance.addProperty(RDF.type, OWL2.NamedIndividual) but it does not seem to help with the problem I was trying to solve. 
>
> The problem is: having a singleton as range of a property. Maybe you have alternative solutions or at least  explanations of why my RDF/XML serialization (II. below) is not visualized correctly in Protege.
>
> I have two versions of the same ontology: I. OWL/XML and II. RDF/XML.
>
> In the OWL/XML version, I express the range of the property in_category for B, as only the singleton containing Bo, i.e.: B in_category only {Bo}
> This is visualized correctly in Protege. 
>
> The RDF/XML is not visualized correctly, i.e., the RDF serialization below, which seems to contain the correct statement, when visualized in Protg cannot find the (now owl:Named) Individual #Bo anywhere, so the curly brackets are left empty, i.e.: B in_category only {}
>
> Is there a way of changing II., or the file of which II. is part. to make sure that Bo appears in the curly brackets when II. Is visualized in Protg?
>
> Thanks, Jos 
>
> I.
>    
> OWL/XML serialization
>
> <SubClassOf>
>         <Class IRI="#B"/>
>         <ObjectAllValuesFrom>
>             <ObjectProperty IRI="#in_category"/>
>             <ObjectOneOf>
>                 <NamedIndividual IRI="#Bo"/>
>             </ObjectOneOf>
>         </ObjectAllValuesFrom>
>     </SubClassOf>
>
> II.
>
> RDF/XML serialization
>
> <owl:Class rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#B">
> <rdfs:subClassOf>
>       <owl:Restriction>
>         <owl:allValuesFrom>
>           <rdfs:Datatype>
>             <owl:oneOf rdf:parseType="Collection">
>               <owl:NamedIndividual rdf:about="http://www. XXX.net/ontologies/2016/LIEBHERRs_Ontology.owl#Bo"/>
>             </owl:oneOf>
>           </rdfs:Datatype>
>         </owl:allValuesFrom>
>         <owl:onProperty rdf:resource="http://www.XXX.net/ontologies/2016/PS_Ontology.owl#in_category"/>
>       </owl:Restriction>
>     </rdfs:subClassOf>
How did you generate this? The rdfs:Datatype tag is confusing and wrong.
It has to result in an owl:oneOf for individuals, i.e. an enumeration of
of individuals.
>
>
>
>
> -----Ursprngliche Nachricht-----
> Von: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
> Gesendet: Montag, 12. Dezember 2016 14:08
> An: users@jena.apache.org
> Betreff: Re: How to create owl:NamedIndividual in Jena?
>
>
> On 12/12/16 11:55, Jos Lehmann wrote:
>> Hi there
>>
>> I am trying to copy a number of classes and their individuals from one 
>> model (model) to another (model2)
>>
>> SITUATION
>>
>> 1. I collect all instances of a given class (thisClass) in model from 
>> a RDF/XML file (produced in Protege from an OWL/XML initial version of 
>> model)
>>
>> ExtendedIterator instances = thisClass.listInstances(); while 
>> (instances.hasNext()) { Individual thisInstance = (Individual) 
>> instances.next();
>>
>>
>> 2. Then I re-create above instances as instances of a copy of 
>> thisClass (newClass) in model2
>>
>> Individual newInstance = 
>> model2.createIndividual(thisInstance.toString(), newClass);
>>
>>
>> 3. I save in RDF/XML
>>
>> File file= new File(Ontology_output_file); model2.write(new 
>> FileOutputStream(file), "RDF/XML");
>>
>>
>> PROBLEM
>>
>> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>>
>> A.
>>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>>     </owl:NamedIndividual>
>>
>> B.
>> <liebherr:af 
>> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>
> There are a couple of issues here.
>
> First, as Martynas says, Jena doesn't support OWL 2 and has no convenience support for named individual. So you would have to explicitly include a statement that your copied resource is a NamedIndividual, e.g.
>
>     newInstance.addProperty(RDF.type, OWL2.NamedIndividual)
>
> If you only care about the semantics - that the resulting model has the right statements in - then that's enough. However, if you care about the serialization then you may need to tweak the configuration of the RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
> This may or may not be possible. My advice would be to not care about the particular abbreviation syntax, just worry about having the right statements.
>
> Dave
>


AW: How to create owl:NamedIndividual in Jena?

Posted by Jos Lehmann <Jo...@bauhaus-luftfahrt.net>.
Hi Martynas & Dave, thank for your replies. 

I have tried the newInstance.addProperty(RDF.type, OWL2.NamedIndividual) but it does not seem to help with the problem I was trying to solve. 

The problem is: having a singleton as range of a property. Maybe you have alternative solutions or at least  explanations of why my RDF/XML serialization (II. below) is not visualized correctly in Protege.

I have two versions of the same ontology: I. OWL/XML and II. RDF/XML.

In the OWL/XML version, I express the range of the property in_category for B, as only the singleton containing Bo, i.e.: B in_category only {Bo}
This is visualized correctly in Protege. 

The RDF/XML is not visualized correctly, i.e., the RDF serialization below, which seems to contain the correct statement, when visualized in Protégé cannot find the (now owl:Named) Individual #Bo anywhere, so the curly brackets are left empty, i.e.: B in_category only {}

Is there a way of changing II., or the file of which II. is part. to make sure that Bo appears in the curly brackets when II. Is visualized in Protégé?

Thanks, Jos 

I.
   
OWL/XML serialization

<SubClassOf>
        <Class IRI="#B"/>
        <ObjectAllValuesFrom>
            <ObjectProperty IRI="#in_category"/>
            <ObjectOneOf>
                <NamedIndividual IRI="#Bo"/>
            </ObjectOneOf>
        </ObjectAllValuesFrom>
    </SubClassOf>

II.

RDF/XML serialization

<owl:Class rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#B">
<rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom>
          <rdfs:Datatype>
            <owl:oneOf rdf:parseType="Collection">
              <owl:NamedIndividual rdf:about="http://www. XXX.net/ontologies/2016/LIEBHERRs_Ontology.owl#Bo"/>
            </owl:oneOf>
          </rdfs:Datatype>
        </owl:allValuesFrom>
        <owl:onProperty rdf:resource="http://www.XXX.net/ontologies/2016/PS_Ontology.owl#in_category"/>
      </owl:Restriction>
    </rdfs:subClassOf>




-----Ursprüngliche Nachricht-----
Von: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
Gesendet: Montag, 12. Dezember 2016 14:08
An: users@jena.apache.org
Betreff: Re: How to create owl:NamedIndividual in Jena?


On 12/12/16 11:55, Jos Lehmann wrote:
> Hi there
>
> I am trying to copy a number of classes and their individuals from one 
> model (model) to another (model2)
>
> SITUATION
>
> 1. I collect all instances of a given class (thisClass) in model from 
> a RDF/XML file (produced in Protege from an OWL/XML initial version of 
> model)
>
> ExtendedIterator instances = thisClass.listInstances(); while 
> (instances.hasNext()) { Individual thisInstance = (Individual) 
> instances.next();
>
>
> 2. Then I re-create above instances as instances of a copy of 
> thisClass (newClass) in model2
>
> Individual newInstance = 
> model2.createIndividual(thisInstance.toString(), newClass);
>
>
> 3. I save in RDF/XML
>
> File file= new File(Ontology_output_file); model2.write(new 
> FileOutputStream(file), "RDF/XML");
>
>
> PROBLEM
>
> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>
> A.
>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>     </owl:NamedIndividual>
>
> B.
> <liebherr:af 
> rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>

There are a couple of issues here.

First, as Martynas says, Jena doesn't support OWL 2 and has no convenience support for named individual. So you would have to explicitly include a statement that your copied resource is a NamedIndividual, e.g.

    newInstance.addProperty(RDF.type, OWL2.NamedIndividual)

If you only care about the semantics - that the resulting model has the right statements in - then that's enough. However, if you care about the serialization then you may need to tweak the configuration of the RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
This may or may not be possible. My advice would be to not care about the particular abbreviation syntax, just worry about having the right statements.

Dave

Re: How to create owl:NamedIndividual in Jena?

Posted by Dave Reynolds <da...@gmail.com>.
On 12/12/16 11:55, Jos Lehmann wrote:
> Hi there
>
> I am trying to copy a number of classes and their individuals from one model (model) to another (model2)
>
> SITUATION
>
> 1. I collect all instances of a given class (thisClass) in model from a RDF/XML file (produced in Protege from an OWL/XML initial version of model)
>
> ExtendedIterator instances = thisClass.listInstances();
> while (instances.hasNext()) {
> Individual thisInstance = (Individual) instances.next();
>
>
> 2. Then I re-create above instances as instances of a copy of thisClass (newClass) in model2
>
> Individual newInstance = model2.createIndividual(thisInstance.toString(), newClass);
>
>
> 3. I save in RDF/XML
>
> File file= new File(Ontology_output_file);
> model2.write(new FileOutputStream(file), "RDF/XML");
>
>
> PROBLEM
>
> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>
> A.
>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>     </owl:NamedIndividual>
>
> B.
> <liebherr:af rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>

There are a couple of issues here.

First, as Martynas says, Jena doesn't support OWL 2 and has no 
convenience support for named individual. So you would have to 
explicitly include a statement that your copied resource is a 
NamedIndividual, e.g.

    newInstance.addProperty(RDF.type, OWL2.NamedIndividual)

If you only care about the semantics - that the resulting model has the 
right statements in - then that's enough. However, if you care about the 
serialization then you may need to tweak the configuration of the 
RDF/XML-ABBREV writer to encourage it to come out the way you expect. 
This may or may not be possible. My advice would be to not care about 
the particular abbreviation syntax, just worry about having the right 
statements.

Dave

Re: How to create owl:NamedIndividual in Jena?

Posted by Martynas Jusevičius <ma...@graphity.org>.
owl:NamedIndividual is OWL 2 which Jena does not support.

I think in Jena terms Individual is simply an instance of a class --
and that is what you are getting in B.

On Mon, Dec 12, 2016 at 12:55 PM, Jos Lehmann
<Jo...@bauhaus-luftfahrt.net> wrote:
> Hi there
>
> I am trying to copy a number of classes and their individuals from one model (model) to another (model2)
>
> SITUATION
>
> 1. I collect all instances of a given class (thisClass) in model from a RDF/XML file (produced in Protege from an OWL/XML initial version of model)
>
> ExtendedIterator instances = thisClass.listInstances();
> while (instances.hasNext()) {
> Individual thisInstance = (Individual) instances.next();
>
>
> 2. Then I re-create above instances as instances of a copy of thisClass (newClass) in model2
>
> Individual newInstance = model2.createIndividual(thisInstance.toString(), newClass);
>
>
> 3. I save in RDF/XML
>
> File file= new File(Ontology_output_file);
> model2.write(new FileOutputStream(file), "RDF/XML");
>
>
> PROBLEM
>
> In the input RDF/XML file the original individuals are serialized in A below.  In the output RDF/XML file they are serialized as in B. I think this is creating problems and I would like the output file to also be as in A. below. Is that possible?
>
> A.
>     <owl:NamedIndividual rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu ">
>         <rdf:type rdf:resource="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#af"/>
>     </owl:NamedIndividual>
>
> B.
> <liebherr:af rdf:about="http://www.XXX.net/ontologies/2016/Ls_Ontology.owl#Bubu"/>
>
>
>
>
>
> Thank you in advance for the advice,
>
> Jos Lehmann
>
>
>
> Knowledge Management
>
> Bauhaus Luftfahrt e.V.
>
> GERMANY
>