prefix obo: <http://purl.obolibrary.org/obo/> 
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?x ?p ?y
WHERE {
  {?x rdfs:subClassOf [
    a owl:Restriction ;
    owl:onProperty ?p ;
    owl:someValuesFrom ?y ] 
  }
  UNION {
   ?x rdfs:subClassOf ?y .
   BIND(rdfs:subClassOf AS ?p)
  }
  ?x a owl:Class .
  ?y a owl:Class .
}
