SELECT ?w ( SAMPLE( ?v ) AS ?S ) WHERE { ?s ?v . OPTIONAL { ?s ?w . } } GROUP BY ?w