how group graph pattern work in SPARQL

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:04:36

问题


First of all, i don't know if this really called group graph pattern or not. Anyway,

Look at this query please

select ?x  ?y where {
  {?x rdf:type rs:Recommendable}
 union
  {?xd rs:doesntexist ?y}
} 

there is no rs:doesntexist but with union i got the results only from the first sub graph which is {?x rdf:type rs:Recommendable}

but if i remove the union, so the query will be:

select ?x  ?y where {
  {?x rdf:type rs:Recommendable}

  {?xd rs:doesntexist ?y}
}

I get empty results, may I ask you please who this work?

and the weird thing to me that this query

select ?x  ?y where {
  {?x rdf:type rs:Recommendable}.{}

}

works perfectly so the one before it doesnt?

Update

I think the union is like optional, I'm not sure. is it right please? (and by optional i didn't mean the optional from sparql, but i meant like when extracting the data from a union two graphs, its optional that two of them have data but if one of them is empty, we'll have the data from the other)


回答1:


select ?x  ?y where {
  {?x rdf:type rs:Recommendable}

  {?xd rs:doesntexist ?y}
}

is like (not identical) to:

select ?x  ?y where {
  ?x rdf:type rs:Recommendable
  ?x rs:doesntexist ?y
}

Both patterns must match. If there is no rs:doesntexist the whole thing fails.

{}

matches all (zero) its patterns so it always works.



来源:https://stackoverflow.com/questions/35314331/how-group-graph-pattern-work-in-sparql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!