在使用 Jena (java) 或 RDFLib (python) 时,我应该如何确定是将 ontology 打开为 'turtle' 还是 'xml'?
While using Jena (java) or RDFLib (python), how should I find out whether to open the ontology as 'turtle' or 'xml'?
Ontology 文件的扩展名通常为 .owl 或 .rdf。
我想知道何时应该使用 'turtle' 以及何时使用 'xml' 或其他格式打开本体?因为似乎它们中的每一个都对一种格式有用而且不幸的是,似乎人们有时会用错误的扩展名保存文件。
这里是 Python 中的示例代码(但 java 也没有太大区别):
g.parse('ontology.owl', format='turtle')
那么,我怎么知道这里的 turtle 是正确的格式?
提前致谢,
射频
您正在打开 RDF 文件,而不是本体。
RDF is an abstract data model. It has several serialization formats:
<?xml version="1.0"?>
<rdf:RDF xmlns="http://example.com/ontology#"
xml:base="http://example.com/ontology"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://example.com/ontology"/>
<owl:Class rdf:about="http://example.com/ontology#Person"/>
<owl:Class rdf:about="http://example.com/ontology#Woman">
<rdfs:subClassOf rdf:resource="http://example.com/ontology#Person"/>
</owl:Class>
</rdf:RDF>
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://example.com/ontology> a owl:Ontology .
<http://example.com/ontology#Person> a owl:Class .
<http://example.com/ontology#Woman>
a owl:Class ;
rdfs:subClassOf <http://example.com/ontology#Person> .
[ {
"@id" : "http://example.com/ontology",
"@type" : [ "http://www.w3.org/2002/07/owl#Ontology" ]
}, {
"@id" : "http://example.com/ontology#Person",
"@type" : [ "http://www.w3.org/2002/07/owl#Class" ]
}, {
"@id" : "http://example.com/ontology#Woman",
"@type" : [ "http://www.w3.org/2002/07/owl#Class" ],
"http://www.w3.org/2000/01/rdf-schema#subClassOf" : [ {
"@id" : "http://example.com/ontology#Person"
} ]
} ]
使用文本编辑器打开您的文件,查看您的文件内容与什么相似,然后 select 适当的选项。您可以使用 this online service 将 RDF 文件从一种序列化格式转换为另一种序列化格式。
RDF(抽象)语法不是 OWL 本体的唯一语法。还有几个:
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://example.com/ontology"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://example.com/ontology">
<Prefix name="" IRI="http://example.com/ontology#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#Person"/>
</Declaration>
<Declaration>
<Class IRI="#Woman"/>
</Declaration>
<SubClassOf>
<Class IRI="#Woman"/>
<Class IRI="#Person"/>
</SubClassOf>
</Ontology>
Prefix(:=<http://example.com/ontology#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://example.com/ontology>
Declaration(Class(:Person))
Declaration(Class(:Woman))
SubClassOf(:Woman :Person)
)
Prefix: : <http://example.com/ontology#>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <http://example.com/ontology>
Class: Person
Class: Woman
SubClassOf:
Person
AFAIK,无法使用 RDFlib 解析这些格式的文件。
您可以使用 this online service 在这些格式(和 RDF 格式)之间转换 OWL 文件。
Ontology 文件的扩展名通常为 .owl 或 .rdf。
我想知道何时应该使用 'turtle' 以及何时使用 'xml' 或其他格式打开本体?因为似乎它们中的每一个都对一种格式有用而且不幸的是,似乎人们有时会用错误的扩展名保存文件。
这里是 Python 中的示例代码(但 java 也没有太大区别):
g.parse('ontology.owl', format='turtle')
那么,我怎么知道这里的 turtle 是正确的格式?
提前致谢, 射频
您正在打开 RDF 文件,而不是本体。
RDF is an abstract data model. It has several serialization formats:
<?xml version="1.0"?>
<rdf:RDF xmlns="http://example.com/ontology#"
xml:base="http://example.com/ontology"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://example.com/ontology"/>
<owl:Class rdf:about="http://example.com/ontology#Person"/>
<owl:Class rdf:about="http://example.com/ontology#Woman">
<rdfs:subClassOf rdf:resource="http://example.com/ontology#Person"/>
</owl:Class>
</rdf:RDF>
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://example.com/ontology> a owl:Ontology .
<http://example.com/ontology#Person> a owl:Class .
<http://example.com/ontology#Woman>
a owl:Class ;
rdfs:subClassOf <http://example.com/ontology#Person> .
[ {
"@id" : "http://example.com/ontology",
"@type" : [ "http://www.w3.org/2002/07/owl#Ontology" ]
}, {
"@id" : "http://example.com/ontology#Person",
"@type" : [ "http://www.w3.org/2002/07/owl#Class" ]
}, {
"@id" : "http://example.com/ontology#Woman",
"@type" : [ "http://www.w3.org/2002/07/owl#Class" ],
"http://www.w3.org/2000/01/rdf-schema#subClassOf" : [ {
"@id" : "http://example.com/ontology#Person"
} ]
} ]
使用文本编辑器打开您的文件,查看您的文件内容与什么相似,然后 select 适当的选项。您可以使用 this online service 将 RDF 文件从一种序列化格式转换为另一种序列化格式。
RDF(抽象)语法不是 OWL 本体的唯一语法。还有几个:
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://example.com/ontology"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://example.com/ontology">
<Prefix name="" IRI="http://example.com/ontology#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#Person"/>
</Declaration>
<Declaration>
<Class IRI="#Woman"/>
</Declaration>
<SubClassOf>
<Class IRI="#Woman"/>
<Class IRI="#Person"/>
</SubClassOf>
</Ontology>
Prefix(:=<http://example.com/ontology#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://example.com/ontology>
Declaration(Class(:Person))
Declaration(Class(:Woman))
SubClassOf(:Woman :Person)
)
Prefix: : <http://example.com/ontology#>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <http://example.com/ontology>
Class: Person
Class: Woman
SubClassOf:
Person
AFAIK,无法使用 RDFlib 解析这些格式的文件。 您可以使用 this online service 在这些格式(和 RDF 格式)之间转换 OWL 文件。