如何使类标签显示为类的列名? [英] How to make a class label shown as the column name of the class?

查看:38
本文介绍了如何使类标签显示为类的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SPARQL

SELECT ?c0 ?l0
WHERE 
{ 
  ?c0 rdf:type <XXXX>.
  OPTIONAL
  {
    ?c0 rdfs:label ?l0.
  }
}

显示两列 c0l0.有什么办法只显示一列 c0,但将 ?l0 的内容作为 ?c0 的标题?结果看起来像 select ?co as ...

shows two columns c0 and l0. Any way to show only one column c0,but with the content of the ?l0 as the title of the ?c0 ? The result would look like select ?co as ...

推荐答案

如果我理解正确,您可以使用 coalesce 来实现,它返回它的第一个非错误绑定参数.首先,这里有一些数据,其中有一个带有标签 "Dog" 的类 :dog 和一个没有标签的类 :cat:

If I understand you correctly, you can do this with coalesce, which returns its first non-error bound argument. First, here's some data where there's a class :dog with the label "Dog", and a class :cat which has no label:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://example.org/> .

:dog a rdfs:Class ;
     rdfs:label "Dog" .
:cat a rdfs:Class .

这里是查询和结果:

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select (coalesce(?label,?class) as ?co) where {
  ?class a rdfs:Class
  optional {
    ?class rdfs:label ?label
  }
}

----------------------------
| co                       |
============================
| <http://example.org/cat> |
| "Dog"                    |
----------------------------

这篇关于如何使类标签显示为类的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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