0

我有以下包含子选择的 SPARQL 查询。数据包含多个图表,我想知道值的来源?b?m来源:

select ?b, ?m, ?g1
where {

 {
    select ?o1, ?o2, ?e 
     where{
      graph ?g{
       ?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> ?o1.
       ?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> ?o2.
       ?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_iteration> '0'^^xsd:decimal.
       ?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_exposureday> ?e.
       ?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_pid1> ?o1.
       ?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_pid2> ?o2.
       ?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_acttype1> '5'^^xsd:decimal.
       ?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_acttype2> '5'^^xsd:decimal
    }
   }ORDER BY ASC(?e) LIMIT 1 
}

{

graph ?g1 {
?b <http://ndssl.bi.vt.edu/chicago/vocab/getInfectedBy> ?o1.
?m <http://ndssl.bi.vt.edu/chicago/vocab/getInfectedBy>* ?b.
   }

}

}

第二个图形模式包含传递属性路径,查询提供以下正确结果:

 b                                                        m                                                        g1 
 -----------------------------------------------------    -----------------------------------------------------    ------------------------------------------------------- 
 <http://ndssl.bi.vt.edu/chicago/person/pid#446734805>    <http://ndssl.bi.vt.edu/chicago/person/pid#446753456>    <http://ndssl.bi.vt.edu/chicago/dendrogram/replicate1/> 

但是,我想查看中间节点并计算传递关系的路径长度。如果我graph ?g1从查询中删除,那么它会显示如下中间节点信息:

 b                                                      m
 ---------------------------------------------------    --------------------------------------------------- 
 http://ndssl.bi.vt.edu/chicago/person/pid#446718746    http://ndssl.bi.vt.edu/chicago/person/pid#446718746 
 http://ndssl.bi.vt.edu/chicago/person/pid#446734805    http://ndssl.bi.vt.edu/chicago/person/pid#446734805 
 http://ndssl.bi.vt.edu/chicago/person/pid#446734805    http://ndssl.bi.vt.edu/chicago/person/pid#446753456 

查询的目的是找出匹配的图形名称?b?m。因此,我想使用graph ?g1. 是否可以通过保留graph关键字来显示中间节点?我正在使用 Virtuoso。

4

1 回答 1

1

由于您没有使用g第一个GRAPH语句,因此没有必要。另请注意,第二GRAPH条语句仅使用?o1,因此以下查询执行您想要的操作。您可能还想检查select 子句中的SPARQL 语法

PREFIX ndssl: <http://ndssl.bi.vt.edu/chicago/vocab/>
SELECT ?b ?m ?g1
WHERE {
  {
    SELECT ?o1
    WHERE {
       ?s   ndssl:dendrogram_infector_pid  ?o1               .
       ?s   ndssl:dendrogram_infectee_pid  ?o2               .
       ?s   ndssl:dendrogram_iteration     '0'^^xsd:decimal  .
       ?s   ndssl:dendrogram_exposureday   ?e                .
       ?s1  ndssl:contactnetwork_pid1      ?o1               .
       ?s1  ndssl:contactnetwork_pid2      ?o2               .
       ?s1  ndssl:contactnetwork_acttype1  '5'^^xsd:decimal  .
       ?s1  ndssl:contactnetwork_acttype2  '5'^^xsd:decimal
    } ORDER BY ASC(?e) LIMIT 1 
  }
  GRAPH ?g1 {
    ?b  ndssl:getInfectedBy   ?o1  .
    ?m  ndssl:getInfectedBy*  ?b   .
  }
}

?b在提供的端点中, or不匹配?m,无论是否使用GRAPH语句。

于 2016-06-12T15:58:59.247 回答