使用 OWL API 加载在 Turtle 中序列化的 Ontology
Load Ontology serialized in Turtle using OWL API
我正在尝试使用 OWL API 从 Jena 模型加载 ontology,但大多数公理都显示为注释。
Turtle中的ontology如下图。我使用 Jena 模型来存储它。 注意:下面的 ontology 不正确,如下面的答案所述
@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" .
假设上面的 ontology 存储在 Jena 模型 ontologyGraph
中,我正在使用下面的代码将 Jena 模型加载为 OWL ontology。
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 的公理出现了注释公理:
Ontology(OntologyID(Anonymous-2)) [Axioms: 15 Logical Axioms: 0] First
20 axioms: {AnnotationAssertion(rdfs:label
http://example.com/powerConsumed "power consumed")
AnnotationAssertion(rdfs:label http://example.com/minimalDecoupling
"minimal decoupling") AnnotationAssertion(rdf:type
http://example.com/ "http://www.w3.org/2002/07/owl#Ontology")
AnnotationAssertion(rdfs:label http://example.com/dimension
"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 "installation")
AnnotationAssertion(rdfs:label http://example.com/voltage "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
"frequency") AnnotationAssertion(rdf:type
http://example.com/installation
"http://www.w3.org/2002/07/owl#DatatypeProperty") }
我的问题是:
- 为什么所有公理都显示为注释?
- 是否可以使用 OWL API 将 Jena 模型直接加载为 OWL ontology 而无需通过 Turtle ?
Why are all the axioms appearing as annotations?
输入模型中的类型是字符串字面量,但需要是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模型中的ontology是使用JenaAPI创建的吗?在这种情况下,需要更改代码以创建 IRI(在 Jena 中也称为“Resources”或“URIResources”)而不是字符串文字。
Is it possible to directly load a Jena model as an OWL ontology using OWL API without having to pass through Turtle?
无法直接将 Jena 模型加载到 OWL-API,但肯定有一些选项可以避免往返乌龟,喜欢ONT-API.
- 1) 如另一个答案中所述 - 提供的 ontology 不正确,而不是 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数据视图:com.github.owlcs.ontapi.jena.model.OntModel,建议使用它而不是org.apache.jena.ontology.OntModel
,因为最后一个不支持OWL2
我正在尝试使用 OWL API 从 Jena 模型加载 ontology,但大多数公理都显示为注释。
Turtle中的ontology如下图。我使用 Jena 模型来存储它。 注意:下面的 ontology 不正确,如下面的答案所述
@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" .
假设上面的 ontology 存储在 Jena 模型 ontologyGraph
中,我正在使用下面的代码将 Jena 模型加载为 OWL ontology。
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 的公理出现了注释公理:
Ontology(OntologyID(Anonymous-2)) [Axioms: 15 Logical Axioms: 0] First 20 axioms: {AnnotationAssertion(rdfs:label http://example.com/powerConsumed "power consumed") AnnotationAssertion(rdfs:label http://example.com/minimalDecoupling "minimal decoupling") AnnotationAssertion(rdf:type http://example.com/ "http://www.w3.org/2002/07/owl#Ontology") AnnotationAssertion(rdfs:label http://example.com/dimension "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 "installation") AnnotationAssertion(rdfs:label http://example.com/voltage "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 "frequency") AnnotationAssertion(rdf:type http://example.com/installation "http://www.w3.org/2002/07/owl#DatatypeProperty") }
我的问题是:
- 为什么所有公理都显示为注释?
- 是否可以使用 OWL API 将 Jena 模型直接加载为 OWL ontology 而无需通过 Turtle ?
Why are all the axioms appearing as annotations?
输入模型中的类型是字符串字面量,但需要是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模型中的ontology是使用JenaAPI创建的吗?在这种情况下,需要更改代码以创建 IRI(在 Jena 中也称为“Resources”或“URIResources”)而不是字符串文字。
Is it possible to directly load a Jena model as an OWL ontology using OWL API without having to pass through Turtle?
无法直接将 Jena 模型加载到 OWL-API,但肯定有一些选项可以避免往返乌龟,喜欢ONT-API.
- 1) 如另一个答案中所述 - 提供的 ontology 不正确,而不是 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数据视图:com.github.owlcs.ontapi.jena.model.OntModel,建议使用它而不是org.apache.jena.ontology.OntModel
,因为最后一个不支持OWL2