Rdf SPARQL查询中的使用条件

Rdf SPARQL查询中的使用条件,rdf,sparql,Rdf,Sparql,我有一个SPARQL查询,如下所示- SELECT ?informationPath ?businessEntitylabel ?path ?sourced ?mastered ?delivered WHERE { ?businessEntity dd:hasPropertyPath ?informationPath . ?businessEntity rdfs:label ?businessEntitylabel . ?informationPath dd:hasPath ?path . OP

我有一个SPARQL查询,如下所示-

SELECT ?informationPath ?businessEntitylabel ?path ?sourced ?mastered ?delivered
WHERE {
?businessEntity dd:hasPropertyPath ?informationPath .
?businessEntity rdfs:label ?businessEntitylabel .
?informationPath dd:hasPath ?path .
OPTIONAL {
?informationPath a dd:SourcedData .
BIND("Yes" as ?sourced)
}
OPTIONAL {
?informationPath a dd:MasteredData .
BIND("Yes" as ?mastered)
}
OPTIONAL {
?informationPath a dd:DeliveredData .
BIND("Yes" as ?delivered)
}
} ORDER BY ?businessEntitylabel ?path
现在,我只想有一列,而不是“来源”或“掌握”或“交付”,名称是“可追溯性”。该列将显示信息路径是主数据还是源数据或交付数据,因此我希望绑定(“源数据”作为“可追溯性”)或(“主数据”作为“可追溯性”)或(“交付数据”作为“可追溯性”)

我是SPARQL的新手,我想知道SPARQL中是否有任何“if”语句可以用作-

if(?informationPath a dd:SourcedData)
BIND("SourcedData" as ?traceability)
任何帮助都将不胜感激。

使用
bind
if
我认为这是的一个副本,并且我已经将其标记为这样,但是如果
if
中的条件应该是什么,可能还不太清楚,所以我添加了这个示例作为答案。假设您有以下表单的数据:

@prefix : <https://stackoverflow.com/q/22985157/1281433/> .

:x1 a :A .
:x2 a :B .
:x3 a :C .
:x4 a :D .
使用
它使用
if
exists
构造来检查各种值。现在,在您的案例中,如果您有特定数量的案例需要检查,您实际上可以使用
来模拟一种
案例
语句。要做到这一点,你可以这样做,虽然这不会给你一个“未知”的情况


要扩展Joshua Taylor的答案,您实际上还可以处理默认情况,这要感谢UNDEF关键字:

prefix : <http://stackoverflow.com/q/22985157/1281433/>

select ?x ?typename where { 
  values (?type ?typename) { 
    (:A "type A")
    (:B "type B")
    (:C "type C")
    (UNDEF "unknown type")
  }
  ?x a ?type
}
前缀:
选择?x?typename,其中{
值(?type?typename){
(:A类)
(:B“B类”)
(:C“C类”)
(未定义“未知类型”)
}
?x a?型
}

SPARQL的可能副本确实有一个
if
操作符,并且在规范中有明确的描述。在您的情况下,您可以执行
bind(if(…,“sourceed,if(…,“Delivered”,if(…,“Mastered”,“Unknown”))之类的操作作为可追溯性)
------------------------
| x   | typename       |
========================
| :x1 | "type A"       |
| :x2 | "type B"       |
| :x3 | "type C"       |
| :x4 | "unknown type" |
------------------------
prefix : <https://stackoverflow.com/q/22985157/1281433/>

select ?x ?typename where { 
  values (?type ?typename) { 
    (:A "type A")
    (:B "type B")
    (:C "type C")
  }
  ?x a ?type
}
------------------
| x   | typename |
==================
| :x1 | "type A" |
| :x2 | "type B" |
| :x3 | "type C" |
------------------
prefix : <http://stackoverflow.com/q/22985157/1281433/>

select ?x ?typename where { 
  values (?type ?typename) { 
    (:A "type A")
    (:B "type B")
    (:C "type C")
    (UNDEF "unknown type")
  }
  ?x a ?type
}