rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
714 stars 133 forks source link

Possible issue with dot #30

Closed elf-pavlik closed 9 years ago

elf-pavlik commented 9 years ago

I tried updating levelgraph-n3 to latest version of n3.js, when running this test https://github.com/mcollina/levelgraph-n3/blob/3d3b6d64ea0b028dc9195633d6553e2920252237/test/putStream_spec.js

I started getting

 1) n3.putStream should store some triples:
     Error: Expected punctuation to follow "http://example.org/cartoons#Cat.c:Jerry" at line 1.
      at Object.N3Parser._error (/cache/code/maintain/levelgraph-n3/node_modules/n3/lib/N3Parser.js:457:20)
      at Object.N3Parser._readPunctuation (/cache/code/maintain/levelgraph-n3/node_modules/n3/lib/N3Parser.js:382:19)
...

Adding in test fixture a white space before . (after c:Cat) fixed those symptoms but I don't think (couldn't find in spec) that Turtle requires this white space before .

RubenVerborgh commented 9 years ago

Seeing this error, I suspect that the string http://example.org/cartoons#Cat.c:Jerry occurs somewhere in the input. This is incorrect, since the IRI should be delimited with angular brackets <…>. Can you give the exact Turtle input and expected output?

elf-pavlik commented 9 years ago

you can find exact input in the test i linked to: https://github.com/mcollina/levelgraph-n3/blob/3d3b6d64ea0b028dc9195633d6553e2920252237/test/putStream_spec.js#L6

"@prefix c: <http://example.org/cartoons#>.\n" +
           "c:Tom a c:Cat.\n" +
           "c:Jerry a c:Mouse;\n" +
           "        c:smarterThan c:Tom;\n" +
           "        c:place \"fantasy\".";

adding a space after c:Cat made it work again (it started to fail after only updating N3 from 0.2.3 to 0.3.4

if you like you can just

  1. check out levelgraph-n3 repo
  2. change N3 dependency to exactly 0.2.3
  3. npm install && npm test will pass tests
  4. bump N3 to 0.3.4
  5. npm install && npm test will fail this one test
RubenVerborgh commented 9 years ago

The problem does not seem to be N3.js-related:

var N3 = require('n3');

var turtle = "@prefix c: <http://example.org/cartoons#>.\n" +
             "c:Tom a c:Cat.\n" +
             "c:Jerry a c:Mouse;\n" +
             "        c:smarterThan c:Tom;\n" +
             "        c:place \"fantasy\".";

new N3.Parser().parse(turtle, console.log);

works fine.

RubenVerborgh commented 9 years ago

It's an issue with the levelgraph-n3 test. It does not generate the above Turtle do the parser, but rather:

@prefix c: <http://example.org/cartoons#>.c:Tom a c:Cat.c:Jerry a c:Mouse;c:smarterThan c:Tom;c:place "fantasy".

This is invalid Turtle, so the parser is correct to reject it.

The bug happens because the test accidentally removes newlines from the Turtle fragment. The following pull request fixes this: mcollina/levelgraph-n3/pull/14

RubenVerborgh commented 9 years ago

BTW The reason for this is that the Turtle spec if different from earlier Turtle drafts, in that it now allows dots as part of prefixed names. Hence, without whitespace after a dot, we cannot disambiguate.

elf-pavlik commented 9 years ago

Thank you!