<?xml version="1.0"?>

<rdf:RDF
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:foaf="http://xmlns.com/foaf/0.1/" 
      xmlns:ex="http://example.org/exNS/"
    >
      
<!--

The graph is such as might be extracted from an email program.

The query intends to categorise senders based on the categorisation
of individual messages.
	
PREFIX ex: <http://example.org/exNS/>
SELECT ?mailbox ?category
WHERE
{
   _:a 	ex:sender ?mailbox ;
   		ex:recipient <mailto:alice@example.com> . 
   OPTIONAL {
   	_:a ex:sender ?mailbox;
   	    ex:category ?category .
   }
}


The attached graph describes the email resources, some of which are categorised. 

Section 2.5.3 (and LeeF) allows for _:a to be bound to distinct message resources in 
each location and should therefore always give categories, where present:

?mailbox						?category
<mailto:frederick@example.com>	"Work"
<mailto:frederick@example.com>	"Work"
<mailto:john@example.com> 		"Personal"
<mailto:john@example.com> 		"Personal"
<mailto:boss@example.com>		


Section 2.8.3 does not allow _:a and _:a to be bound to separate message descriptions 
and therefore gives some results with ?category unbound :

?mailbox						?category
<mailto:john@example.com> 		"Personal"
<mailto:john@example.com>
<mailto:frederick@example.com>	"Work"
<mailto:frederick@example.com>
<mailto:boss@example.com>		
	
-->
	
	<foaf:Person>
		<foaf:name>John Smith</foaf:name>
		<foaf:nick>Johnny</foaf:nick>
		<foaf:mbox rdf:resource="mailto:john@example.com" />
	</foaf:Person>
	
	<foaf:Person>
		<foaf:name>Frederick Smith</foaf:name>
		<foaf:nick>Freddy</foaf:nick>
		<foaf:mbox rdf:resource="mailto:frederick@example.com" />
	</foaf:Person>

	<ex:Message>
		<ex:sender rdf:resource="mailto:frederick@example.com" />
		<ex:recipient rdf:resource="mailto:alice@example.com" />
		<ex:category>Work</ex:category>
		<ex:subject>Sales Report</ex:subject>
	</ex:Message>

	<ex:Message>
		<ex:sender rdf:resource="mailto:frederick@example.com" />
		<ex:recipient rdf:resource="mailto:alice@example.com" />
		<ex:subject>Re: Sales Report</ex:subject>
	</ex:Message>

	<ex:Message>
		<ex:sender rdf:resource="mailto:john@example.com" />
		<ex:category>Personal</ex:category>
		<ex:recipient rdf:resource="mailto:alice@example.com" />		
		<ex:subject>Gig tonight</ex:subject>
	</ex:Message>

	<ex:Message>
		<ex:sender rdf:resource="mailto:john@example.com" />
		<ex:recipient rdf:resource="mailto:alice@example.com" />
		<ex:subject>Re: Gig tonight</ex:subject>
	</ex:Message>
	
	<ex:Message>
		<ex:sender rdf:resource="mailto:boss@example.com" />
		<ex:recipient rdf:resource="mailto:alice@example.com" />
		<ex:subject>Get back to work!</ex:subject>
	</ex:Message>

</rdf:RDF>


