繁体   English   中英

在SPARQL中选择文字?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM