【问题标题】:Load Ontology serialized in Turtle using OWL API使用 OWL API 加载在 Turtle 中序列化的 Ontology
【发布时间】:2019-08-23 10:49:59
【问题描述】:

我正在尝试使用 OWL API 从 Jena 模型加载本体,但大多数公理都显示为注释。

Turtle 中的本体如下图所示。我使用 Jena 模型来存储它。 注意:下面的答案中提到的本体不正确

@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

<http://example.com/minimalDecoupling>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "minimal decoupling" .

<http://example.com/frequency>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "frequency" .

<http://example.com/voltage>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "Voltage" .

<http://example.com/powerConsumed>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "power consumed" .

<http://example.com/installation>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "installation" .

<http://example.com/Device>
        a           "http://www.w3.org/2002/07/owl#Class" ;
        rdfs:label  "device" .

<http://example.com/dimension>
        a           "http://www.w3.org/2002/07/owl#DatatypeProperty" ;
        rdfs:label  "dimension" .

<http://example.com/>
        a       "http://www.w3.org/2002/07/owl#Ontology" .

假设上述本体存储在Jena模型ontologyGraph中,我使用下面的代码将Jena模型加载为OWL本体。

OWLOntology ontology = ontologyManager.
                loadOntologyFromOntologyDocument
                        (new ByteArrayInputStream(Ontology.toTurtle(ontologyGraph).getBytes()));

toTurtle 方法如下所示:

public static String toTurtle(Model ontologyGraph){
        StringWriter out = new StringWriter();
        ontologyGraph.write(out,"TTL");
        return out.toString();
    } 

然而,正如我们在下面的输出中看到的,来自本体的公理出现在注解公理:

Ontology(OntologyID(Anonymous-2)) [公理:15 逻辑公理:0] 首先 20 个公理:{AnnotationAssertion(rdfs:label http://example.com/powerConsumed“功耗”) AnnotationAssertion(rdfs:label http://example.com/minimalDecoupling "最小解耦") AnnotationAssertion(rdf:type http://example.com/ "http://www.w3.org/2002/07/owl#Ontology") AnnotationAssertion(rdfs:label http://example.com/dimension “维度”)AnnotationAssertion(rdf:type http://example.com/dimension "http://www.w3.org/2002/07/owl#DatatypeProperty") AnnotationAssertion(rdf:type http://example.com/voltage "http://www.w3.org/2002/07/owl#DatatypeProperty") AnnotationAssertion(rdf:type http://example.com/Device "http://www.w3.org/2002/07/owl#Class") AnnotationAssertion(rdfs:label http://example.com/installation“安装”) AnnotationAssertion(rdfs:label http://example.com/voltage "电压") AnnotationAssertion(rdf:type http://example.com/minimalDecoupling "http://www.w3.org/2002/07/owl#DatatypeProperty") AnnotationAssertion(rdf:type http://example.com/frequency "http://www.w3.org/2002/07/owl#DatatypeProperty") AnnotationAssertion(rdfs:label http://example.com/Device "device") AnnotationAssertion(rdf:type http://example.com/powerConsumed "http://www.w3.org/2002/07/owl#DatatypeProperty") AnnotationAssertion(rdfs:label http://example.com/frequency “频率”)注释断言(rdf:类型 http://example.com/installation "http://www.w3.org/2002/07/owl#DatatypeProperty") }

我的问题是:

  1. 为什么所有公理都显示为注释?
  2. 是否可以使用 OWL API 直接将 Jena 模型加载为 OWL 本体而无需通过 Turtle?

【问题讨论】:

    标签: jena owl-api turtle-rdf


    【解决方案1】:
    • 1) 如另一个答案所述 - 提供的本体不正确,而不是 URI,而是文字。
    • 2) ONT-API - 基于 Jena 的 OWL-API-api 实现。

    您可以将 turtle 加载到管理器中,由于转换器而进行一些更改,或者按原样传递 Graph(带或不带转换器)。 在给定 RDF 的最后一种情况下,只有AnnotationAssertion 公理。 如果您手动修复您的 RDF,将文字替换为 URI,则需要以下公理:

        Declaration(Class(<http://example.com/Device>))
        Declaration(DataProperty(<http://example.com/dimension>))
        Declaration(DataProperty(<http://example.com/installation>))
        Declaration(DataProperty(<http://example.com/powerConsumed>))
        Declaration(DataProperty(<http://example.com/voltage>))
        Declaration(DataProperty(<http://example.com/frequency>))
        Declaration(DataProperty(<http://example.com/minimalDecoupling>))
        AnnotationAssertion(rdfs:label <http://example.com/minimalDecoupling> "minimal decoupling"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/frequency> "frequency"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/voltage> "Voltage"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/powerConsumed> "power consumed"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/installation> "installation"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/Device> "device"^^xsd:string)
        AnnotationAssertion(rdfs:label <http://example.com/dimension> "dimension"^^xsd:string)
    

    另外注意:还有一个RDF数据视图:com.github.owlcs.ontapi.jena.model.OntModel,建议用它代替org.apache.jena.ontology.OntModel,因为最后一个不支持OWL2

    【讨论】:

    • 我太傻了,对不起,我真的没有注意到本体不正确!我会解决这个问题,我相信它会起作用!
    【解决方案2】:

    为什么所有公理都显示为注释?

    输入模型中的类型是字符串文字,但它们必须是 IRI。比如这个:

    <http://example.com/Device>
        a "http://www.w3.org/2002/07/owl#Class" ;
    

    应该是:

    <http://example.com/Device>
        a <http://www.w3.org/2002/07/owl#Class> ;
    

    然后会自动缩写为:

    <http://example.com/Device>
        a owl:Class ;
    

    输入 Jena 模型中的本体是使用 Jena API 创建的吗?在这种情况下,需要更改代码以创建 IRI(在 Jena 中也称为“资源”或“URIResources”)而不是字符串文字。

    是否可以使用 OWL API 直接将 Jena 模型加载为 OWL 本体而无需通过 Turtle?

    没有办法直接将 Jena 模型加载到 OWL-API 中,但肯定有一些选项可以避免往返于 Turtle,例如 ONT-API

    【讨论】:

    • 您可能知道ONT-D2RQ,它是您项目 (d2rq) 的一个可行分支,已更新为使用现代 Jena。该项目支持 OWL2 并在依赖项中包含 ONT-API。所以,问题是为什么你不这么认为?你有一些论据来证明它还是只是感觉?
    • 我专注于问题的“直接”部分。我编辑了答案以澄清。
    • ONT-API 也支持直接传递 Graph:见OntologyManager#addOntology(...)
    • @ssz 我又编辑了。我第一次应该措辞更好。 D2RQ 讨论在 GitHub 上会更合适。
    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-20
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多