SPARQL 中的条件构造
Conditional construct in SPARQL
我想知道是否可以有条件地创建构造子句的某些部分。例如假设我们有以下构造查询:
Construct {-:a a <smth:classtype>.
-:a <smth:attr> ?b} WHERE
{?c a <smth:anotherCalss>.
Optional{?c <smth:anotherAttr> ?b}}
在这种情况下,?b 并不总是绑定到 smth。我只想创建一个空白节点 -:a 如果 ?b 是有界的。有没有办法在sparql的construct子句中加入这样的条件?
您可以在 WHERE 子句中有条件地创建 bnode,方法是将它放在 OPTIONAL 中:
CONSTRUCT {?BN a <smth:classtype>.
?BN <smth:attr> ?b}
WHERE
{?c a <smth:anotherCalss>.
Optional
{?c <smth:anotherAttr> ?b
BIND(BNODE()AS ?BN)
}
}
我想知道是否可以有条件地创建构造子句的某些部分。例如假设我们有以下构造查询:
Construct {-:a a <smth:classtype>.
-:a <smth:attr> ?b} WHERE
{?c a <smth:anotherCalss>.
Optional{?c <smth:anotherAttr> ?b}}
在这种情况下,?b 并不总是绑定到 smth。我只想创建一个空白节点 -:a 如果 ?b 是有界的。有没有办法在sparql的construct子句中加入这样的条件?
您可以在 WHERE 子句中有条件地创建 bnode,方法是将它放在 OPTIONAL 中:
CONSTRUCT {?BN a <smth:classtype>.
?BN <smth:attr> ?b}
WHERE
{?c a <smth:anotherCalss>.
Optional
{?c <smth:anotherAttr> ?b
BIND(BNODE()AS ?BN)
}
}