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

时间:2017-05-31 08:55:29

标签: java python rdf owl ontology

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

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

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

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

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

提前致谢, RF

1 个答案:

答案 0 :(得分:3)

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

RDF是一个抽象数据模型。它有几个serialization formats

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

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

        RDF(抽象)语法不是OWL本体的唯一语法。其他人很少:

        1. OWL/XML
        2. <?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. Functional syntax
          2. 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. Manchester syntax
            2. 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文件。