使用Jena API基于OWL本体(在Protege上创建)创建大量个体



我有一个大型XML文档(100Go),希望对其进行解析以提取信息并将其存储到RDF三元组存储中。

我发现了如何使用Java解析大型XML文件,并了解了如何使用Jena RDFneneneba API读取/写入RDF文件。

  1. 如何基于我在OWL本体,使用Protege创建
  2. 是否可以读取/加载此OWL本体并创建实例类的三元组,并使用Jena将它们存储到RDF File

主要问题是创建了大量实例(三元组)。

XML文件示例:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>
         <name>Gaella, Matt</name>
         <initial>MG</initial>
      </author>
      <title>User Guide</title>
      <price>45.95</price>
      <publish_date>2010-10-01</publish_date>
   </book>
   <book id="bk102">
      <author>
         <name>Rall, Kimiou</name>
         <initial>KR</initial>
      </author>
      <title>Midnight Scene</title>
      <price>5.75</price>
      <publish_date>2011-12-02</publish_date>
   </book>
   <book id="bk103">
      <author>
         <name>Colin, Evian</name>
         <initial>EC</initial>
      </author>
      <title>Cool Ascendant</title>
      <price>5.50</price>
      <publish_date>2012-11-03</publish_date>
   </book>
   <book id="bk104">
      <author>
         <name>Cortes, Smith</name>
         <initial>SC</initial>
      </author>
      <title>Farmer Legacy</title>
      <price>10.50</price>
      <publish_date>2013-03-04</publish_date>
   </book>
    . . .
</catalog>

OWL-DL本体:

<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
    xmlns="http://www.owl-ontologies.com/OntologyBooks.owl#"
    xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xml:base="http://www.owl-ontologies.com/OntologyBooks.owl">
  <owl:Ontology rdf:about=""/>
  <owl:Class rdf:ID="Book">
    <owl:disjointWith>
      <owl:Class rdf:ID="Author"/>
    </owl:disjointWith>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom>
          <owl:Class rdf:about="#Author"/>
        </owl:allValuesFrom>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="hasAuthor"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#hasAuthor"/>
        </owl:onProperty>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Author"/>
        </owl:someValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
        >1</owl:cardinality>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="price"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
        >1</owl:cardinality>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="publishDate"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="title"/>
        </owl:onProperty>
        <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
        >1</owl:cardinality>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </owl:Class>
  <owl:Class rdf:about="#Author">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
        >1</owl:cardinality>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="initial"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
        >1</owl:cardinality>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="name"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <owl:disjointWith rdf:resource="#Book"/>
  </owl:Class>
  <owl:ObjectProperty rdf:ID="isAuthorOf">
    <rdfs:domain rdf:resource="#Author"/>
    <rdfs:range rdf:resource="#Book"/>
    <owl:inverseOf>
      <owl:ObjectProperty rdf:about="#hasAuthor"/>
    </owl:inverseOf>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#hasAuthor">
    <owl:inverseOf rdf:resource="#isAuthorOf"/>
    <rdfs:domain rdf:resource="#Book"/>
    <rdfs:range rdf:resource="#Author"/>
  </owl:ObjectProperty>
  <owl:DatatypeProperty rdf:about="#publishDate">
    <rdfs:domain rdf:resource="#Book"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="#price">
    <rdfs:domain rdf:resource="#Book"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="#initial">
    <rdfs:domain rdf:resource="#Author"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="#name">
    <rdfs:domain rdf:resource="#Author"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="#title">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Book"/>
  </owl:DatatypeProperty>
</rdf:RDF>

您考虑过Jena中基于磁盘的模型吗?我指的是TDB和Fuseki。

这里的文件上写着:

"如果您希望在多个应用程序之间共享TDB数据集,请使用我们的Fuseki组件,该组件提供了一个可以使用TDB进行持久存储的SPARQL服务器,并通过HTTP提供用于查询、更新和REST更新的SPARQL协议。"

TDB支持非常大的本体,您可以通过Jena模型访问存储的数据——在加载本体后,您将以这种方式探索和添加个人。

Fuseki还支持SPARQL和更新,这意味着您也可以通过这种方式添加个人。

还支持将存储的模型导出回RDF文件,这将为您提供所需的输出。

关于为Protege中定义的类创建实例,这很容易——你会发现RDF文件中声明的类,很可能是像这样的三元组

classIRI rdf:type owl:Class

然后,您可以使用创建实例

instanceIRI rdf:type classIRI

最新更新