是否可以使用SPARQL/Update中的GROUPBY子句执行INSERT操作?

是否可以使用SPARQL/Update中的GROUPBY子句执行INSERT操作?,sparql,rdf,blazegraph,knowledge-graph,Sparql,Rdf,Blazegraph,Knowledge Graph,假设我有一个包含三个不同年级学生的图表 示例图: <http://some/graph#John_Doe> rdf:type <http://some/graph/ontology#Student> <http://some/graph#John_Doe> <http://some/graph#hasGrade> <http://some/graph#Grade_3> <http://some/graph#Grade_3>

假设我有一个包含三个不同年级学生的图表

示例图:

<http://some/graph#John_Doe> rdf:type <http://some/graph/ontology#Student>
<http://some/graph#John_Doe> <http://some/graph#hasGrade> <http://some/graph#Grade_3>
<http://some/graph#Grade_3> rdf:type <http://some/graph/ontology#Grade>
rdf:type
rdf:类型
我想为classGrade的每个实例创建一个名为gradeStrength的属性,以存储该年级的学生人数

在上面的例子中,它看起来像:

<http://some/graph#Grade_3> <http://some/graph#gradeStrength> 1^^xsd:integer
1^^xsd:integer
目前,我使用两个单独的查询来实现它,如下所示-

  • 在图形上运行SELECT+GROUP BY查询以获取每个等级的计数
  • 迭代1的结果行。创建一个三元组字符串的步骤
  • 在图形上运行插入数据更新查询
  • 如何通过使用INSERT和GROUPBY构造使用单个SPARQL/Update查询来实现这一点?我尝试编写这样的查询,但在Blazegraph中失败。

    使用

    INSERT {
      ?grade <http://some/graph#gradeStrength> ?gradeStrength
    } 
    WHERE 
    { 
      { 
        SELECT ?grade (COUNT(?student) AS ?gradeStrength)  
        { 
          ?student  <http://some/graph#hasGrade> ?grade . 
        } 
        GROUP BY ?grade   
      } 
    }
    
    插入{
    ?等级?等级强度
    } 
    哪里
    { 
    { 
    选择等级(将(?学生)计算为等级强度)
    { 
    学生成绩。
    } 
    按年级分组
    } 
    }
    

    根据@UninformedUser的评论做出的回答。通过上传问题的样本三元组在Blazegraph上进行测试。

    是的,这是可能的。使用
    插入{grade?gradeStrength},其中{{SELECT?grade(COUNT(?student)AS?gradeStrength){student?grade}按?grade}分组}
    -(确实未测试)@UninformedUser我使用上面的示例数据和您在blazegraph上建议的更新查询对其进行了测试,它成功了!非常感谢。关于stackoverflow的第一个问题-不确定如何接受此作为答案并关闭该问题。您只需添加工作查询作为答案,还可以单击“接受”以获得自己的答案。这将基本上标志着问题已经解决,没有适当的“结束”