Is there currently a way to access RDF term type information (URI, blank node, typed literal, language-tagged literal) when executing a SPARQL SELECT query over a dataframe in a mapping file?
By “type”, I specifically refer to the type field returned in the SPARQL Query Results JSON format, e.g.:
{
"head": {
"vars": ["obj", "pred", "sub"]
},
"results": {
"bindings": [
{
"obj": {
"type": "uri",
"value": "https://knowledge.c-innovationhub.com/cefriel/data/HardwareModel#NVIDIA_BLUEFIELD"
}
}
]
}
}
Problem
I need to process SPARQL query results in a mapping layer where RDF terms must be handled differently depending on whether they are:
- URIs
- blank nodes
- literals (with or without datatype)
- language-tagged literals
For URIs, this is straightforward since they have a stable and recognizable structure, and we can also use helper functions such as isAbsoluteURI defined in TemplateFunctions.
However, blank nodes are more problematic because:
- Their
"value" field is implementation-dependent
- Different triplestores serialize blank nodes differently
- The identifier has no semantic meaning outside the result set
For example, Oxigraph returns:
{
"obj": {
"type": "bnode",
"value": "fbba96224680f2b6fadb3fff0ea508bb"
}
}
From my understanding, the only reliable way to detect that a value is a blank node is via the "type": "bnode" field in the SPARQL JSON results, since the "value" is not stable or meaningful.
Extension of the issue: literals
The same issue applies to literals, where additional type metadata is required:
Typed literal
{
"type": "literal",
"value": "ciao",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
}
Language-tagged literal
{
"type": "literal",
"value": "ciao",
"xml:lang": "it"
}
In both cases, correct downstream processing depends on correctly distinguishing:
- datatype-typed literals (
datatype)
- language-tagged literals (
xml:lang)
- plain literals (neither present)
@marioscrock, Do we currently have a way to get this information in an MTL mapping?
Is there currently a way to access RDF term type information (URI, blank node, typed literal, language-tagged literal) when executing a SPARQL
SELECTquery over a dataframe in a mapping file?By “type”, I specifically refer to the
typefield returned in the SPARQL Query Results JSON format, e.g.:{ "head": { "vars": ["obj", "pred", "sub"] }, "results": { "bindings": [ { "obj": { "type": "uri", "value": "https://knowledge.c-innovationhub.com/cefriel/data/HardwareModel#NVIDIA_BLUEFIELD" } } ] } }Problem
I need to process SPARQL query results in a mapping layer where RDF terms must be handled differently depending on whether they are:
For URIs, this is straightforward since they have a stable and recognizable structure, and we can also use helper functions such as
isAbsoluteURIdefined inTemplateFunctions.However, blank nodes are more problematic because:
"value"field is implementation-dependentFor example, Oxigraph returns:
{ "obj": { "type": "bnode", "value": "fbba96224680f2b6fadb3fff0ea508bb" } }From my understanding, the only reliable way to detect that a value is a blank node is via the
"type": "bnode"field in the SPARQL JSON results, since the"value"is not stable or meaningful.Extension of the issue: literals
The same issue applies to literals, where additional type metadata is required:
Typed literal
{ "type": "literal", "value": "ciao", "datatype": "http://www.w3.org/2001/XMLSchema#string" }Language-tagged literal
{ "type": "literal", "value": "ciao", "xml:lang": "it" }In both cases, correct downstream processing depends on correctly distinguishing:
datatype)xml:lang)@marioscrock, Do we currently have a way to get this information in an MTL mapping?