Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OWLAPI,从URI中提取字符串_Java_Owl Api - Fatal编程技术网

Java OWLAPI,从URI中提取字符串

Java OWLAPI,从URI中提取字符串,java,owl-api,Java,Owl Api,给定一个任意的IRI,例如主本体或它导入的一个本体,我想提取标题,但代码不会产生任何注释 OWLOntology o= ... // init the ontology as usual for (OWLAnnotation ann: o.getAnnotations()){ if(ann.getProperty().equals(dataFactory.getRDFSLabel()){ // here you have found a rdfs:label annota

给定一个任意的IRI,例如主本体或它导入的一个本体,我想提取标题,但代码不会产生任何注释

OWLOntology o= ... // init the ontology as usual
for (OWLAnnotation ann: o.getAnnotations()){
    if(ann.getProperty().equals(dataFactory.getRDFSLabel()){
        // here you have found a rdfs:label annotation, so you can use the value for your purposes
    }
}
下面是我所说的SKOS本体的一个例子:

  <owl:Ontology rdf:about="http://www.w3.org/2004/02/skos/core">
    <dct:title xml:lang="en">SKOS Vocabulary</dct:title>
编辑:根据以下建议更新代码,但仅为rdfs返回1个对象:请参见

public void getData()抛出OWLOntologyCreationException

{
    // Get hold of an ontology manager 
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    // Load an ontology from the Web.  We load the ontology from a document IRI 
    IRI docIRI = IRI.create("http://www.w3.org/2009/08/skos-reference/skos.rdf"); 
    OWLOntology skos = manager.loadOntologyFromOntologyDocument(docIRI); 

    for (OWLAnnotation ann: skos.getAnnotations())
    {
        System.out.println("ann: " + ann.getProperty());
        System.out.println();
    }


}

您正在寻找的注释是本体注释,这意味着作为其主题的IRI就是本体IRI本身。这与标准注释的访问方式不同

OWLOntology o= ... // init the ontology as usual
for (OWLAnnotation ann: o.getAnnotations()){
    if(ann.getProperty().equals(dataFactory.getRDFSLabel()){
        // here you have found a rdfs:label annotation, so you can use the value for your purposes
    }
}
编辑:使用示例

public static void main(String[] args) throws OWLOntologyCreationException {
    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    OWLOntology o = m.loadOntology(IRI
            .create("http://www.w3.org/2009/08/skos-reference/skos.rdf"));
    for (OWLAnnotation a : o.getAnnotations()) {
        System.out.println("TestSkos.main() " + a);
    }
}
Output:

    TestSkos.main() Annotation(rdfs:seeAlso <http://www.w3.org/TR/skos-reference/>)
    TestSkos.main() Annotation(<http://purl.org/dc/terms/creator> "Alistair Miles")
    TestSkos.main() Annotation(<http://purl.org/dc/terms/description> "An RDF vocabulary for describing the basic structure and content of concept schemes such as thesauri, classification schemes, subject heading lists, taxonomies, 'folksonomies', other types of controlled vocabulary, and also concept schemes embedded in glossaries and terminologies."@en)
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Participants in W3C's Semantic Web Deployment Working Group.")
    TestSkos.main() Annotation(<http://purl.org/dc/terms/creator> "Sean Bechhofer")
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Nikki Rogers")
    TestSkos.main() Annotation(<http://purl.org/dc/terms/title> "SKOS Vocabulary"@en)
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Dave Beckett")
publicstaticvoidmain(字符串[]args)抛出owletologyCreationException{
OWLOntologyManager m=OWLManager.createOWLOntologyManager();
OWLOontology=m.loadOntology(IRI
.创建(“http://www.w3.org/2009/08/skos-reference/skos.rdf"));
对于(OWLA:o.getAnnotations()){
System.out.println(“TestSkos.main()”+a);
}
}
输出:
main()注释(rdfs:seeAllow)
main()注释(“Alistair Miles”)
TestSkos.main()注释(“一个RDF词汇表,用于描述概念方案的基本结构和内容,如同义词表、分类方案、主题标题列表、分类法、“大众分类法”、其他类型的受控词汇,以及嵌入在词汇表和术语中的概念方案。”@en)
main()注释(“W3C语义Web部署工作组的参与者”)
main()注释(“Sean Bechhofer”)
main()注释(“Nikki Rogers”)
main()注释(“SKOS词汇表”@en)
main()注释(“Dave Beckett”)

不幸的是,上面的代码只生成一个用于rdfs的注释:请参见。找不到SKOS词汇表。您使用的是哪个OWLAPI版本?我都明白了。请参阅更新的代码段。我使用的是版本3.**但我切换到了版本4.**并且它工作得非常完美。谢谢你是如何获得其中一个导入本体的名称的?@Ignazio:我也想知道这一点。