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

Add support for empty graphs in the subject and object positions #374

Draft
wants to merge 2 commits into
base: versions/2.0.0
Choose a base branch
from

Conversation

Dexagod
Copy link

@Dexagod Dexagod commented Dec 6, 2023

This PR contains a fix for parsing empty graphs in subject and object positions when parsing empty graphs.

I added some test cases that check for empty graphs in the subject and object position, both in the default graph, and contained in a subgraph.

Note that this does NOT work for empty graphs in the predicate position.
I have added tests for these as well, but they are commented out at the moment.

@RubenVerborgh
Copy link
Member

@Dexagod Are empty graphs supported by both N3 (seems yes) and RDF-star (citation needed)?
If not, we will need a check on content type.

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's definitely not true in subject position for RDF-star, so we will need a format check.

@RubenVerborgh
Copy link
Member

(I might be overcautious here, and maybe this code doesn't hit with RDF-star; just want to be sure.)

src/N3Parser.js Outdated
const outerGraph = this._contextStack[this._contextStack.length - 1].graph;
this._emit(
graph,
this._namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#value'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to use a constant for this.

src/N3Parser.js Outdated
this._emit(
graph,
this._namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#value'),
this._literal('true', this._namedNode('http://www.w3.org/2001/XMLSchema#boolean')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to use a constant for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an error on my part.
I represented the empty graph as a blank node with an rdf:value of "true"^^xsd:boolean,
whereas I was corrected that it should be directly replaced with "true"^^xsd:boolean.

src/N3Parser.js Outdated
if (this._subject !== null) {
// Catch the empty graph being closed when parsing N3.
// In this case, we emit the empty graph as the value "true"^^xsd:boolean
if (!this._predicate && !this._object) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it sufficient to check that there is no predicate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predicate check should be sufficient, as the flow goes as follows:
at the start of the formula the this._readSubject function is called. This one sets the this._predicate value to null.
As the token here is }, the this._readPunctuation function is called, that then calls the this._readFormulaTail function.
In here, we find this code. So I concluded that we should only check on the this._predicate value being null, and not the this._object, as the predicate value alone should be enough of an indicator and I am unsure how the object gets there in all flows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. so let's do if (this._predicate === null) indeed.

@jeswr
Copy link
Collaborator

jeswr commented Dec 6, 2023

@Dexagod indeed we will only want to do this in N3 mode and error otherwise.

@RubenVerborgh this PR is not about RDF-Star; it is specifically for N3 content types in order to align with the decisions made in w3c/N3#185 & rdfjs/types#37 in the next major release.

In particular note that there are now N3 spec tests for what has been implemented here w3c/N3#202.

@RubenVerborgh
Copy link
Member

RubenVerborgh commented Dec 6, 2023

Ack about it being for N3; just want to make sure it doesn't fire at the wrong time. But perhaps _readFormulaTail is only accessed in N3 mode in any case.

@Dexagod
Copy link
Author

Dexagod commented Dec 6, 2023

Yep, synced on it with Jos and I indeed was mistaken. I'm setting it straight atm in terms of the true needing to be injected directly instead of with rdf:value. I'll double check to make sure the routine only fires in N3 mode.

@Dexagod Dexagod marked this pull request as draft December 6, 2023 14:08
@Dexagod
Copy link
Author

Dexagod commented Dec 6, 2023

Empty graphs are now correctly represented as "true"^^xsd:boolean.

I checked and the _readFormulaTail function is only called in N3 mode.

Should I check if RDF-star is enabled and throw an error in case it is?

@jeswr
Copy link
Collaborator

jeswr commented Dec 6, 2023

Should I check if RDF-star is enabled and throw an error in case it is?

No, I do not think we should error when N3 and star are both enabled. There is just no particular behavior we have to comply with as there is no N3-star spec.

@RubenVerborgh RubenVerborgh self-assigned this Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants