【问题标题】:bind multiple sparql variables into one so this one variable can be used to order results将多个 sparql 变量绑定为一个,以便可以使用这个变量对结果进行排序
【发布时间】:2014-05-16 16:58:45
【问题描述】:

基本上我有一些数据,例如:

:student1 :hasAScore "4.1"
:student2 :hasAScore "2.7"
:student2 :hasBScore "2.1"

但在我的查询中,我想

select * where{
  ?a :hasAScore ?score1
  ?b :hasBScore ?score2
  //bind ?score1 as ?score and bind ?score2 as ?score too, so they can be ranked by "order by"
} order by(?score)

基本上我是说我希望能够按分数对学生进行排名,分数可以是 AScore 或 BScore。无论如何我可以将 ?score1 和 ?score2 结合为 ?score 以便我可以按 ?score 排名

【问题讨论】:

    标签: rdf sparql semantic-web


    【解决方案1】:

    无论如何我可以有某种联合?score1 和 ?score2 作为 ?score 以便我可以按 ?score 排名

    当然,您可以使用适当命名的union,如下所示。我假设您的意思是同一个学生同时具有 A 分数和 B 分数,因此您实际上希望在学科位置中使用一个变量。

    select * where { 
      { ?student :hasAScore ?score } 
      union 
      { ?student :hasBScore ?score }
    }
    

    不过,您甚至不需要在这里使用union。在 SPARQL 1.1 中,引入了属性路径,这意味着您可以编写 :hasScoreA|:hasScoreB,如下所示:

    select * where { 
      ?student :hasAScore|:hasBScore ?score
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多