On 03/01/12 16:57, Florian Beuter wrote:
Hello together,

I'm using Jena to process SPARQL queries and have a weird problem
regarding blank nodes in the result of a Select query. My RDF graph
contains blank nodes written like this:
_:A10b7f677X3aX134a46e2d15X3aXX2dX7f6b

Serialized to N-Triples like that ... it's the internal id, converted to a string but the label is really scoped to the file (if you read it in again, you will get different bnodes).

And I want to retrieve this in the same way as a result of my Select
query. Unfortunately I'm getting something different like:
10b7f677:134a46e2d15:-7f5b

.. this is the internal label.

N-triples does not allow:
1/ A leading digit so add the "A"
2/ : or - and these are encodes as "X" and the hex.  X3a is ":"

I retrieve an RDFNode from the QuerySolution and make sure that in case
of a blank node (by calling RDFNode.isAnon()) it is converted to a
Resource. Now I can access the AnonId by calling Resource.getId(), which
offers to ways to return a String representation of it:
AnonId.toString() and AnondId.getLabelString().
Both methods return 10b7f677:134a46e2d15:-7f5b in my case. Shouldn't one
of them return the other representation
_:A10b7f677X3aX134a46e2d15X3aXX2dX7f6b instead or did I get something
wrong? Or is there another way to access this String representation of
my blank nodes?

You can access blank nodes directly but first think about whether the app really should be doing that. They are blank and have no (real) name. Yes, jena gives them internal ids, but they are internal, not URIs.

You can acess them in SPARQL querying a local graph using the pseudo-URI scheme "_:" followed by the internal label

<_:10b7f677:134a46e2d15:-7f5b>

but it only works for local queries. You have to get the server to cooperate for it to work remotely and so it isn't portable.

        Andy


Best regards,

Florian Beuter

Reply via email to