2014-09-24 130 views
0

的結果獲取URI我的DBpedia的URI的名單,我想獲得他們每個人的一些信息(類別,標籤)在一個查詢:在DBpedia中的SPARQL查詢

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') 
    } 
} 

此查詢工作正常,但我需要將URI自己添加到結果中,以便能夠識別哪個結果行用於哪個URI。

回答

1

,你可以這樣做

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) 
}} 

或使用這樣

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 } 
}} 

一招,第二個可能是快,但需要SPARQL 1.1