Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Rdf 如何使用JenaAPI从owl文件检索注释?_Rdf_Jena_Ontology_Owl_Protege - Fatal编程技术网

Rdf 如何使用JenaAPI从owl文件检索注释?

Rdf 如何使用JenaAPI从owl文件检索注释?,rdf,jena,ontology,owl,protege,Rdf,Jena,Ontology,Owl,Protege,目前我正在做一个基于本体的信息检索项目。我已经使用本体编辑器Protege创建了基础本体,并获得了文件,比如family.owl。基本上我想执行一个搜索功能。用户提供搜索词,然后使用本体中的个人进行搜索。如果找到匹配项,则打印与该个人相关联的注释。我已使用Jena API解析本体。到目前为止,我成功获得了与每个资源相关联的主语、谓语和宾语,但我无法获得与每个资源相关联的注释。猫头鹰家族的一部分看起来像这样 <!-- http://www.semanticweb.org/ontologies

目前我正在做一个基于本体的信息检索项目。我已经使用本体编辑器Protege创建了基础本体,并获得了文件,比如family.owl。基本上我想执行一个搜索功能。用户提供搜索词,然后使用本体中的个人进行搜索。如果找到匹配项,则打印与该个人相关联的注释。我已使用Jena API解析本体。到目前为止,我成功获得了与每个资源相关联的主语、谓语和宾语,但我无法获得与每个资源相关联的注释。猫头鹰家族的一部分看起来像这样

<!-- http://www.semanticweb.org/ontologies/2012/9/family.owl#Beth -->
<owl:Thing rdf:about="#Beth">
    <rdfs:comment>Beth is the Daughter of Adam . She is the Sister of Chuck .  
     She is the Mother of Dotty & Edward . She is the Aunt of Fran & Greg.
    </rdfs:comment>
    <isChildOf rdf:resource="#Adam"/>
    <isSiblingOf rdf:resource="#Chuck"/>
</owl:Thing>

rdfs:comment
应该作为您得到的谓词之一存在(建议您不要顺便依赖它的
toString
,它将是:
http://www.w3.org/2000/01/rdf-schema#comment
)。如果没有,那么要么你的代码不是你展示给我们的,要么数据不是你引用的。因为我找不到你提到的本体,所以我们无法检查

做你想做的事情的一个更简单的方法是使用。使用本体API,您可以执行以下操作(我还没有运行此代码,但它应该可以工作):


在这种情况下,请单击绿色复选标记将答案标记为已接受。这会告诉其他用户您已经找到了问题的答案。在beth.getComment()中,传递了什么参数
    StmtIterator iter=model.listStatements();          
    while(iter.hasNext())
    {
        Statement stmt=iter.nextStatement();
        String subject=stmt.getSubject().toString;                             
        String predicate=stmt.getPredicate().toString();            
        String object=stmt.getObject().toString();
        ...
    }
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
FileManager.get().readModel( m, "... your input file here ..." );

String NS = "http://www.semanticweb.org/ontologies/2012/9/family.owl#";
Individual beth = m.getIndividual( NS + "Beth" );
String comment = beth.getComment();