2016-05-12 22 views
2

我想構建一個SPARQL查詢,其中填入了我設置爲文字的值。在SPARQL中選擇文字?

例如

SELECT 'A', 'B', attribute 
FROM 
    TABLE 

將返回一個表可能看起來像這樣的:

A | B | attribute 
-------|---------|-------------- 
    A | B | Mary 
    A | B | has 
    A | B | a 
    A | B | little 
    A | B | lamb 

我想要做的是運行一個像這樣的查詢來獲取所有的對象類型的triplestore:

select distinct ?o ("class" as ?item_type) 
where { 
    ?s rdf:type ?o. 
} 

然後(理想情況下)UNION它與第二個查詢,拉出所有不同的謂詞值:

select distinct ?p ("predicate" as ?item_type) 
where { 
    ?s ?p ?o. 
} 

其結果可能是:

item   | item_type  
-----------------|----------------- 
a_thing   | class 
another_thing | class 
a_relation  | predicate 
another_relation | predicate 

但在SPARQL一個聯盟額外的where子句中,這意味着我不能指定ITEM_TYPE文字我希望注入我的結果只能鏈接組。

+0

你的意思是'(? 「對象」 作主語)'?這仍然是一種相當古怪的說法。也許你想說'(「class」爲?item_type)'和'(「謂詞」爲?item_type)'? – scotthenninger

+0

是的,這是一個更清潔的方式。我會修改。 –

回答

4

我認爲有以下應該得到你想要的東西:

SELECT DISTINCT ?item ?item_type 
WHERE { 
    { ?s a ?item . 
    BIND("class" AS ?item_type) 
    } 
    UNION 
    { ?s ?item ?o 
    BIND("predicate" AS ?item_type) 
    } 

}

+0

啊,所以*那*是什麼綁定 - 好極了 - 非常感謝你:) –