Task
In my triple store I have a resource type address. Resources of this type of email have a sender and one or more recipients.
Let the designation "A-> B" be defined as "A is the sender of the email for which B is one of the recipients."
Now I would like to know the following: How many times has a person sent an email to person B? Note that the roles of A and B are important, i.e. A-> B is different from B-> A.
Formatted SPARQL query
To answer this question for all available pairs, I wrote this SPARQL (1.1) query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX email: <http://example.com/schema/for/email/> SELECT ?sender ?recipient (COUNT(?sender ?recipient) AS ?count) WHERE { ?sender rdf:type foaf:Person. ?recipient rdf:type foaf:Person. ?e rdf:type email:Email. ?e email:sender ?sender. ?e email:recipient ?recipient. } GROUP BY ?sender ?recipient
This does not work, AllegroGraph gives me the MALFORMED QUERY: Line 5, Found ?recipient (of type varname) error MALFORMED QUERY: Line 5, Found ?recipient (of type varname) - line 5, which is a SELECT clause. I tried other options, changing the SELECT and / or GROUP BY clause, but to no avail.
I'm not sure if aggregates are allowed on multiple resources. In the SPARQL 1.1 documents and the related SO question ( Counting in SPARQL ), I found only aggregates based on one resource.
So finally, here is my question: is it possible to aggregate the sender and receiver?
source share