sparqlrdfgraphdbblank-nodes

Converting a bnode to a string in graphdb


I have an RDF file where the resources are identified with nodeID's instead of URIs. I have imported them into Ontotext graphdb, and would like to generate URIs based on the nodeID (which I preserved during import). For example, I am trying to map this triple

_:C00456 rdf:type skos:Concept

to this:

<https://example.com/data/C00456> rdf:type skos:Concept

Unfortunately, if ?s is a BNODE, STR(?s) is an empty string in graphdb. xsd:string(?s), ditto. IRI(?s), you guessed it. Is there any function that will expose the form of the bnode as a string, so that I can build a URI from it? I went through the list of functions in the sparql 1.1 specification and could not see any.

PS It would have been nice if graphdb would just convert the nodeIDs to URIs during import (I specified a prefix for relative names), but it went by the book and turned them into bnodes. If I overlooked something, I'll be glad to be set right.


Solution

  • You can use the spif:buildString function to convert a BNode to String and then to IRI. Here is a sample query:

    PREFIX spif: <http://spinrdf.org/spif#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    CONSTRUCT {?sIRI ?p ?o}  WHERE {
    ?s ?p ?o .
        FILTER (isBlank(?s))
        BIND (IRI(spif:buildString("http://my/namespace/{?1}", ?s)) as ?sIRI)        
    } LIMIT 10 
    

    The function is documented here: https://graphdb.ontotext.com/documentation/10.0/sparql-functions-reference.html?highlight=buildstring#sparql-spin-functions-and-magic-predicates