PREFIX :
PREFIX rdf:
SELECT count(distinct ?p)
{
# UNION is asymmetric in what it generates
{ ?x rdf:type :X . } UNION { ?x rdf:type :X . FILTER (?x != :x2 )}
# and :x2 :p 2 with ":p 2" occuring twice.
OPTIONAL { ?x :p ?p . }
OPTIONAL { ?x :n ?n . }
}