user2831591
user2831591

Reputation: 53

Get URI in results of dbpedia SPARQL query

I have a list of dbpedia URI's and I want to get some informations (categories, label) about each of them in one query:

SELECT ?category ?label where {
    {
        dbpedia:Financial_Times dcterms:subject ?category .
        dbpedia:Financial_Times rdfs:label ?label .
        FILTER ( lang(?label) = 'en' )
    }
    UNION
    {
        dbpedia:London dcterms:subject ?category .
        dbpedia:London rdfs:label ?label .
        FILTER ( lang(?label) = 'en' )
    }
}

This query works fine, but I'd need to add the URI's themself into the result to be able identify which result row is for which URI.

Upvotes: 0

Views: 491

Answers (1)

dvcama
dvcama

Reputation: 81

you can do something like

SELECT distinct ?who  ?category ?label where {
{
    ?who dcterms:subject ?category .
    ?who rdfs:label ?label .
    FILTER ( lang(?label) = 'en' ).
    FILTER(?who =  dbpedia:Financial_Times or ?who =  dbpedia:London )
}}

or use a trick like this

 SELECT ?who  ?category ?label where {
{
    dbpedia:Financial_Times dcterms:subject ?category .
    dbpedia:Financial_Times rdfs:label ?label .
    FILTER ( lang(?label) = 'en' ).
    VALUES ?who { dbpedia:Financial_Times}

}
UNION
{
    dbpedia:London dcterms:subject ?category .
    dbpedia:London rdfs:label ?label .
    FILTER ( lang(?label) = 'en' ) . 
    VALUES ?who { dbpedia:London }
}}

the second one probably is faster but needs SPARQL 1.1

Upvotes: 1

Related Questions