tags:

views:

109

answers:

1

Hello,

I am new to Jena. I want to create a new OntModel and need to imports some other ontology to this model.If I write it to file, I expect the file can show something like follow:

  <owl:Ontology rdf:about="">
    <owl:imports rdf:resource="http://test.owl#"/&gt;
  </owl:Ontology>

Right now, I dont know how to import other ontology to the model by jena. Can any one give me some advices?

Thank you

+1  A: 

See jena's Ontology API (which sits over the RDF api) and in particular the imports section.

To make something like you want, try:

String base = "http://www.example.com/ont";
OntModel model = ModelFactory.createOntologyModel();
Ontology ont = model.createOntology(base);
ont.addImport(model.createResource("http://test.owl#"));
model.write(System.out, "RDF/XML-ABBREV", base);

Result:

<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#"&gt;
  <owl:Ontology rdf:about="">
    <owl:imports rdf:resource="http://test.owl#"/&gt;
  </owl:Ontology>
</rdf:RDF>