我想构造一个 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 子句,这意味着我无法指定要注入(inject)到结果集中的 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)
}
}
关于sparql - 在 SPARQL 中选择文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37189315/