【问题标题】:How to retrieve comments from an owl file using Jena API?如何使用 Jena API 从 owl 文件中检索评论?
【发布时间】:2012-11-06 09:46:44
【问题描述】:

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

<!-- 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>

所以当我搜索 Beth 时,我应该得到与之相关的评论,即。Beth 是亚当的女​​儿。她是查克的妹妹。她是多蒂和爱德华的母亲。她是 Fran & Greg 的姑姑。我用来获取主语、谓语和宾语的代码如下

    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();
        ...
    }

【问题讨论】:

    标签: rdf jena ontology owl protege


    【解决方案1】:

    rdfs:comment 应该作为您获得的谓词之一存在(它的 toString,建议您不要偶然依赖它,它将是:http://www.w3.org/2000/01/rdf-schema#comment)。如果它不存在,那么您的代码不是您向我们展示的内容,或者数据不是您引用的内容。由于我找不到您所指的本体,我们无法检查。

    更简单的方法是使用Jena ontology API。使用本体 API,您可以执行以下操作(我没有运行此代码,但应该可以):

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

    【讨论】:

    • 在这种情况下,请单击绿色复选标记将答案标记为已接受。这会告诉其他用户您已找到问题的答案。
    • 在 beth.getComment() 中传递了什么参数
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多