2015-12-08 178 views
0

我需要一些帮助来编写查询。SPARQL查询从OWL文件检索数据

要检索的数据: 将其“flys”布尔值设置为true的“Animal”的所有实例。

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} 
+0

究竟什么是你的问题?你在哪里写入查询?显然,它应该已经工作,除了限制'动物'的实例' - 这个问题吗?什么不清楚? –

+0

@ o-r-mapper问题是,即使我在查询“WHERE {?anims:flys?fly}”(它应该返回表格中的所有内容)中进行此更改,我什么都得不到。所以,是的,我坚持写查询,但我想这个问题必须隐藏在猫头鹰文件中。 –

+2

如果你不放'FROM '在你的查询?没有看到你如何将RDF数据放入SPARQL端点,我想你会将它放到默认(无名)图中,而不是一个特定的命名图。 –

回答

0

通过内容你的.owl文件(我把整个文件打印在这里)不起作用的主要原因是你在一个无效的名字空间中搜索。文件中没有将前缀定义为anims。您可以修改此使用的Protege或添加以下行的!DOCTYPE rdf:RDF块:

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

这应该做的伎俩;)