3

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.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • as you already recognized, str works on URIs and literals, the specs also state this: https://www.w3.org/TR/sparql11-query/#func-str – UninformedUser Jul 26 '22 at 14:07
  • the question is now, you did you import which raw data exactly? – UninformedUser Jul 26 '22 at 14:08
  • The data is not public. It is in RDF+XML form and consists of skos:Concept definitions identified by nodeID attributes instead of URIs. – alexis Jul 26 '22 at 16:36
  • I see. That wasn't clear from your question, you mention during import you set a prefix for relative URIs - but this indeed wouldn't apply to bnodes in the RDF data. You want to keep track of the bnode labels, can you explain why? Technically those are meaningless, but I understand that people sometimes want to preserve them during loading. Given those labels look like some domain specific identifier for the SKOS concepts, isn't there also some `skos:notation` triple which keeps track of the ID in a usable literal maybe? – UninformedUser Jul 26 '22 at 17:59
  • Right, these are clearly meaningful, and the Ids are not present in some other field in this input. Not how i would have done it, but that's the file I've got. And I'd rather transform the RDF, not the input file with search-and-replace... – alexis Jul 26 '22 at 21:24
  • Anyway it's often useful to derive distinct persistent identifiers from bnode IDs, and by far the simplest way is to base the URIs on the existing ids. Got a good alternative? – alexis Jul 26 '22 at 21:25

1 Answers1

2

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

Konstantin Petrov
  • 1,058
  • 6
  • 11
  • Thank you! I'll know next time to look at the graphdb function list instead of just the list in the sparql standard. – alexis Jul 28 '22 at 07:55