2

我正在尝试合并两个本体以创建一个新的单一本体。为此,我应该如何指定新本体的IRI?它应该是新文件的路径还是某个 url?

这是我的代码:

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);

}

创建的本体开始如下:

<?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"/>

的值xmlns是文件的路径。但是,当我将 url 指定为新本体的 IRI 时,例如:http://www.semanticweb.org/ontologies/2015/11/productCatalog#,它给出了以下异常:

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

那么指定新本体的IRI的正确方法是什么?

4

1 回答 1

3

它应该是新文件的路径还是某个 url?

本体 IRI 应该是一个 IRI。虽然有“文件 IRI”(例如,file://something-here),但您通常希望本体 IRI 有用,如果您打算在线发布本体,制作本体可能会有所帮助(但不是强制性的) IRI 可以从中检索实际本体的 IRI。

让 OWL API 知道将您创建的本体保存在哪里的问题实际上是一个不同的问题。OWL API 文档中的示例包括一个名为shouldSaveOntology的测试用例,它显示有一个OWLOntologyManager#saveOntology()版本,它接受两个参数,即本体和保存它的路径,并提供了一个示例:

File file = folder.newFile("owlapiexamples_saving.owl");
manager.saveOntology(ontology, IRI.create(file.toURI()));
于 2016-03-24T15:04:55.010 回答