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

Writer does not support Notation3 #316

Open
jeswr opened this issue Dec 26, 2022 · 5 comments
Open

Writer does not support Notation3 #316

jeswr opened this issue Dec 26, 2022 · 5 comments

Comments

@jeswr
Copy link
Collaborator

jeswr commented Dec 26, 2022

If we parse the statement {?s a ?o} => {?s a ?o}. into RDF/JS quads and then write those quads back to text/n3 using the Stream Writer we get

_:n3-0 {
?s a ?o
}
_:n3-1 {
?s a ?o
}
_:n3-0 <http://www.w3.org/2000/10/swap/log#implies> _:n3-1.

When trying to parse this result again we get the error Error: Expected entity but got { on line 1.

Can be reproduced by running this script

function write(quads: Quad[]): Promise<string> {
  return new Promise<string>((res) => {
    const writer = new StreamWriter({ format: 'text/n3' });
    let s: string = '';
    Readable.from(quads)
      .pipe(writer)
      .on('data', d => {
        s += d
      }).on('end', () => { res(s) })
  });
}

function parse(str: string): Quad[] {
  const parser = new Parser({ format: 'text/n3' });
  return parser.parse(str)
}

async function main() {
  const parsed = parse(`{?s a ?o} => {?s a ?o}.`);
  const backToString = await write(parsed);
  console.log(backToString)
  // Errors on this line
  parse(backToString);
}

main();
@jeswr
Copy link
Collaborator Author

jeswr commented Dec 26, 2022

I'm struggling to find a grammar that I can get my head around to work out how this needs to be written. I.e. do we need re-write it as {?s a ?o} => {?s a ?o}; or can we make the above form valid n3 with a couple of minor tweaks.

I've also not been able to find any other JavaScript TypeScript N3 writers for this purpose.

@jeswr
Copy link
Collaborator Author

jeswr commented Dec 26, 2022

@josd Would you be able to point me to the package / code responsible for serializing N3 in Eye as a reference point?

@josd
Copy link

josd commented Dec 26, 2022

The code doing the reasoning output in eye starts at https://github.com/eyereasoner/eye/blob/6405dcb4b1dacb806af9e18f909cc06db31b3059/eye.pl#L3431 and ends at https://github.com/eyereasoner/eye/blob/6405dcb4b1dacb806af9e18f909cc06db31b3059/eye.pl#L4649
This also includes the writing of proofs and that's why it is so longwinded :-)

@RubenVerborgh
Copy link
Member

write those quads back to text/n3 using the Stream Writer

Just want to note that N3.js at the moment does not support Notation3 writing (because it cannot be done in a streaming way).

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 4, 2023

Just as a note - the code I am currently using to do N3 writing is https://github.com/eyereasoner/eye-js/blob/main/lib/n3Writer.temp.ts

@RubenVerborgh RubenVerborgh changed the title Writer not writing valid Notation3 Writer does not support Notation3 Jan 11, 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

No branches or pull requests

3 participants