user2201650
user2201650

Reputation: 557

Is it possible to just extract the SPARQL endpoint from a SPARQL query?

I'm learning Semantic Web programming and trying to develop an app for the Android platform. There's a textfield in my app where the user would enter a SPARQL query.

I was wondering if I could just extract the SPARQL endpoint from a whole SPARQL query. For example, in the query SELECT ?class FROM <http://myexample.com> WHERE{?class a owl:Class} Order By ?class I would want to extract the http://myexample.com.

Or from a query that looks like SELECT ?dataType ?data WHERE { <http://nasa.dataincubator.org/launch/1961-012> ?dataType ?data.} , extract the http://nasa.dataincubator.org/launch/1961-012.

I want to use the extracted endpoint and then retrieve the classes, properties, etc. of that ontology from within the SPARQL endpoint.

Is it possible to extract just the endpoint?

Upvotes: 0

Views: 163

Answers (1)

Jeen Broekstra
Jeen Broekstra

Reputation: 22042

It's easy enough to extract the URI http://myexample.com/ from your example query. Either parse the query and inspect the parse result (how you do this depends on what query parser you use), or just write a simple regex that grabs the FROM clause and extract the URI behind it.

However, the URI in the FROM clause is not the SPARQL endpoint. The FROM clause in a SPARQL query specifies a named graph, which, very generally speaking, is a subset of the total dataset over which you're querying. But it doesn't tell you what SPARQL endpoint the query will be executed by.

In general, the SPARQL endpoint is not part of the query itself, but is determined by the tool you use to actually execute the query.

There is one case in which you can determine the endpoint used from the query itself, and that is if the SPARQL query uses a SERVICE clause, for example:

SELECT *
WHERE { 
   SERVICE <http://example.org/sparql> { ?s ?p ?o } 
}
LIMIT 100

But this construction is not guaranteed to be used, and in fact the majority of SPARQL queries don't use it.

Upvotes: 1

Related Questions