Reputation: 3271
I have the following query:
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 rec:<http://www.receta.org#>
SELECT ?r (count(distinct ?Ingrediente) as ?oi) {
?r rec:Ingrediente ?Ingrediente.
filter not exists {
?r rec:Ingrediente ?other_ingredient
filter( ?other_ingredient not in ( rec:Aceite, rec:Cebolla ) )
}
}
GROUP BY ?r
order by (count(distinct ?Ingrediente))
And I get this:
?r ?oi
Recipe1 1
Recipe2 2
I would like to get something like this:
?r ?oi ?PreparationMode ?IngredientList
Recipe1 1 First, you have to.. ing1, ing2, ing3...
Recipe2 2 First, you have to.. ing1, ing2, ing3...
I tried to do this:
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 rec:<http://www.receta.org#>
SELECT ?r (count(distinct ?Ingrediente) as ?oi) ?mo ?sa{
?r rec:Ingrediente ?Ingrediente.
?m rdf:type rec:ModoPreparacion.
?m rdfs:label ?mo.
?s rdf:type rec:ListaIngredientes.
?s rdfs:label ?sa.
filter not exists {
?r rec:Ingrediente ?other_ingredient
filter( ?other_ingredient not in ( rec:Aceite, rec:Cebolla ) )
}
}
GROUP BY ?r ?mo ?sa
order by (count(distinct ?Ingrediente))
But I get the recipe name multiply lots of times and I dont know how to fix that. Any idea? Thanks!!!!
This is the DDBB structure:
Each recipe has ingredients and a preparation mode:
Each preparation mode has a label with a description:
And each ingredient list has a label with other description:
And also here is the protégé ddbb:
http://webprotege.stanford.edu/#Edit:projectId=bb11a09e-29f5-47c5-b2f9-a81c3a88aa9d5
Upvotes: 0
Views: 44
Reputation: 85843
There's no connection between the variables ?r and ?m:
?r rec:Ingrediente ?Ingrediente.
?m rdf:type rec:ModoPreparacion.
This says "find (a recipe) ?r with an ingredient ?Ingrediente and an ?m with type rec:ModoPreparacion." That means that you find every possible combination. Compare with data like:
:John a :Person; :hasAge 30 .
:Bill a :Person; :hasAge 35 .
If you write a query like
select ?person ?age {
?person a :Person .
?y :hasAge ?age .
}
You'll get four rows in your results:
John 30
Bill 30
John 35
Bill 35
Upvotes: 3