在Virtuoso 7.20.3217中使用SPARQL“from”与图形和图形组

时间:2016-11-28 16:07:04

标签: sparql virtuoso

我有 m 图表的<group>图表<group_1> ... <group_m>,其中 n 总三元组。当我在图表组外部使用图表<graph> k 总三元组进行计数时,我只获得图表组中三元组的数量 n

select count(*)
from <group>
from <graph>
{?s ?p ?o}

结果: n

但是,当我明确列出图表组中的图表时,我得到了正确的结果:

select count(*)
from <group_1>
from <group_2>
...
from <group_m>
from <graph>
{?s ?p ?o}

结果: n + k

如何使用图表组获得正确的结果?这种行为的原因是什么?

1 个答案:

答案 0 :(得分:1)

您应该使用这样的两个子查询,例如:

select ?n ?k (?n + ?k as ?totalCount) where {
  { select (count(*) as ?n) where {
      graph group: { ?s ?p ?o } }
  { select (count(*) as ?k) where {
      graph graph: { ?s ?p ?o } }
}

或使用联盟:

select (count(?s1) as ?n)
       (count(?s2) as ?k)
       (?n + ?k as ?totalCount)
where {
  { graph group: { ?s1 ?p1 ?o1 } }
  union
  { graph graph: { ?s2 ?p2 ?o2 } }
}
相关问题