One way of doing this would be with a GROUP BY clause combined with a SAMPLE aggregate:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT (sql:SAMPLE(?name) AS ?Name) (MIN(?birth) AS ?birthDate)
{
?person <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:American_television_actors> .
{ ?person dbo:birthDate ?birth }
UNION
{ ?person dbpedia2:birthdate ?birth. }
?person foaf:name ?name.
FILTER( REGEX( STR(?birth),"[0-9]{4}-[0-9]{2}-[0-9]{2}"))
}
GROUP BY ?person
What this query does is group by the URI of the person which is the same regardless of how many different forms of their name are present in DBPedia and then uses SAMPLE to pick just one possible name from the group.
When using GROUP BY you can only project either the group variables (so in this case ?person) or aggregates over these groups (in this case SAMPLE and MIN)
Note - Because Virtuoso does not strictly follow the SPARQL 1.1 standard you have to prefix SAMPLE with their special prefix sql: in order for this to work
answered
03 Oct '11, 04:06
Rob Vesse ♦
11.9k●6●15
accept rate:
28%