4

I have an rdf graph with several entries. Now I want to get all related triples to a given id. This is my sparql query:

select ?s ?p ?o from <http://localhost:8890/DAV/ranking> where {
 {<http://seekda.com/providers/cdyne.com/PhoneNotify> so:hasEndpoint ?s.
 ?s ?p ?o} union
 {<http://seekda.com/providers/cdyne.com/PhoneNotify> ?p ?o}
}

The ID in this case is <seekda.com/providers/cdyne.com/PhoneNotify>.

But I need a graph query (construct or describe). So I think I have to pack them togheter with an union. How do I do that?

MERose
  • 4,048
  • 7
  • 53
  • 79
simon
  • 39
  • 1
  • 2
  • 8

1 Answers1

4

The short answer is: there is no difference.

The longer answer is: think about SPARQL queries as having two parts.

  1. The query (WHERE) part, which produces a list of variable bindings (although some variables may be unbound).

  2. The part which puts together the results. SELECT, ASK, CONSTRUCT, or DESCRIBE.

SELECT * is effectively what the query returns. SELECT ?v1 ?v2 takes results and produces another result set with the other variables removed. ASK just looks to see if there are any results.

CONSTRUCT uses a template to make RDF from the results. For each result row it binds the variables and adds the statements to the result model. If a template triple contains an unbound variable it is skipped.

DESCRIBE is the most unusual, since it takes each result node, finds triples associated with it, and adds them to a result model. Unlike the others it can contain more information than the query matches.

So having UNION, OPTIONAL, whatever, in the query is allowed for all forms. They may lead to missing triples due to unbound variables.

Your query doesn't make much sense. It's no different to {?s ?p ?o}. What are you trying to do? Ok, makes more sense now.

Given clarifications below it sounds like you want the following:

construct { <http://seekda.com/providers/cdyne.com/PhoneNotify> ?p ?o }
from <http://localhost:8890/DAV/ranking> 
where {
  { <http://seekda.com/providers/cdyne.com/PhoneNotify> so:hasEndpoint ?s.
    ?s ?p ?o }
  union
  { <http://seekda.com/providers/cdyne.com/PhoneNotify> ?p ?o }
}
user205512
  • 8,798
  • 29
  • 28
  • Hey, thank you for your answer. ok, what im trying to do is: i have an rdf graph with several entries. now i want to get all related triples to a given id(in this case the id is ). as i need it in rdf, i have to use construct and as there are some transitive relations i have to pack them togheter with an union(?). i hope this clarifyies my problem. best regards simon ps: there was an error in my query, i corrected it, i think now it makes more sense :) – simon Apr 29 '10 at 10:35
  • Ah, I see. So you want info about this thing (PhoneNotify), and the endpoint? – user205512 Apr 29 '10 at 11:49
  • You mentioned 'transitive relations'. Is the idea that the 'endpoint' relations apply to 'PhoneNotify'? – user205512 Apr 29 '10 at 11:54