← every query · class 09 · queries/filters-optionals-negation.rq

Filters, optionals and negation

The same answer in both regimes: this query asks only for what was written.

?name?price?discount
"Wireless optical mouse"@en"29.90"^^xsd:decimal—
"Mechanical keyboard"@en"49.90"^^xsd:decimal—

The query

# Filters, optionals and negation (slide "Filters, optionals and negation").
# Note: the price lives in the offer (schema:offers/schema:price), as the class
# 06 graph models it and as the slide writes it. Writing ?p schema:price ?price
# directly on the product matches nothing in this graph — which is what example
# 01 shows, as the first case of an "empty query".
PREFIX schema: <https://schema.org/>
PREFIX onto:   <https://data.csoares.me/onto#>

SELECT ?name ?price ?discount
WHERE {
  ?p a onto:Product ;
     schema:name ?name ;
     schema:offers/schema:price ?price .

  # whatever may not exist goes in OPTIONAL
  OPTIONAL { ?p onto:discount ?discount }

  # condition on values
  FILTER (?price > 20 && ?price <= 100)
  FILTER (LANG(?name) = "en")
}
ORDER BY ?price

Edit it in the query box →