2016-03-24 6 views
2

Ich versuche, zwei Ontologien zusammenzuführen, um eine neue einzelne Ontologie zu erstellen. Wie soll ich das IRI der neuen Ontologie spezifizieren? Sollte es der Pfad zu der neuen Datei oder einer URL sein?Angeben von Ontologie-IRI in Java

Hier ist mein Code:

void createRepOntology(OWLOntology O1, OWLOntology O2) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException 
{ 
    OWLOntologyManager man = OWLManager.createOWLOntologyManager(); 
    OWLDataFactory fac = man.getOWLDataFactory(); 
    OWLOntology ont; 
    FileWriter writer = new FileWriter(new File(System.getProperty("user.dir") + "/repOnt.owl")); 
    String url = "file://" + System.getProperty("user.dir") + "/repOnt.owl"; 

    IRI iri = IRI.create(url); 

    ont = man.createOntology(iri); 

      . . . 

    OWLClass c = fac.getOWLClass(IRI.create(url1)); 
    OWLAxiom ax = fac.getOWLDeclarationAxiom(c); 
    man.addAxiom(ont, ax); 
    man.saveOntology(ont); 

} 

Die Ontologie beginnt wie folgt erstellt:

<?xml version="1.0"?> 
<rdf:RDF xmlns="file:///home/repOnt.owl#" 
xml:base="file:///home/repOnt.owl" 
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
xmlns:owl="http://www.w3.org/2002/07/owl#" 
xmlns:productCatalog="http://www.semanticweb.org/ontologies/2015/11/productCatalog#" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:ElectronicDevices="http://www.semanticweb.org/ontologies/2015/9/ElectronicDevices#" 
xmlns:Acer_Backpack_15="http://www.semanticweb.org/ontologies/2015/11/productCatalog#Acer_Backpack_15.6&#39;&#39;"> 
<owl:Ontology rdf:about="file:///home/repOnt.owl"/> 

Der Wert xmlns ist der Pfad zur Datei. Aber wenn ich eine URL wie die IRI der neuen Ontologie angeben: http://www.semanticweb.org/ontologies/2015/11/productCatalog#, gibt es die folgende Ausnahme:

Exception in thread "main" org.semanticweb.owlapi.model.OWLOntologyStorageException: java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true) 
at org.semanticweb.owlapi.util.AbstractOWLOntologyStorer.storeOntology(AbstractOWLOntologyStorer.java:147) 
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:841) 
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:827) 
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:821) 
at ontomap.RepOnt.createRepOntology(RepOnt.java:112) 
at ontomap.RepOnt.run(RepOnt.java:85) 
at ontomap.RepOnt.main(RepOnt.java:49) 
Caused by: java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1074) 
at org.semanticweb.owlapi.util.AbstractOWLOntologyStorer.storeOntology(AbstractOWLOntologyStorer.java:105) 
... 6 more 
Java Result: 1 

Also, was ist der richtige Weg, um die IRI der neuen Ontologie angeben?

Antwort

3

Sollte es der Pfad zu der neuen Datei oder einer URL sein?

Die Ontologie IRI sollte eine IRI sein. Während es "Datei-IRIs" gibt (zB file://something-here), möchten Sie normalerweise, dass die Ontologie-IRI etwas Nützliches ist, und wenn Sie die Ontologie online veröffentlichen möchten, kann es hilfreich sein (aber es ist nicht obligatorisch), das zu machen Ontologie IRI ein IRI, von dem Sie die tatsächliche Ontologie abrufen können.

Das Problem, die OWL API wissen zu lassen, wo eine von Ihnen erstellte Ontologie gespeichert werden soll, ist ein anderes Problem. Die Beispiele in der OWL-API-Dokumentation umfassen einen Testfall genannt shouldSaveOntology, die zeigt, dass es eine Version von OWLOntologyManager#saveOntology(), die zwei Argumente übernimmt, die Ontologie und den Pfad, an dem sie zu retten, und liefert ein Beispiel:

File file = folder.newFile("owlapiexamples_saving.owl"); 
manager.saveOntology(ontology, IRI.create(file.toURI()));