为什么这个变量永远没有值 [英] why this variable is never have a value

查看:83
本文介绍了为什么这个变量永远没有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查实例是否具有用于特定谓词的值,将该值绑定到特定变量,否则,将该变量绑定到整数类型的值1.这是我的代码

I am checking that if an instance has a value for a specific predicate, bound that value to a specific variable, otherwise, bound that variable to the value 1 of type integer. this is my code

select ?boosted where {
    :r1 a ?x
  optional
  {
    ?item rs:boostedBy ?boostedOptional
      bind (if(bound(?boostedOptional), ?boostedOptional, "1"^^xsd:integer) as ?boosted)
  }
}

"boosted"的值始终为空,请查看

the value of ?boosted is always empty, look please

为什么请?

我认为您不需要数据来测试为什么我的代码无法正常工作,因为对我来说,这听起来像是使用绑定的普遍错误.但是,如果您需要数据,我会给您数据.

I think you don't need data to test why my code is not working, because for me it sounds like a general mistake about using the bound. however, if you want data, i give you data.

从一开始就没有rs:boostedBy谓词,因此我一直希望默认值始终为,在这种情况下为整数类型的1.

there is no rs:boostedBy predicate from the first place, so i was looking to have the default value always , which is 1 of type integer in this case.

推荐答案

IF必须在可选图形模式之外:

The IF needs to be outside of the optional graph pattern:

SELECT ?boosted WHERE {
    :r1 a ?x
    OPTIONAL{ ?item rs:boostedBy ?boostedOptional . }
    BIND (IF(bound(?boostedOptional), ?boostedOptional, "1"^^xsd:integer) as ?boosted)
}

第二,我看不到rs:boostedBy属性和{:r1 a?x}三重模式之间的关系. IE.您是否正在尝试查看主题是否具有boostedBy属性?在这种情况下,如果我了解您的意图,则:r1和?item应该相同,即都应该是:r1或都应该是?item.

Secondly, I don't see the relationship between the rs:boostedBy property and the {:r1 a ?x} triple pattern. I.e. are you trying to see if the subject has a boostedBy property? In that case :r1 and ?item should be the same, i.e. both should be :r1 or both should be ?item, if I'm understanding your intent here.

这篇关于为什么这个变量永远没有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆