w3c / rdf-star

RDF-star specification
https://w3c.github.io/rdf-star/
Other
120 stars 23 forks source link

TriG-star: plain triples starting with an embedded triple are not supported #187

Closed Tpt closed 3 years ago

Tpt commented 3 years ago

The SPARQL-star testsuite provides TriG-star files like:

<< <http://example/s> <http://example/p> <http://example/o> >>
        <http://example/source>  <http://example/faraway> .

However, these files does not seem to be supported by the current TriG-star grammar.

Indeed, the root rules or Trig grammar are:

[2g] block ::= triplesOrGraph | wrappedGraph |  triples2 |  "GRAPH" labelOrSubject wrappedGraph
[3g] triplesOrGraph ::= labelOrSubject (wrappedGraph |  predicateObjectList '.')

and none of them produces something like embTriple predicateObjectList '.' if we apply the TriG-star modification.

Here is a sample test case that does not pass if TriG-star grammar is implemented naïvely:

<trig_nested_triple>
    rdf:type rdft:TestTrigEval ;
    mf:name "nested triple in TriG without graph name" ;
    mf:action <trig_nested_triple.trig> ;
    mf:result <trig_nested_triple.nq> .

With trig_nested_triple.trig:

<< <http://example/s> <http://example/p> <http://example/o> >>
        <http://example/source>  <http://example/faraway> .

And trig_nested_triple.nq:

<< <http://example/s> <http://example/p> <http://example/o> >> <http://example/source>  <http://example/faraway> .

A simple solution is maybe to update

[3g] triplesOrGraph ::= labelOrSubject (wrappedGraph |  predicateObjectList '.')

into something like

[3g-star] triplesOrGraph ::= (labelOrSubject | embTriple) (wrappedGraph |  predicateObjectList '.')
pchampin commented 3 years ago

Thanks @Tpt for spotting that.

Either we integrate your test-case, or maybe we could do for Trig and Turtle was was alreadt done for Turtle and N-Triples, namely to duplicate the tests of the "subset" language into the testsuite of the "superset" language... But that's a lot a redundancy to maintain if we do that :-/

The production rule [3g-star] that you propose unfortunately does not work, as it allows an embedded triple in the subject position... It should rather look like:

[3g-star] triplesOrGraph ::= labelOrSubject (wrappedGraph |  predicateObjectList '.') | embTriple predicateObjectList '.'
gkellogg commented 3 years ago

The TriG-star tests already include many Turtle-star tests, including https://w3c.github.io/rdf-star/cg-spec/editors_draft.html#trig-star


:s :p :o .
<<:s :p :o>> :q 123 .

Also, the TriG-star section does say that it uses the Turtle-star productions and does not reference a complete (or partial) TriG grammar directly (@Tpt where did you take your grammar from?). The section should be updated to be more explicit on the grammar used, including something like @pchampin mentioned. As it is, it seems that, although there are tests, simply saying to use the Turtle-star grammar doesn't account for these parser paths.

Tpt commented 3 years ago

The production rule [3g-star] that you propose unfortunately does not work, as it allows an embedded triple in the subject position... It should rather look like:

Yes, indeed. Your grammar looks much better. Thank you!

Also, the TriG-star section does say that it uses the Turtle-star productions and does not reference a complete (or partial) TriG grammar directly (@Tpt where did you take your grammar from?).

I am using the RDF 1.1 TriG grammar on which I applied the Turtle-star grammar modification. I assumed it was what the working draft was suggesting as the expected "TriG-star" grammar.

The section should be updated to be more explicit on the grammar used, including something like @pchampin mentioned. As it is, it seems that, although there are tests, simply saying to use the Turtle-star grammar doesn't account for these parser paths.

Yes, it would be amazing! There also seems to be no explicit TriG-star test at the moment with annotated triples in the default graph. Rio passes all TriG-star test with just the Turtle-star grammar modification applied to the parser (thanks to @pchampin). However it fails on the test I provided.

gkellogg commented 3 years ago

Yes, it would be amazing! There also seems to be no explicit TriG-star test at the moment with annotated triples in the default graph. Rio passes all TriG-star test with just the Turtle-star grammar modification applied to the parser (thanks to @pchampin). However it fails on the test I provided.

The example I referenced above has an embedded triple in the subject position in the default graph. If you're referring to the annotation syntax, https://w3c.github.io/rdf-star/tests/trig/syntax/#turtle-star-ann-1 is in the default graph.

PREFIX : <http://example/>

:s :p :o {| :r :z |} .

But, the one mentioned in https://github.com/w3c/rdf-star/issues/187#issuecomment-860071126 seems to match your test case.

Tpt commented 3 years ago

If you're referring to the annotation syntax, https://w3c.github.io/rdf-star/tests/trig/syntax/#turtle-star-ann-1 is in the default graph.

Thank you! I did not thought about using Turtle-star tests to test our TriG-star parser. Sorry for the noise.