2015-02-08 26 views
2

我的本體論是關於雞尾酒。這是一個名爲 「餘輝」Sparql查詢限制列表(相當於)protégé

<owl:Class rdf:about="&cocktails;AfterGlow"> 
    <owl:equivalentClass> 
     <owl:Class> 
      <owl:intersectionOf rdf:parseType="Collection"> 
       <owl:Restriction> 
        <owl:onProperty rdf:resource="&cocktails;aPourIngredient"/> 
        <owl:someValuesFrom rdf:resource="&cocktails;JusAnanas"/> 
       </owl:Restriction> 
       <owl:Restriction> 
        <owl:onProperty rdf:resource="&cocktails;aPourIngredient"/> 
        <owl:someValuesFrom rdf:resource="&cocktails;JusOrange"/> 
       </owl:Restriction> 
       <owl:Restriction> 
        <owl:onProperty rdf:resource="&cocktails;aPourIngredient"/> 
        <owl:someValuesFrom rdf:resource="&cocktails;SiropGrenadine"/> 
       </owl:Restriction> 
       <owl:Restriction> 
        <owl:onProperty rdf:resource="&cocktails;aPourDescription"/> 
        <owl:hasValue>Descriptoion AfterGlow</owl:hasValue> 
       </owl:Restriction> 
       <owl:Restriction> 
        <owl:onProperty rdf:resource="&cocktails;aPourTitre"/> 
        <owl:hasValue>AfterGlow</owl:hasValue> 
       </owl:Restriction> 
      </owl:intersectionOf> 
     </owl:Class> 
    </owl:equivalentClass> 
    <rdfs:subClassOf rdf:resource="&cocktails;Cocktail"/> 
</owl:Class> 

JusOrange意味着橙汁 JusAnanas雞尾酒意味着菠蘿汁

aPourIngredientproperty,這意味着 「已(含)成分」

enter image description here

這是請求列出我所有的雞尾酒與他們的收縮

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX : <http://www.semanticweb.org/cocktails#> 
SELECT * 
WHERE { 
    ?Cocktail rdfs:subClassOf :Cocktail. 
    ?Cocktail owl:equivalentClass ?restriction . 
} 

enter image description here

我如何申請例如 「選擇包含JusAnanas和JusOrange所有雞尾酒」

你可以在這裏找到我的本體論:

https://s3-eu-west-1.amazonaws.com/ontologycero/cocktailsOnthology.owl 

我已經已經發現了一個醜陋的請求,但它不可用,因爲我們必須知道使用這種請求的本體。

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX : <http://www.semanticweb.org/cocktails#> 
SELECT * 
WHERE { 
    ?Cocktail rdfs:subClassOf :Cocktail. 
    ?Cocktail owl:equivalentClass ?restriction . 
    ?restriction owl:intersectionOf ?intersection. 
    ?intersection rdf:first ?ingredient1. 
    ?intersection rdf:rest ?rest1. 
    ?rest1 rdf:first ?ingredient2. 
    ?rest1 rdf:rest ?rest2. 
    ?rest2 rdf:first ?ingredient3. 

    ?ingredient1 owl:someValuesFrom :JusAnanas. 
    ?ingredient2 owl:someValuesFrom :JusOrange. 
} 

回答

1

我不確定你在找什麼,但據我所知,你想繞過本體的結構。由於您不知道限制後會發生什麼,因此您可以提及查詢以檢查可能的組合。

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX : <http://www.semanticweb.org/cocktails#> 
SELECT * 
WHERE { 
    ?Cocktail rdfs:subClassOf :Cocktail. 
    ?Cocktail owl:equivalentClass ?restriction . 
    ?restriction (rdfs:subClassOf|(owl:intersectionOf/rdf:rest*/rdf:first))* ?ingredient1. 
    ?restriction (rdfs:subClassOf|(owl:intersectionOf/rdf:rest*/rdf:first))* ?ingredient2. 
    ?ingredient1 owl:someValuesFrom :JusAnanas. 
    ?ingredient2 owl:someValuesFrom :JusOrange. 
    } 
+0

謝謝,但它不工作。你的要求給我所有的雞尾酒包含:JusAnanas OR:JusOrange。我需要含有的雞尾酒:JusAnanas AND:JusOrange – amdev 2015-02-09 21:34:01

+0

如何添加另一種成分。這會比你的更好,我認爲你無論如何都能給出正確的答案。我編輯了我的答案。 – Artemis 2015-02-10 09:47:38

0

SPARQL並不是要理解您設置的正式OWL模型。它是RDF三元組的圖形模式匹配查詢語言。因此,而不是試圖通過模型進行查詢,查詢使用您所設計的模型的語義數據:

SELECT * 
WHERE { 
    ?coctails rdfs:subClassOf* :Cocktail . 
    ?aoCocktail a ?coctails . 
    ?aoCocktail :aPourIngredient :JusAnanas . 
    ?aoCocktail :aPourIngredient :JusOrange . 
} 

前兩個三重模式找到:Cocktail和它的子類的所有成員。最後兩個三重模式查找所有同時具有:JusOrange:JusAnanas的成員作爲屬性:aPourIngredient的值。