[英]Select literal in SPARQL?
I want to construct a SPARQL query populated with values I'm setting as literals. 我想构造一个SPARQL查询,该查询填充有我设置为文字的值。
eg 例如
SELECT 'A', 'B', attribute
FROM
TABLE
Would return a table that might look like this: 将返回一个可能如下所示的表:
A | B | attribute
-------|---------|--------------
A | B | Mary
A | B | has
A | B | a
A | B | little
A | B | lamb
What I want to do is run a query like this to get all the object types in a triplestore: 我想做的是运行这样的查询,以在三元组中获取所有对象类型:
select distinct ?o ("class" as ?item_type)
where {
?s rdf:type ?o.
}
and then (ideally) UNION it with a second query that pulls out all the distinct predicate values: 然后(理想情况下)使用第二个查询将其UNION,以提取所有不同的谓词值:
select distinct ?p ("predicate" as ?item_type)
where {
?s ?p ?o.
}
the results of which might look like: 结果可能如下所示:
item | item_type
-----------------|-----------------
a_thing | class
another_thing | class
a_relation | predicate
another_relation | predicate
But a UNION in SPARQL only links in an additional where clause, which means I can't specify the item_type literal I want to inject into my results-set. 但是SPARQL中的UNION仅链接附加的where子句,这意味着我无法指定要注入到结果集中的item_type文字。
I think the following should get you what you want: 我认为以下内容将为您提供所需的服务:
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.