繁体   English   中英

在使用Jena(java)或RDFLib(python)时,我应该如何将本体打开为“turtle”或“xml”?

[英]While using Jena (java) or RDFLib (python), how should I find out whether to open the ontology as 'turtle' or 'xml'?

本体文件通常具有.owl或.rdf等扩展名。

我想知道何时应该用'turtle'和'xml'或其他格式打开本体? 因为它们似乎对于某种格式很有用,不幸的是,人们似乎有时会使用错误的扩展名来保存文件。

这是Python中的示例代码(但java也不是很相似):

g.parse('ontology.owl', format='turtle')

那么,我怎么知道龟是正确的格式?

提前谢谢,RF

您正在打开RDF文件,而不是本体。

RDF是一种抽象数据模型。 它有几种序列化格式

  1. RDF / XML
<?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> .
  1. JSON-LD
[ {
  "@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"
  } ]
} ]

使用文本编辑器打开文件,查看文件内容与之类似的内容,然后选择适当的选项。 您可以使用此在线服务将RDF文件从一种序列化格式转换为另一种序列化格式。

RDF(抽象)语法不是OWL本体的唯一语法。 其他几个:

  1. OWL / XML
<?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>
  1. 功能语法
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)
)
  1. 曼彻斯特语法
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解析这些格式的文件。 您可以使用此在线服务在这些格式(和RDF格式)之间转换OWL文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM