← every query · class 09 · queries/q5-products-sharing-components.rq

Q5 · Which products share components with product 17?

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

?other?name?component
product:23"Optical mouse"@encomponent:blue-switch
product:23"Optical mouse"@encomponent:spring
product:88"27-inch monitor"@encomponent:usb-c-cable

The query

# Q5. Which products share components with product 17?
# hasPart+ on both sides: a component of a component counts too, so a product
# that contains the same switch also shares the spring inside it — a fact
# nobody wrote down.
PREFIX schema:  <https://schema.org/>
PREFIX onto:    <https://data.csoares.me/onto#>
PREFIX product: <https://data.csoares.me/product/>

SELECT DISTINCT ?other ?name ?component
WHERE {
  product:17 onto:hasPart+ ?component .
  ?other onto:hasPart+ ?component ;
         schema:name ?name .
  # product:17 shares every component with itself: leave it out
  FILTER (?other != product:17)
  FILTER (LANG(?name) = "en")
}
ORDER BY ?other ?component

Edit it in the query box →