How to make a class label shown as the column name of the class?

笑着哭i 提交于 2019-12-05 20:00:36

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 .

Here are the query and results:

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"                    |
----------------------------
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!