Re: Sparql query help

Hi Samuel,

If you are using a SPARQL engine that doesn't speak OWL natively, you 
have to write your query against the raw RDF triples that encode your 
OWL model. In your case, this would look something like:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX plate: <http://www.owl-ontologies.com/testFood2.owl#">
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?ingredients
WHERE {
   plate:ChickenWithTomato rdfs:subClassOf [
     owl:onProperty plate:hasIngridients ;
     owl:someValuesFrom ?ingredients
   ]
}

(Warning, as always, untested query, but hopefully it helps!)

Lee


Samuel Pedro wrote:
> I changed the ontology, have now this class,
> 
> <owl:Class rdf:ID="ChickenWithOnions">
>     <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>     >Chicken With Onions</rdfs:label>
>     <rdfs:subClassOf>
>       <owl:Restriction>
>         <owl:someValuesFrom rdf:resource="#Onion"/>
>         <owl:onProperty rdf:resource="#hasIngridients"/>
>       </owl:Restriction>
>     </rdfs:subClassOf>
>     <rdfs:subClassOf>
>       <owl:Restriction>
>         <owl:onProperty rdf:resource="#hasIngridients"/>
>         <owl:someValuesFrom rdf:resource="#Chicken"/>
>       </owl:Restriction>
>     </rdfs:subClassOf>
>     <rdfs:subClassOf>
>       <owl:Class rdf:about="#Plates"/>
>     </rdfs:subClassOf>
>   </owl:Class>
> 
> If i want to know which ingredients have the plate "Chicken with Onions"?
> Shouldn´t be...
> 
> PREFIX owl:<http://www.w3.org/2002/07/owl#>
> PREFIX plate:<http://www.owl-ontologies.com/testFood2.owl#">
> SELECT ?ingredients
> 
> WHERE { ?ingredients owl:someValuesFrom plate:ChickenWithTomato } --> 
> (how do you read this?)
> 
> what's wrong this time?
> 
> 2009/6/12 Paul Gearon <gearon@ieee.org <mailto:gearon@ieee.org>>
> 
>     On Fri, Jun 12, 2009 at 1:31 PM, Samuel Pedro<samuelcpspam@gmail.com
>     <mailto:samuelcpspam@gmail.com>> wrote:
>      > So i can only do queries using properties like owl:sameAS,
>     :differentFrom,
>      > :subClass, transitive..... to object like  rdfs:label, and... ?x 
>     ????
> 
>     No, there is no restriction of this type.
> 
>      > I have this class in the ontology,that have the property
>     someValues can i do
>      > a query that ask wich are the ingredients that
>     "ChickenWithOnions" have?
>      >
>      > <owl:Class rdf:ID="ChickenWithOnions">
>      >     <rdfs:label
>     rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>      >     >Chicken With Onions</rdfs:label> (add the label)
>      >     <rdfs:subClassOf rdf:resource="#Plates"/>
>      >     <rdfs:subClassOf>
>      >       <owl:Restriction>
>      >         <owl:onProperty rdf:resource="#hasIngridients"/>
>      >         <owl:someValuesFrom>
>      >           <owl:Class>
>      >             <owl:intersectionOf rdf:parseType="Collection">
>      >               <owl:Class rdf:about="#Chicken"/>
>      >               <owl:Class rdf:about="#Onion"/>
>      >             </owl:intersectionOf>
>      >           </owl:Class>
>      >         </owl:someValuesFrom>
>      >       </owl:Restriction>
>      >     </rdfs:subClassOf>
>      >   </owl:Class>
> 
>     This model isn't doing what you think it is. It says that some of the
>     ingredients come from something that is both a chicken and an onion. I
>     know that Monsanto have been doing some rather avant-garde research
>     into genetic engineering of food, but I think they have still come
>     short of this.
> 
>     What I think you were looking for was a Plate that is a subclass of
>     the intersection of "things with some ingredients that are chicken"
>     and "things with some ingredients that are onion".
> 
>      > the query should be this... (wrong tried and nothing, i'm doing
>     again the
>      > same mistake right?)
>      >
>      > SELECT ?plate ?ingredient
>      > WHERE {
>      >  ?plate owl:hasIngridients ?ingredient.
>      >  ?plate rdfs:label "Chicken With Onions" .
>      > }
>      >
>      > so the only property that i can use is the ones that says
>     "rdfs:...."  ???
> 
>     Not at all. It's just that the data didn't say what you thought it
>     did. Also, there is no "hasIngredients" predicate in the OWL
>     namespace. Perhaps you should define it as food:hasIngredients.
> 
>     Actually, queries are a pretty good way to find what you want, without
>     needing to define plates of "Chicken with Onions".
> 
>     SELECT ?plate ?ingredient
>     WHERE {
>      ?plate food:hasIngredients ?ingredient .
>      ?plate food:hasIngredients food:Chicken .
>      ?plate food:hasIngredients food:Onion .
>     }
> 
>     This will return a list of all the plates and their ingredients, where
>     the plates are restricted to only those that have both Chicken and
>     Onion in their ingredients. Of course, both Chicken and Onion will
>     show up in the list for each plate, as will all of the other
>     ingredients.
> 
>     Regards,
>     Paul
> 
> 
> -- 
> --
> Samuel Pedro

Received on Sunday, 14 June 2009 01:27:32 UTC