Question

I want to get results from sparql query and the results contain no namespace. ex: there is result in triple format like:

"http://www.xyz.com#Raxit"  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"  "http://www.xyz.com#Name"

So i want to get only following:

Raxit type Name

I want to get this results directly from sparql query. I am using virtuoso.

Is it possible to get this from sparql?

Please share your thoughts regarding this.

Thanks in Advance.

Was it helpful?

Solution

If your data is regular, and you know that the sub-string you want always occurs after a # character, then you can use the strafter function from SPARQL 1.1. I do not know whether this is available in Virtuoso's implementation or not.

However this is, in general, a very risky strategy. Not all URI's are formatted with a local name part after a # character. In fact, in general, a URI may not have a legal or useful localname at all. So you should ask yourself: why do you think you need this? Generally speaking, a semantic web application uses the whole URI as an indivisible identifier. If your need is actually for something human-friendly to display in a UI, have your query also look for rdfs:label or skos:label properties. Worst case, try to abbreviate the URI to q-name form (i.e. prefix:name), using the prefixes from the model or a service like prefix.cc

OTHER TIPS

The simplest way to achieve this is to not bother with adapting your query, but to just post-process the result yourself. Depending on which client library you use to communicate with Virtuoso, you will typically find it has API support to parse the result, get back values, and for each value then get only local name (I suggest you look for a URI.getLocalName() method or something similar).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top