How to execute SPARQL Query (Call a service) Over extracted subgraph?

时间:2016-04-25 09:11:55

标签: sparql rdf subgraph

I have a RDF graph with several types of relations (relations with the same prefix and with different prefixes also). I need to call a service over the graph but filtering out some relations.

Example: enter image description here

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix myPref: <http://www.myPref.com/>.
@prefix otherPref: <http://www.otherPref.com/>.

myPref:1
    myPref:label "1" ;
    myPref:solid myPref:2 ;
    myPref:dotted myPref:4 ;
    otherPref:dashed myPref:3 ;
    otherPref:dashed2 myPref:3 .

myPref:2
    myPref:label "2" ;
    myPref:solid myPref:3 .

myPref:3
    myPref:label "3" .

myPref:4
    myPref:label "4" ;
    myPref:dotted myPref:3 .

I would like to run the service call over an extracted sub-graph containing only the solid and dotted relations (In this particular case, running a service calculating the shortest path between 1 to 3, I want to exclude those direct links).

I run the service (Over the entire graph) like this:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
PREFIX myPref: <http://www.myPref.com/>.
PREFIX otherPref: <http://www.otherPref.com/>.
PREFIX gas: <http://www.bigdata.com/rdf/gas#>

SELECT ?sp ?out {
  SERVICE gas:service {
     gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" .
     gas:program gas:in myPref:1 .
     gas:program gas:target myPref:3 . 
     gas:program gas:out ?out . 
     gas:program gas:out1 ?sp . 
  }
}

How can I extract a subgraph containing only the links I want (Dotted and solid) and the run the service call over the extracted sub-graph?

1 个答案:

答案 0 :(得分:0)

不幸的是,SPARQL没有提供查询构造图的任何功能。我遇到的地方很容易让一些查询变得容易。但是,有些端点确实有扩展来支持它。我认为dotNetRDF可能会支持它。可能有几个方面:在许多情况下,它实际上并不是必需的;如果端点支持更新,您可以创建一个新的命名图并构造它,然后针对它启动第二个查询(这几乎是您要求的,但分两步);这可能是一个非常昂贵的操作,因此端点可能会禁用它,即使它是直接支持的。

但是,第一个注意事项似乎经常没有必要,似乎可能就是这种情况。

  

我需要在图表上调用服务,但过滤掉一些关系。

在这种情况下,您可以使用属性路径查询您想要的子图。您可以要求仅使用实线和虚线构建的路径,如:

?s  myPref:solid|myPref:dotted ?t

如果你想要它们的任意路径,你可以重复它:

?s  (myPref:solid|myPref:dotted)+ ?t

如果源和目的地之间有唯一的路径,那么您可以使用标准“计算分割路径的方法”技术来计算路径的长度:

select (count(?t) as ?length) {
  ?s  (myPref:solid|myPref:dotted)* ?t
  ?t  (myPref:solid|myPref:dotted)* ?u
}
group by ?s ?t