SPARQL 为缺失的字段生成值 [英] SPARQL generate Values for missing fields

查看:44
本文介绍了SPARQL 为缺失的字段生成值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 SELECT,它为我提供了表中的所有值.我有可选值,如果它们不存在,我希望用标准值填充它们.

I´m trying to write a SELECT, that gives me all the Values in a Table. I have optional Values, I want those to be filled with a standard value, If they don´t exist.

这是我的代码:

SELECT * WHERE {
?a nmo:hasObject nm:coin 
OPTIONAL
{ ?a nmo:hasAuthority ?b }
OPTIONAL
{ ?a nmo:hasMaterial ?c }}

我得到的 id 如下:

What I get id the following:

?a ?b ?c
1  yx 
2     ab
3  xz bc

如果没有值,我想要的是用字符串missing"填充它:

What I want is to fill it up with the String "missing" if there is no value:

?a ?b        ?c
1  yx        "missing"
2  "missing"  ab
3  xz         bc

关于如何构造 SELECT 以获得此输出的任何想法?

Any ideas on how to structure the SELECT to get this output?

推荐答案

我可能会使用 合并在这里:

I'd probably use coalesce here:

SELECT
  ?a
  (coalesce (?b, ?missing) as ?bb)
  (coalesce (?c, ?missing) as ?cc)
WHERE {
  VALUES ?missing { "missing" }
  ?a nmo:hasObject nm:coin 
  OPTIONAL
  { ?a nmo:hasAuthority ?b }
  OPTIONAL
  { ?a nmo:hasMaterial ?c }
}

这篇关于SPARQL 为缺失的字段生成值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆