You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Tim Harsch <ha...@yahoo.com> on 2011/03/03 01:31:01 UTC

write an OWL file

If I have a regular model that was loaded with N-triples, and those N-triples represented an OWL ontology, how could I write it back out such that I would see everything in OWL XML?  

What I did was something similar to:
Model curModel = FileManager.get().loadModel(file);

OntModel asOwl = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
asOwl.add(curModel);
FileWriter fstream = new FileWriter(filePath);

BufferedWriter out = new BufferedWriter(fstream);
grandSchema.write(out);

The resulting XML is expressed in pure RDF/XML:
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="http://example.org/unnamed0">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>

  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/unnamed0#Uncle">
    <owl:equivalentClass rdf:resource="http://example.org/unnamed0#XXX"/>
    <rdfs:subClassOf rdf:resource="http://example.org/unnamed0#Person"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
...

but should look more like the following OWL (created by opening the output file with Top Braid Composer and saving it back out):

  <owl:Class rdf:about="http://example.org/unnamed0#Uncle">
    <owl:equivalentClass>
      <owl:Class rdf:about="http://example.org/unnamed0#XXX"/>
    </owl:equivalentClass>
    <rdfs:subClassOf>
      <owl:Class rdf:about="http://example.org/unnamed0#Person"/>
    </rdfs:subClassOf>
  </owl:Class>



      

Re: write an OWL file

Posted by Ian Dickinson <ia...@epimorphics.com>.
On 03/03/11 00:31, Tim Harsch wrote:
> If I have a regular model that was loaded with N-triples, and those N-triples represented an OWL ontology, how could I write it back out such that I would see everything in OWL XML?
>
> What I did was something similar to:
> Model curModel = FileManager.get().loadModel(file);
>
> OntModel asOwl = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
> asOwl.add(curModel);
> FileWriter fstream = new FileWriter(filePath);
>
> BufferedWriter out = new BufferedWriter(fstream);
> grandSchema.write(out);

grandSchema.write( out, "RDF/XML-ABBREV" ), per [1]

Ian

[1] 
http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.OutputStream,%20java.lang.String)

-- 
____________________________________________________________
Ian Dickinson                   Epimorphics Ltd, Bristol, UK
mailto:ian@epimorphics.com        http://www.epimorphics.com
cell: +44-7786-850536              landline: +44-1275-399069
------------------------------------------------------------
Epimorphics Ltd.  is a limited company registered in England
(no. 7016688). Registered address: Court Lodge, 105 High St,
               Portishead, Bristol BS20 6PT, UK