On 11/07/12 17:37, Cong Wang wrote:
However, if i don't know the prefix???
What do you want?
A possible namespace -- afn:namespace or in java Util.splitNamespace
The namespaces declared -- the model and the query record the prefixes
(or you can set them).
But the namespace is not in the triple data itself - RDF is always about
absolute IRIs.
Andy
--
Cong Wang
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Wednesday, July 11, 2012 at 5:33 PM, Andy Seaborne wrote:
On 11/07/12 17:19, Dave Reynolds wrote:
On 11/07/12 16:26, Cong Wang wrote:
Hi all,
ex:car1 rdfs:subClassOf ex:SportsCar .
Suppose the sparql query is
select ?x
where {
?x ?y ?z .
}
while, I want to get "ex:car1" as a string, then i use str(?x),
however it returns "http://.…./ex#car1", with prefix..I just want
"ex:car1". Besides, using afn:namespace or afn:localname doesn't work
as well….
Anyone knows how to do that?
If you are doing this in java over a local model then take the result
from and do:
model.shortform( valueOfX )
If you have to do this directly in standard SPARQL then you could use
REPLACE to manipulate the string, maybe something like:
SELECT (REPLACE(STR(?x), "^http://.../ex#", "ex:") AS ?prefixed) ...
Dave
The trick in SPARQL is to use ex: as a prefix name to get its expansion
and change the URI string.
REPLACE(STR(?x), str(ex:), "ex:")
:-)
- - - - - -
PREFIX ex: <http://example/>
SELECT *
{
BIND(<http://example/local> as ?x)
BIND(REPLACE(str(?x), str(ex:), "ex:") as ?y)
}
sparql --data D.nt --query Q.rq --results tsv
==>
?x ?y
<http://example/local> "ex:local"
Andy