I have triples like this, where the object is an anyURI-typed string representation of a CURIe. I would like to construct the triples with the object as a true CURIe or IRI.
@prefix source: <https://example.org/source> .
@prefix external: <https://example.org/external> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
source:sample1 source:external_identifiers "external:0110680"^^xsd:anyURI .
IRI(?o)returns nothing.IRI(str(?o))returns<external:0110680>- but I want
<https://example.org/external/0110680>
- but I want
- This question mentions
tarql:expandPrefixedName, but when I try that (with the prefix or just as bareexpandPrefixedName) I get the following error message inarqor GraphDB. I assume that's because thetarqlfunctions aren't available in those tools?
MALFORMED QUERY: Lexical error at line 12, column 28. Encountered: '40' (40), after prefix "expandPrefixedName"
I would prefer to do this in SPARQL, but would also try a Python solution using something like rdflib.
To convert it to an IRI, you could use:
REPLACE()replaces the string"external:"(i.e., the prefix label;^represents the beginning of the value) inSTR(?o)withSTR(external:)STR(?o)converts?o("external:0110680"^^xsd:anyURI) to a string ("external:0110680")STR(external:)takes the prefix IRI (<https://example.org/external>) and converts it to a string ("https://example.org/external")IRI()converts the replaced string to an IRIIf you have a few different prefixes, you could use something like this:
(Instead of a
FILTER, you could useIFinside theBIND.)Another option could be
COALESCEwith nestedIFs.