Sparql Query Results without Namespace
Asked Answered
J

2

9

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.

Jackson answered 27/6, 2012 at 20:29 Comment(0)
C
7

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

Carolanncarole answered 27/6, 2012 at 23:7 Comment(2)
Yes, I need this. I want show data to user and i dont want use split or indexof function in java. Thats why i want to get directly from sparql query.Jackson
I find it kinda unbelievable that so few tools have an option for this. I guess people working with rdf seldom work with the text format? Apache Jena's arq output are by default prefixed instead of full uris thoughBlackburn
O
1

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).

Overleap answered 27/6, 2012 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.