簡體   English   中英

SPARQL查詢以從OWL文件中檢索數據

[英]SPARQL query to retrieve data from OWL file

我需要一些幫助來編寫查詢。

要檢索的數據:“動物”的所有實例都將其“ flys”布爾值設置為true。

OWL文件(一團糟):

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY swrl "http://www.w3.org/2003/11/swrl#" >
    <!ENTITY swrlb "http://www.w3.org/2003/11/swrlb#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY assert "http://www.owl-ontologies.com/assert.owl#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY protege "http://protege.stanford.edu/plugins/owl/protege#" >
    <!ENTITY xsp "http://www.owl-ontologies.com/2005/08/07/xsp.owl#" >
    <!ENTITY swrla "http://swrl.stanford.edu/ontologies/3.3/swrla.owl#" >
    <!ENTITY sqwrl "http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#" >
]>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://www.owl-ontologies.com/Animals.owl#"
    xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
    xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
    xmlns:assert="http://www.owl-ontologies.com/assert.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:sqwrl="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:swrla="http://swrl.stanford.edu/ontologies/3.3/swrla.owl#"
  xml:base="http://www.owl-ontologies.com/Animals.owl">
  <owl:Ontology rdf:about="">
    <owl:imports rdf:resource="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl"/>
    <owl:imports rdf:resource="http://swrl.stanford.edu/ontologies/3.3/swrla.owl"/>
    <owl:imports rdf:resource="http://www.owl-ontologies.com/assert.owl"/>
  </owl:Ontology>

  <owl:Class rdf:ID="Carnivore">
  <rdfs:label xml:lang="gr">Σαρκοφάγο</rdfs:label>
    <rdfs:subClassOf>
      <owl:Class rdf:ID="Living_thing"/>
    </rdfs:subClassOf>
  </owl:Class>

    <owl:Class rdf:ID="Plant">
     <owl:complementOf>
                  <owl:Class rdf:about="#Animal"/>
                </owl:complementOf>
    <rdfs:label xml:lang="gr">Φυτό</rdfs:label>
    <rdfs:subClassOf>
      <owl:Class rdf:ID="Living_thing"/>
    </rdfs:subClassOf>
  </owl:Class>


  <owl:Class rdf:ID="Perioxi">
  <rdfs:label xml:lang="gr">Περιοχή</rdfs:label>
    <rdfs:subClassOf>
      <owl:Class rdf:ID="Domain_entity"/>
    </rdfs:subClassOf>
  </owl:Class>

  <owl:Class rdf:ID="Living_thing">
  <owl:complementOf>
                  <owl:Class rdf:about="#Perioxi"/>
                </owl:complementOf>
  <rdfs:label xml:lang="gr">Οργανισμός</rdfs:label>
    <rdfs:subClassOf>
     <owl:Restriction>
        <owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="belongs"/>
        </owl:onProperty>
         </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
    <owl:Restriction>
        <owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="kind"/>
        </owl:onProperty>
         </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
    <owl:Restriction>
        <owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
       <owl:onProperty>
      <owl:DatatypeProperty rdf:ID="flys"/>
        </owl:onProperty>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
    <owl:Restriction>
        <owl:allValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
        <owl:onProperty>
          <owl:DatatypeProperty rdf:ID="population"/>
        </owl:onProperty>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Domain_entity"/>
  </owl:Class>

  <owl:Class>
    <owl:unionOf rdf:parseType="Collection">
      <owl:Class rdf:about="#Living_thing"/>
      <owl:Class rdf:about="#Animal"/>
    </owl:unionOf>
  </owl:Class>

  <owl:Class rdf:ID="Carnivore">
    <rdfs:subClassOf>
    <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <owl:Restriction>
            <owl:onProperty>
              <owl:ObjectProperty rdf:ID="kind"/>
            </owl:onProperty>
            <owl:allValuesFrom rdf:resource="#Animal"/>
          </owl:Restriction>
        </owl:unionOf>
      </owl:Class>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom>
          <owl:Class>
            <owl:intersectionOf rdf:parseType="Collection">
              <owl:Class rdf:about="#Animal"/>
              <owl:Class>
                <owl:complementOf>
                  <owl:Class rdf:about="#Plant"/>
                </owl:complementOf>
              </owl:Class>
            </owl:intersectionOf>
          </owl:Class>
        </owl:allValuesFrom>
        <owl:onProperty>
          <owl:TransitiveProperty rdf:about="#eats"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Class rdf:about="#Living_thing"/>
    </rdfs:subClassOf>
  </owl:Class>


  <owl:Class rdf:ID="Herbivore">
  <rdfs:label xml:lang="gr">Φυτοφάγο</rdfs:label>
    <rdfs:subClassOf>
      <owl:Class rdf:about="#Living_thing"/>
    </rdfs:subClassOf>
  </owl:Class>

<owl:Class rdf:about="#Ellinika_zwa">
<rdfs:label xml:lang="gr">Ελληνικά_ζώα</rdfs:label>
<rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Animal"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#kind"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:hasValue rdf:resource="#Greece"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#lives-in"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Living_thing"/>
  </owl:Class>



  <owl:Class rdf:about="#Animal">
  <owl:complementOf>
                  <owl:Class rdf:about="#Plant"/>
                </owl:complementOf>
  <rdfs:label xml:lang="gr">Ζώο</rdfs:label>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#lives-in"/>
        </owl:onProperty>
        <owl:someValuesFrom rdf:resource="#Perioxi"/>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Living_thing"/>
  </owl:Class>

  <owl:Class rdf:ID="Dangerous_Animals_America">
  <rdfs:label xml:lang="gr">Αρπακτικά_Αμερικής</rdfs:label>
  <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Carnivore"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#belongs"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
<rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#America"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#lives-in"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
  <rdfs:subClassOf>
      <owl:Restriction>
        <owl:hasValue rdf:resource="#True"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#flys"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Living_thing"/>
</owl:Class>

  <owl:Class rdf:ID="Europe">
   <owl:complementOf>
                  <owl:Class rdf:about="#Asia"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#Africa"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#America"/>
                </owl:complementOf>
  <rdfs:label xml:lang="gr">Ευρώπη</rdfs:label>
    <rdfs:subClassOf rdf:resource="#Perioxi"/>
  </owl:Class>

  <owl:Class rdf:ID="Asia">
  <owl:complementOf>
                  <owl:Class rdf:about="#Europe"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#Africa"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#America"/>
                </owl:complementOf>
  <rdfs:label xml:lang="gr">Ασία</rdfs:label>
    <rdfs:subClassOf rdf:resource="#Perioxi"/>
  </owl:Class>

    <owl:Class rdf:ID="America">
    <owl:complementOf>
                  <owl:Class rdf:about="#Asia"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#Africa"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#Europe"/>
                </owl:complementOf>
    <rdfs:label xml:lang="gr">Αμερική</rdfs:label>
    <rdfs:subClassOf rdf:resource="#Perioxi"/>
  </owl:Class>

    <owl:Class rdf:ID="Africa">
    <owl:complementOf>
                  <owl:Class rdf:about="#Asia"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#Europe"/>
                </owl:complementOf>
                 <owl:complementOf>
                  <owl:Class rdf:about="#America"/>
                </owl:complementOf>
    <rdfs:label xml:lang="gr">Αφρική</rdfs:label>
    <rdfs:subClassOf rdf:resource="#Perioxi"/>
  </owl:Class>

<owl:Class rdf:about="#Herbivore">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Plant"/>
        <owl:onProperty>
          <owl:TransitiveProperty rdf:about="#eats"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Animal"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="#kind"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Living_thing"/>
  </owl:Class>




  <owl:ObjectProperty rdf:ID="eatable">
  <rdfs:label xml:lang="gr">τρώγεται</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/>
    <owl:inverseOf>
      <owl:ObjectProperty rdf:ID="eats"/>
    </owl:inverseOf>
  </owl:ObjectProperty>

  <owl:ObjectProperty rdf:ID="isancestor">
  <rdfs:label xml:lang="gr">πρόγονος</rdfs:label>
   <rdf:type rdf:resource="&owl;TransitiveProperty"/>
    <rdfs:range rdf:resource="#Living_thing"/>
    <rdfs:domain rdf:resource="#Living_thing"/>
  </owl:ObjectProperty>

  <owl:ObjectProperty rdf:ID="lives-in">
  <rdfs:label xml:lang="gr">ζει-σε</rdfs:label>
    <rdfs:range rdf:resource="#Perioxi"/>
    <rdfs:domain rdf:resource="#Living_thing"/>
  </owl:ObjectProperty>

  <owl:ObjectProperty rdf:ID="competitor">
  <rdfs:label xml:lang="gr">ανταγωνιστής</rdfs:label>
  <rdf:type rdf:resource="&owl;SymmetricProperty"/>
    <rdfs:range rdf:resource="#Living_thing"/>
    <rdfs:domain rdf:resource="#Living_thing"/>
  </owl:ObjectProperty >

  <owl:ObjectProperty rdf:about="#eats">
  <rdfs:label xml:lang="gr">τρώει</rdfs:label>
    <owl:inverseOf rdf:resource="#eatable"/>
    <rdfs:range>
      <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <owl:Class rdf:about="#Animal"/>
          <owl:Class rdf:about="#Living_thing"/>
          <owl:Class rdf:about="#Herbivore"/>
          <owl:Class rdf:about="#Dangerous_Animals_America"/>
          <owl:Class rdf:about="#Ellinika_zwa"/>
          <owl:Class rdf:about="#Carnivore"/>
          <owl:Class rdf:about="#Plant"/>
        </owl:unionOf>
      </owl:Class>
    </rdfs:range>
    <rdfs:domain rdf:resource="#Living_thing"/>
  </owl:ObjectProperty>

<owl:DatatypeProperty rdf:about="#kind">
<rdfs:label xml:lang="gr">είδος</rdfs:label>
<rdf:type rdf:resource="&owl;InverseFunctionalProperty"/>
    <rdfs:domain>
      <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <owl:Class rdf:about="#Herbivore"/>
          <owl:Class rdf:about="#Carnivore"/>
          <owl:Class rdf:about="#Dangerous_Animals_America"/>
          <owl:Class rdf:about="#Ellinika_zwa"/>
        </owl:unionOf>
      </owl:Class>
    </rdfs:domain>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>

  <owl:DatatypeProperty rdf:about="#belongs">
  <rdfs:label xml:lang="gr">ανήκει-στο-γένος</rdfs:label>
    <rdfs:domain>
      <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <owl:Class rdf:about="#Animal"/>
          <owl:Class rdf:about="#Plant"/>
        </owl:unionOf>
      </owl:Class>
    </rdfs:domain>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>

  <owl:DatatypeProperty rdf:ID="flys">
  <rdfs:label xml:lang="gr">πετάει</rdfs:label>
    <rdfs:domain rdf:resource="#Animal"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
  </owl:DatatypeProperty>

   <owl:DatatypeProperty rdf:ID="population">
   <rdfs:label xml:lang="gr">πληθυσμός</rdfs:label>
    <rdfs:domain rdf:resource="#Animal"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
  </owl:DatatypeProperty>

    <owl:DatatypeProperty rdf:ID="name">
    <rdfs:label xml:lang="gr">όνομα</rdfs:label>
    <rdfs:domain rdf:resource="#Perioxi"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>





  <Animal rdf:ID="bear">
  <rdfs:type xml:lang="gr">Αρκούδα</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Carnivore</belongs>
    <lives-in rdf:resource="Europe"/>
    <eats rdf:resource="Animal"/>
    <flys rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean"
     >false</flys>
  </Animal>

  <Animal rdf:ID="wolf">
  <rdfs:type xml:lang="gr">Λύκος</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Carnivore</belongs>
    <lives-in rdf:resource="Europe"/>
    <eats rdf:resource="Animal"/>
    <flys rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean"
     >false</flys>
  </Animal>

  <Plant rdf:ID="lettuce">
   <rdfs:type xml:lang="gr">Μαρούλι</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Plant</belongs>
  </Plant>

    <Plant rdf:ID="pefkos">
       <rdfs:type xml:lang="gr">Πεύκο</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Plant</belongs>
  </Plant>


    <Herbivore rdf:ID="horse">
       <rdfs:type xml:lang="gr">Άλογο</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Herbivore</belongs>
    <lives-in rdf:resource="Europe"/>
    <eats rdf:resource="Plant"/>
    <flys rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean"
     >false</flys>
  </Herbivore>

  <Herbivore rdf:ID="elephant">
     <rdfs:type xml:lang="gr">Ελέφαντας</rdfs:type>
    <belongs rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Herbivore</belongs>
    <lives-in rdf:resource="Europe"/>
    <eats rdf:resource="Plant"/>
    <flys rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean"
     >false</flys>
  </Herbivore>



  <Europe rdf:ID="Italy">
     <rdfs:name xml:lang="gr">Ιταλία</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Italy</name>
  </Europe>

   <Europe rdf:ID="Greece">
   <rdfs:name xml:lang="gr">Ελλάδα</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Greece</name>
  </Europe>

   <Africa rdf:ID="Nigeria">
   <rdfs:name xml:lang="gr">Νιγηρία</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Nigeria</name>
  </Africa>

  <Africa rdf:ID="Senegal">
  <rdfs:name xml:lang="gr">Σενεγάλη</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Senegal</name>
  </Africa>

  <Asia rdf:ID="China">
  <rdfs:name xml:lang="gr">Κίνα</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >China</name>
  </Asia>

    <Asia rdf:ID="Japan">
    <rdfs:name xml:lang="gr">Ιαπωνία</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Japan</name>
  </Asia>

    <America rdf:ID="USA">
    <rdfs:name xml:lang="gr">Η.Π.Α</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >USA</name>
  </America>

   <America rdf:ID="Brasil">
   <rdfs:name xml:lang="gr">Βραζιλία</rdfs:name>
   <name rdf:datatype ="http://www.w3.org/2001/XMLSchema#string"
    >Brasil</name>
  </America>


</rdf:RDF>

我編寫的查詢(該查詢不應返回任何結果,但仍然無法正常工作):

PREFIX anims:<http://www.owl-ontologies.com/Animal.owl#>
SELECT *
FROM <http://www.owl-ontologies.com/Animal.owl>
WHERE {?A anims:flys true}

根據您的.owl文件的內容(我認為整個文件都已打印在此處),其不起作用的主要原因是您正在無效的名稱空間中搜索。 文件中沒有定義為anims前綴。 您可以使用Protege對此進行修改,也可以在!DOCTYPE rdf:RDF塊中添加以下行:

<!ENTITY anims "http://www.owl-ontologies.com/Animal.owl#" >

這應該夠了吧 ;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM