使用OWL API在Turtle中序列化的Load Ontology

时间:2019-04-02 07:32:22

标签: jena owl-api turtle-rdf

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

Turtle中的本体如下所示。我使用耶拿模型进行存储。 注意:下面的答案中提到的以下本体是不正确的

@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“设备”)   AnnotationAssertion(rdf:type http://example.com/powerConsumed   “ http://www.w3.org/2002/07/owl#DatatypeProperty”)   AnnotationAssertion(rdfs:label http://example.com/frequency   “频率”)AnnotationAssertion(rdf:type   http://example.com/installation   “ http://www.w3.org/2002/07/owl#DatatypeProperty”)

我的问题是:

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

2 个答案:

答案 0 :(得分: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 API在输入Jena模型中创建本体吗?在这种情况下,需要更改代码以创建IRI(在耶拿中也称为“资源”或“ URIResources”),而不是字符串文字。

  

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

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

答案 1 :(得分:2)

  • 1),如另一个答案所述-提供的本体不正确,而不是URI,而是文字。
  • 2)ONT-API-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数据视图:OntGraphModel,建议改用OntModel,因为最后一个不支持OWL2