在protégé中对限制列表(等效于)的Sparql查询

时间:2015-02-08 16:59:11

标签: sparql owl protege rdfs pellet

我的本​​体论是关于鸡尾酒的。这是一种名为" AfterGlow"

的鸡尾酒
<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,表示&#34;包含(#)成分&#34;

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

我如何请求例如&#34;选择所有包含JusAnanas和JusOrange的鸡尾酒&#34;

你可以在这里找到我的本体:

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.
}

2 个答案:

答案 0 :(得分: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.
  }

答案 1 :(得分:0)

SPARQL并不意味着要了解您已设置的正式OWL模型。它是匹配RDF三元组的查询语言的图形模式。因此,不是试图通过模型查询,而是使用您设计的模型的语义来查询数据:

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

前两个三元模式查找:Cocktail及其子类的所有成员。最后两个三元模式查找将:JusOrange:JusAnanas同时作为属性:aPourIngredient的值的所有成员。

相关问题