rdf - 如何使类标签显示为类的列名?

标签 rdf sparql

SPARQL

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

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

最佳答案

如果我没理解错的话,您可以使用 coalesce 来完成此操作,它会返回其第一个非错误绑定(bind)参数。首先,这里有一些数据,其中有一个带有标签 "Dog" 的类 :dog 和一个没有标签的类 :cat:

@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"                    |
----------------------------

关于rdf - 如何使类标签显示为类的列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26114572/

相关文章:

python - 如何将 Pandas DataFrame 转换为 RDF(资源描述框架)?

html - 使用 SPARQL 从 HTML 页面查询元数据不返回任何内容

sparql - 将 Freebase 导入 Triplestore

java - 使用不同程序但具有不同结果的相同 Sparql

java - RDF-Gravity 1.0 - 无法启动应用程序

sql - SPARQL 查询,选择除匹配项之外的所有内容?

apache - Pubby 显示问号而不是实际的命名空间

sparql - DELETE WHERE 查询中的可选三元组

java - 耶拿 : Create a single Statement based on a String object

python - RDF/XML rdflib : Invalid property element URI