Sparql query on restriction list (Equivalent To) in protégé

余生长醉 提交于 2019-11-28 05:34:51

问题


My ontology is about Cocktail. This is a cocktail named "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 means Orange juice JusAnanas means Pineapple juice

aPourIngredient is a property which means "has(contain) the ingredient"

This is the request which list all my cocktails with theirs rectrictions

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

How can I request for example "select all cocktail which contains JusAnanas AND JusOrange"

You can find my ontology here :

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

I've already found an ugly request, but it's not usable because we have to know the ontology for use this kind of request.

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:


I am not sure what you are looking for, but as far as I understand you want to bypass the structure of the ontology. Since you don't know what comes after restriction, you can mention to the query to check wall the possible combinations.

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



回答2:


SPARQL isn't meant to understand the formal OWL model you've set up. It's a graph pattern matching query language for RDF triples. So instead of trying to query through the model, query the data using the semantics of the model you've designed:

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

The first two triple patterns find all member of :Cocktail and its subclasses. The last two triple patterns find all members that have both :JusOrange and :JusAnanas as values for the property :aPourIngredient.



来源:https://stackoverflow.com/questions/28396707/sparql-query-on-restriction-list-equivalent-to-in-prot%c3%a9g%c3%a9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!