2

我的本体是关于鸡尾酒的。这是一款名为“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意思是菠萝汁

aPourIngredient是一个property意思是“有(包含)成分”

在此处输入图像描述

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

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

2 回答 2

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.
  }
于 2015-02-09T15:39:46.390 回答
0

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

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

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

于 2017-04-04T00:00:06.030 回答