[英]Select literal in 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
我想做的是運行這樣的查詢,以在三元組中獲取所有對象類型:
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中的UNION僅鏈接附加的where子句,這意味着我無法指定要注入到結果集中的item_type文字。
我認為以下內容將為您提供所需的服務:
SELECT DISTINCT ?item ?item_type
WHERE {
{ ?s a ?item .
BIND("class" AS ?item_type)
}
UNION
{ ?s ?item ?o
BIND("predicate" AS ?item_type)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.