简体   繁体   English

SPARQL中的条件构造

[英]Conditional construct in SPARQL

I was wondering if it is possible to conditionally create some part of the construct clause. 我想知道是否有可能有条件地创建构造子句的某些部分。 For instance assume we have the following construct query: 例如,假设我们有以下构造查询:

Construct {-:a a <smth:classtype>.
           -:a <smth:attr> ?b} WHERE
          {?c a <smth:anotherCalss>.
           Optional{?c <smth:anotherAttr> ?b}}

In this case ?b is not always bounded to smth. 在这种情况下,?b并不总是与smth有关。 I want to only create a blank node -:a if ?b is bounded. 我想只创建一个空白节点 - :if?b是有界的。 Is there a way to add such conditions in the construct clause of sparql? 有没有办法在sparql的construct子句中添加这样的条件?

You can create the bnode conditionally in the WHERE clause by putting it inside the OPTIONAL: 您可以通过将其放在OPTIONAL中来有条件地在WHERE子句中创建bnode:

CONSTRUCT {?BN a <smth:classtype>.
           ?BN <smth:attr> ?b}
WHERE
          {?c a <smth:anotherCalss>.
            Optional
              {?c <smth:anotherAttr> ?b
               BIND(BNODE()AS ?BN)
              }
           }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM