Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N-Quads serializer cannot deal with default graph. #561

Open
RinkeHoekstra opened this issue Jul 20, 2022 · 0 comments · Fixed by #562
Open

N-Quads serializer cannot deal with default graph. #561

RinkeHoekstra opened this issue Jul 20, 2022 · 0 comments · Fixed by #562
Assignees
Labels

Comments

@RinkeHoekstra
Copy link
Contributor

RinkeHoekstra commented Jul 20, 2022

The following valid N-Quad does not contain a graph:

_:b0 <https://example.com/hasExampleProperty> "some literal value" .

This is correctly parsed into a $rdf.Store.

When iterating over the statement, the graph term looks something like:

{
    "termType": "DefaultGraph",
    "value": "",
    "uri": "chrome:theSession"
}

However, the atomicTermToN3 function in serializer.js does not deal with nodes of type DefaultGraph:

rdflib.js/src/serializer.js

Lines 522 to 567 in c14dfd5

atomicTermToN3 (expr, stats) {
switch (expr.termType) {
case 'BlankNode':
case 'Variable':
return expr.toNT()
case 'Literal':
var val = expr.value
if (typeof val !== 'string') {
throw new TypeError('Value of RDF literal node must be a string')
}
// var val = expr.value.toString() // should be a string already
if (expr.datatype && this.flags.indexOf('x') < 0) { // Supress native numbers
switch (expr.datatype.uri) {
case 'http://www.w3.org/2001/XMLSchema#integer':
return val
case 'http://www.w3.org/2001/XMLSchema#decimal': // In urtle must have dot
if (val.indexOf('.') < 0) val += '.0'
return val
case 'http://www.w3.org/2001/XMLSchema#double': {
// Must force use of 'e'
const eNotation = val.toLowerCase().indexOf('e') > 0;
if (val.indexOf('.') < 0 && !eNotation) val += '.0'
if (!eNotation) val += 'e0'
return val
}
case 'http://www.w3.org/2001/XMLSchema#boolean':
return expr.value === '1' ? 'true' : 'false'
}
}
var str = this.stringToN3(expr.value)
if (expr.language) {
str += '@' + expr.language
} else if (!expr.datatype.equals(this.xsd.string)) {
str += '^^' + this.atomicTermToN3(expr.datatype, stats)
}
return str
case 'NamedNode':
return this.symbolToN3(expr)
default:
throw new Error('Internal: atomicTermToN3 cannot handle ' + expr + ' of termType: ' + expr.termType)
}
}

And fails with the error:

Error: Internal: atomicTermToN3 cannot handle DefaultGraph of termType: DefaultGraph

This should be fixed in atomicTermToN3 function in serializer.js by returning an empty string when the term type is DefaultGraph.

NB this is consistent also with how TriG represents default graphs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants