我试图使用OWL API从Jena模型加载本体,但大多数公理都是作为注释出现的。
乌龟的本体论如下所示。我使用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();
}
但是,正如我们在下面的输出中所看到的,本体的公理正在出现注释公理:
本体论(OntologyID(Anonymous-2))[Axioms:15 Logical Axioms:0]前20个公理:{AnnotationAssertion(rdfs:label http://example.com/powerConsumed“power consume”)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“安装”)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”)}
我的问题是:
您可以将乌龟加载到管理器中,由于变换器而进行一些更改,或者按原样传递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
为什么所有的公理都作为注释出现?
输入模型中的类型是字符串文字,但它们必须是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中,但肯定有一些选项可以避免像Qazxswpoi那样通过Turtle往返。