If I have a SPARQL query say,
PREFIX foaf <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?x foaf:name ?name.
?x foaf:knows ?y.
}
to select the name of some x, who knows some y. How could I select only the names of those people who know exactly 3 other people (or any other number)?
Also, as a side question – is there a better title for this question? One which uses better terminology to clarify the problem?
Thanks
You could achieve that with SPARQL 1.1 and it new features: GROUP BY, HAVING and SUBQUERIES. Something like this would do the job:
Unfortunately not all SPARQL engines support all these features together. That I know Jena/ARQ and Virtuoso support them.
If you are working with an SPARQL engine that doesn’t support these features then I recommend to run the query:
… and programatically compute the rest of the logic that you need in the query with few lines of client-side code.