SPARQL question— is it possible to do a COUNT command on the union of two restrictions? Here is the query syntax.
No. The result isn’t giving me what I expect. One query solo gives me 156, the other solo 190. When I run them as a Union, I get 156. Given that, I feel like I should get a different number.
I do not see the closing brackets, could be the source of error. My guess is that ?x is always bound in the first UNION and thus you would need to reformulate to use OPTIONAL instead of UNION and move ?x rdf:type ?restriction outside
Thank you! I’ll try this.
Unfortunately, this didn’t work but I think it’s because of the issue on our end. The classes in question have a class/subclass relationship. So I think I’ll have to try something else… but I think this works if classes are sibling classes.
Why are you trying to use this query, rather than simply:
SELECT (COUNT(DISTINCT ?x) AS ?nox)
WHERE {
VALUES ?topClass {gfo:itemOne gfo:itemTwo}
?x gfo:involves/rdf:type ?topClass
}Or also:
SELECT (COUNT(DISTINCT ?x) AS ?nox)
WHERE {
{?x gfo:involves/rdf:type gfo:itemOne}
UNION
{?x gfo:involves/rdf:type gfo:itemTwo}
}Thank you. I’ll try this next time…
Did you end up finding another solution or just gave up?
I found a workaround.