【问题标题】:Sparql query on restriction list (Equivalent To) in protégéSparql 查询 protégé 中的限制列表(等效于)
【发布时间】:2015-02-08 16:59:10
【问题描述】:

我的本​​体是关于鸡尾酒的。这是一款名为“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,意思是“有(包含)成分”

这是列出我所有的鸡尾酒及其限制的请求

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

我如何请求例如“选择所有包含 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.
}

【问题讨论】:

    标签: sparql owl protege rdfs pellet


    【解决方案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.
      }
    

    【讨论】:

    • 谢谢,但它不起作用。您的要求给我所有包含:JusAnanas 或:JusOrange 的鸡尾酒。我需要含有 :JusAnanas 和 :JusOrange 的鸡尾酒
    • 添加另一种成分怎么样。它会比你的好一点,而且我不认为你给出了正确的答案。我编辑了我的答案。
    【解决方案2】:

    SPARQL 并不是为了理解您设置的正式 OWL 模型。它是一种用于 RDF 三元组的图形模式匹配查询语言。因此,不要尝试通过模型进行查询,而是使用您设计的模型的语义来查询数据:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-20
      • 2014-08-15
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      相关资源
      最近更新 更多