Re: [N3] What is the meaning of '=', 'has ...', and 'is ... of'?

Hi Vivien,

Some answers below:

> On Nov 12, 2023, at 5:38 PM, Vivien Kraus <vivien@planete-kraus.eu> wrote:
> 
> Dear Notation-3 authors,
> 
> In the process of implementing Solid, I am starting with a Notation-3
> parser. I made good progress, however I am still puzzled about a few
> aspects of the specification.
> 
> I intended to use the same parser for both Turtle and Notation3, but
> the incompatibility between N3 collections and RDF collections is
> worrying me a bit. It is not explicitely incompatible, but I wonder
> what would happen if a N3 PATCH request were to modify a RDF collection
> with a N3 syntax. This is a purely hypothetical problem right now, as
> Solid won’t accept blank nodes in PATCH requests.

Note that in the N3 spec, N3 collections are more than RDF collections with an easier syntax - they are terms <https://w3c.github.io/N3/reports/20230703/semantics.html#dfn-term> in their own right. The original member submission describes the latter <https://www.w3.org/TeamSubmission/n3/#lists> as a reification of the former, and shows how extra axioms can make N3 and RDF collections equivalent.


> I am leaning on the Turtle specification to know how to parse a stream
> of triples. I believe the parser state and productions described in the
> Turtle document could be adapted to Notation3 by simply recording the
> current formula and adjusting for pathes, but I may be missing
> something still.

(I am assuming you are aware of the N3 grammar <https://w3c.github.io/N3/reports/20230703/#grammar> and its EBNF format <https://w3c.github.io/N3/reports/20230703/n3.ebnf>). Regarding parser state, I used ANTLR to generate an N3 parser for jen3 (an N3-extended version of Apache Jena) and construct corresponding “N3Models” in the N3GraphInserter class <https://github.com/william-vw/jen3/blob/master/src/main/java/org/apache/jen3/n3/N3GraphInserter.java>. Maybe this can give you some ideas for your own parser (but, possibly some of the complexity there is no longer needed, as we are now avoiding explicit quantification(. Note that the spec also has some algorithms <https://w3c.github.io/N3/reports/20230703/#pathres> for path parsing, which can be quite tricky IMO - path resolution is also implemented in that class.

> I use a yacc/bison-like parser generator. It is possible to produce the
> triples (quads if we are working with formulas) in the correct order,
> but it requires overloading the IPLSTART, [, ( and { terminals with
> non-terminals (to mint the new node early) and make sure the triple
> with the new node is emitted only once. I also had to create a couple
> extra nonterminals to clear the state for path resolution. The
> formulaContent rule is hard to translate to yacc/bison, because of the
> separation dot after n3Statements. The rule for a collection is also
> hard to translate. I managed to bypass both problems by adding new
> rules.

Unsure what particular issues you ran into. Maybe the n3.g4 file <https://github.com/w3c/N3/blob/master/grammar/n3.g4> that I created for ANTLR can help.

> Other than that, I am not sure what the verb keywords "has expression",
> "is expression of" and "=" mean. I guess "is expression of" is the same
> as "<-". Maybe "has expression" is the same as "expression"? I don’t
> know for "=".

The “=“ is a shorthand for owl:sameAs (I believe this was copied from turtle) - you are right that it does not seem to be documented :-( The "is … of” production is described in the EBNF grammar section:

"The original N3 grammar allowed the inverting of a property by using the @is .. @of construct. But, this construct can be unintuitive when property names are more verbosely specified (e.g., :hasFather), leading to statements such as ?x @is :hasFather @of ?y. The is .. of construct is still supported, but the above statement can now be represented as follows: ?x <- :hasFather ?y.”


> In section Relationship to Other Languages, Turtle (5.1), you write
> about these keywords:
> 
>    All keywords can be optionally preceded by "@", for consistency   
>     with the "@prefix" and "@base" keywords.
> 
> I am not sure this is reflected in the grammar.

You are right, this statement is outdated - we chose to leave out the “@“ prefixes from the grammar.


Hope this helps.

William


> Best regards,
> 
> Vivien
> 
> 

Received on Monday, 13 November 2023 13:34:46 UTC