Learn more
- Jun 26, 2015
Using SPARQL clause VALUES in PoolParty

E.g. when you want to know which cocktails you can create with Gin and a highball glass you can go to http://vocabulary.semantic-web.at/PoolParty/sparql/cocktails and fire this query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>PREFIX co: <http://vocabulary.semantic-web.at/cocktail-ontology/>SELECT ?cocktailLabelWHERE { ?cocktail co:consists-of ?ingredient ; co:uses ?drinkware ; skos:prefLabel ?cocktailLabel . ?ingredient skos:prefLabel ?ingredientLabel . ?drinkware skos:prefLabel ?drinkwareLabel . FILTER (?ingredientLabel = "Gin"@en && ?drinkwareLabel = "Highball glass"@en )} |
When you want to add additional pairs of ingredients and drink ware you want to filter in combination the query gets quite clumsy. Wrongly placed braces can break the syntax. In addition, when writing complicated queries you easily insert errors, e.g. by mixing boolean operators which results in wrong results…
...FILTER ((?ingredientLabel = "Gin"@en && ?drinkwareLabel = "Highball glass"@en ) || (?ingredientLabel = "Vodka"@en && ?drinkwareLabel ="Old Fashioned glass"@en ))} |
Using VALUES can help in this situation. For example this query shows you how to filter both pairs Gin+Highball glass and Vodka+Old Fashioned glass in a neat way:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>PREFIX co: <http://vocabulary.semantic-web.at/cocktail-ontology/>SELECT ?cocktailLabelWHERE { ?cocktail co:consists-of ?ingredient ; co:uses ?drinkware ; skos:prefLabel ?cocktailLabel . ?ingredient skos:prefLabel ?ingredientLabel . ?drinkware skos:prefLabel ?drinkwareLabel .}VALUES ( ?ingredientLabel ?drinkwareLabel ){ ("Gin"@en "Highball glass"@en) ("Vodka"@en "Old Fashioned glass"@en)} |
Especially when you create SPARQL code automatically, e.g. generated by a form, this clause can be very useful.