0

enter image description here[![SPARQL Query Details][2]][2]

How should I write SPARQL query to get the details from node2 : URI for node2 is same in both the graphs and URI for node 1 is different. Thank you in advance.

as such, I need below details.

node2 def
hasID ghi
hasvertex jkl
hasLastname mno
Manoj Deshpande
  • 311
  • 2
  • 18
  • any tutorial would answer your question ... just use a triple pattern per edge in your graph and for anything you don't want to specify use a avialable. Then select which variables you need. that's the whole story of basic SPARQL in a nutshell. `select ?p ?o where { ?p ?o }` – UninformedUser Feb 19 '20 at 19:55
  • yeah i get that....But if I have similar two graphs where only URI of node1 is different and URI of node2 is same in both the graphs. I want to query in this condition. Can you please let me know how exactly to traverse in particular case. Thank you. – Manoj Deshpande Feb 19 '20 at 20:59
  • I don't know what you're asking now, this doesn't match the image you show in the question. You asked for *"all details of node2"* which is exactly what my query does. So what's the problem now? Use `DISTINCT` operator if there are multiple nodes having an edge to node2: `select distinct ?p ?o where { ?p ?o }` – UninformedUser Feb 20 '20 at 04:00
  • I edited image and made it more clear now. Please suggest me a query for the expected result. That would be really helpful. Thank you. @UninformedUser – Manoj Deshpande Feb 20 '20 at 09:08

2 Answers2

1

To get all triples write SELECT ?node2 ?p ?o WHERE {?node2 ?p ?o}.

Now to restrict the results to graph 1 (defined by the URI of node1) you need to add <http://ex/abc> hasName ?node2.

Together:

SELECT ?node2 ?p ?o WHERE{
  <http://ex/abc> hasName ?node2 .
  ?node2 ?p ?o
}
Pascalco
  • 2,481
  • 2
  • 15
  • 31
1

Just alter that SPARQL slightly to use real URIs for properties:

SELECT ?node2 ?p ?o
WHERE {
  <http://ex/node1> <http://ex/hasName> ?node2 .
  ?node2 ?p ?o .
}
Nicholas Car
  • 1,164
  • 4
  • 7