-1

I try to use SERVICE keyword in SPARQL query on website having this query link I found about SERVICE keyword here : this link.

My query is which I already give link above to execute:

 SELECT * 
 WHERE { 
   ?x a ?name .  
   SERVICE ?name 
   { ?p a ?q . } 
 }

But it is not execting my SPARQL query and giving error why? I tried to change ?p to ?name but it still not working.

TallTed
  • 9,069
  • 2
  • 22
  • 37
Badman
  • 407
  • 5
  • 17
  • 1
    `SERVICE` specifies a SPARQL endpoint, not a class (nor other entity) name, so I would expect this query to produce errors. I don't understand what you're trying to achieve, so cannot provide any useful advice toward success... – TallTed Aug 10 '16 at 17:41
  • @TallTed In above query, ?name is an URL I want to take rdf graph/data from ?name URL and further query on data (RDF data or graph) from ?name URL. – Badman Aug 10 '16 at 17:51
  • Which data do you expect to be contained in a class, like e.g. `http://dbpedia.org/ontology/Book`? – UninformedUser Aug 11 '16 at 15:00
  • @Badman - Your goal remains unclear, to me and to the others trying to help you. Perhaps you could try to explain in simple language (in a rewording of the question, not in a comment, so you can use formatting to help with clarity) — what are you trying to achieve? – TallTed Aug 11 '16 at 20:03

2 Answers2

0

What is the idea of the query? I don't understand what you want to achieve with the query. By the way, the number of triples of type ?s a ?cls is 100 555 839 in DBpedia...

I don't think that DBpedia has separate graphs for each class. And even if it would have, the query for a given class, e.g. dbo:Person

SELECT * WHERE { 
   SERVICE dbo:Person 
   { ?p a ?q . } 
}
LIMIT 10

leads to an error

Virtuoso 42000 Error SQ070:SECURITY: Must have select privileges on view DB.DBA.SPARQL_SINV_2

I guess the DBpedia SPARQL endpoint does not allow federated queries

TallTed
  • 9,069
  • 2
  • 22
  • 37
UninformedUser
  • 8,397
  • 1
  • 14
  • 23
  • I think you are right Federated query is not working but when and how we can use keyword SERVICE . – Badman Aug 11 '16 at 13:58
  • Without finally understanding the goal/meaning of your query, I cannot answer your question. For the technical hurdles, indeed you could setup your own triples store. – UninformedUser Aug 11 '16 at 15:04
0

Based on unclear expansion of question in comment... I don't think SERVICE is relevant to your query, for which I think you want something more like --

SELECT DISTINCT ?x ?name ?q
WHERE 
  {
    ?x     a  ?name  .
    ?name  a  ?q     .
  }
ORDER BY ?x ?name ?q
LIMIT 100

See results here

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • In above query you took default IRI http://dbpedia.org . While I am taking graph IRI is http://dbpedia.org/sparql .For this it gives 0 results but according to me it should give 1 result.To clearify my question I divide above query in two parts first query is SELECT ?x ?name WHERE { ?x a?name . } [this is result](http://librdf.org/query?uri=http%3A%2F%2Fdbpedia.org%2Fsparql%2F&query=SELECT+%3Fx+%3Fname%0D%0AWHERE+%7B%0D%0A+++%3Fx+a+%3Fname+.%0D%0A%7D%0D%0A&language=sparql&Run+Query=Run+Query&.cgifields) – Badman Aug 10 '16 at 19:23
  • and In Second query : SELECT ?name ?q WHERE { ?name a ?q . } [this is result](http://librdf.org/query?uri=http%3A%2F%2Fwww.w3.org%2Fns%2Fsparql-service-description%23Service&query=SELECT+%3Fname+%3Fq%0D%0AWHERE+%7B%0D%0A++%3Fname++a+%3Fq+.%0D%0A%7D%0D%0A&language=sparql&Run+Query=Run+Query&.cgifields=json&.cgifields=raw) for graph IRI http://www.w3.org/ns/sparql-service-description#Service – Badman Aug 10 '16 at 19:24
  • So according to query (query in your answer) for graph IRI dbpedia.org/sparql it should give 1 result : x = http://dbpedia.org/sparql , name= http://www.w3.org/ns/sparql-service-description#Service , z= http://www.w3.org/2000/01/rdf-schema#Class .While it gives nothing in result – Badman Aug 10 '16 at 19:29
  • @badman Just because the *endpoint *is dbpedia.org/sparql doesn't mean that that is the IRI of the graph that you're querying over. – Joshua Taylor Aug 10 '16 at 19:39
  • @JoshuaTaylor So what endpoint means? But my acutal problem is there maybe two or more URLs having some rdf data and they are related to each other like URL1 having data which apache jena automatically convert to rdf graph for SPARQL query ( assume URL1 have a triplet data (rdf graph) : Joshua details . and URL2 (www.abc.com/JoshuaTaylor) have triplets data (rdf graph) : DOB 12-6-1980 .So from above query starting from URL1 it should give result(triplets) : Joshua DOB 12-6-1980 .Problem is ?name is URL which is not resolving automatically – Badman Aug 11 '16 at 03:29
  • Endpoint is just the URL that provides the SPARQL service. It doesn't mean to be graph resp. knowledge base itself. – UninformedUser Aug 11 '16 at 15:02
  • And again, Jena does nothing "automatically", especially not retreiving additional data for the URIs that occur in a SPARQL query resp. as result. – UninformedUser Aug 11 '16 at 15:03