0

I have following SPARQL query that contains a sub-select. The data contains multiple graphs and I want to know what graph the values for ?b and ?m come from:

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.
   }

}

}

The second graph pattern contains a transitive property path and the query provides following correct result:

 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/> 

However, I want to see the intermediate nodes and count the path length from transitive relationship. If I remove graph ?g1 from the query, then it shows the intermediate node information like following:

 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 

The Purpose of the query is to figure out graph name for matching ?b and ?m. Hence, I want to use graph ?g1. Is it possible to show intermediate nodes by retaining the graph keyword? I am using Virtuoso.

TallTed
  • 9,069
  • 2
  • 22
  • 37
Beautiful Mind
  • 5,828
  • 4
  • 23
  • 42
  • Off-topic: It's illegal SPARQL syntax with the `,`. And for readability, I'd suggest to make it more compact by using TURTLE features, especially for the first sub-select. – UninformedUser Jun 12 '16 at 16:02

1 Answers1

1

Since you're not using g the first GRAPH statement is not necessary. Note also that the second GRAPH statement only uses ?o1, so the following query do what you want it to. You may also want to check SPARQL syntax in your select clause.

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   .
  }
}

In the endpoint provided there isn't a match for ?b or ?m, regardless of whether a GRAPH statement is used or not.

TallTed
  • 9,069
  • 2
  • 22
  • 37
scotthenninger
  • 3,921
  • 1
  • 15
  • 24
  • Thank you for your answer. I need to apply the lowest value of the "?e" that's why I used "ORDER BY ASC(?e) LIMIT 1" in my query. However, you omitted it from your answer. If I use the "ORDER BY" clause then I have the same problem as mentioned in my question. You can test my data through following SPARQL endpoint: "http://taos.vbi.vt.edu:8890/sparql" – Beautiful Mind Jun 12 '16 at 18:52
  • OK, I see what the sub-select is about, but the question remains a bit vague. – scotthenninger Jun 12 '16 at 19:55
  • endpoint provides match for ?b and ?m. My question is if I use "GRAPH" keyword then SPARQL select statement doesn't provide intermediate node from transitivity. However, if I omit the "GRAPH" keyword then it works fine. That means it provides intermediate node information. Why is it so? I need intermediate node information with "GRAPH" URI. – Beautiful Mind Jun 12 '16 at 21:24
  • There is no match at the endpoint for an `?o1` binding that also matches the criteria in the `GRAPH` statement, where `?b ndssl:getInfectedBy ?o1.` This is the point where the query is failing to find a match. It has nothing to do with `GRAPH` itself. If you simply take 'graph ?g1` out of the query, there are no matches for `?b` and `?m` because the aforementioned triple pattern does not find a match for `?o1`.. – scotthenninger Jun 12 '16 at 23:45
  • Are you looking at the right SPARQL endpoint? It working for me. I am getting the result for `?o1' and for both with graph and without graph command. I am getting the results that I mentioned in the question. If you want then I can send you the result URLs. BTW my SPARQL endpoint is [link](http://taos.vbi.vt.edu:8890/sparql) – Beautiful Mind Jun 13 '16 at 01:24