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

Rationale for allowing directives throughout an N3 Document #175

Open
jeswr opened this issue Apr 14, 2023 · 11 comments
Open

Rationale for allowing directives throughout an N3 Document #175

jeswr opened this issue Apr 14, 2023 · 11 comments
Labels
defer Deferring this issue until we have established the N3 standard.

Comments

@jeswr
Copy link
Member

jeswr commented Apr 14, 2023

I was wondering what the rationale for allowing @prefix and @base statements to occur in arbitrary positions throughout an N3 document was.

To me it seems quite messy and could create a lot of shadowing of prefixes and bases in different contexts. Why not just require that directives precede all statements?

@jeswr jeswr changed the title Rationale for allowing directives throughout the doc Rationale for allowing directives throughout an N3 Document Apr 14, 2023
@jeswr
Copy link
Member Author

jeswr commented Apr 14, 2023

Cases in particular the the spec does not explicitly define the behavior of are if I had the following; whether the last triple in the document should be <http://example.org/1/s> <http://example.org/1/p> <http://example.org/1/o> or <http://example.org/2/s> <http://example.org/2/p> <http://example.org/2/o>.

@prefix ex: <http://example.org/1/>

<a> <b> {
  @prefix ex: <http://example.org/2/>
}

ex:s ex:p :exo .

Whilst <http://example.org/1/s> <http://example.org/1/p> <http://example.org/1/o> is more sensible from a user perspective; it is also more difficult & CPU memory intensive to implement.

@william-vw
Copy link
Collaborator

@jeswr Good point. We currently mention the following about this:

We recommend listing @Prefix / PREFIX and @base / BASE declarations at the top of an N3 document. This is not mandatory, however, and they can technically be put anywhere before the prefixed name or relative IRI that relies on the declaration. Subsequent @Prefix / PREFIX directives may "re-map" the same prefix label to another namespace IRI.

Behavior is inconsistent between reasoners when remapping the namespace inside a quoted graph:
https://n3-editor.herokuapp.com/n3/editor/s/6TuP2UdU

IIRC, this decision was made in the original N3 proposal and was not revised afterwards.

Tying in @doerthe or @josd to help shed light on this.

@josd
Copy link
Collaborator

josd commented Apr 14, 2023

It is good to have declarations at the top of the file but it is another thing to throw exceptions when that is not the case.

@jeswr
Copy link
Member Author

jeswr commented Apr 14, 2023

If this is to remain in the spec (personally I would prefer an error to be thrown) then what do you think the correct behaviour for #175 (comment) would be @josd ?

@josd
Copy link
Collaborator

josd commented Apr 14, 2023

The behaviour of Cwm and EYE ;-)
For

@prefix ex: <http://example.org/1/> .
@prefix : <http://example.org/> .

<a> <b> {
  @prefix ex: <http://example.org/2/> .
} .

ex:s ex:p :exo .

Cwm gives

             @prefix : <./> .
    @prefix ex_: <http://example.org/2/> .

    :a     :b {} .

    ex_:s     ex_:p <#exo> .

and EYE gives

@prefix ex: <http://example.org/1/>.
@prefix : <http://example.org/>.
@prefix ns1: <http://example.org/2/>.

<file:///app/tmp/a> <file:///app/tmp/b> true.
ns1:s ns1:p :exo.

@josd
Copy link
Collaborator

josd commented Apr 14, 2023

Also remark that this behaviour is also needed for the namespace prefixes declared in graphs obtained via log:semantics.

@gkellogg
Copy link
Member

gkellogg commented Apr 14, 2023

It is good to have declarations at the top of the file but it is another thing to throw exceptions when that is not the case.

It’s interesting that N3 allows declarations anywhere you can have a statement; Turtle does this too, but does not have graph blocks. TriG only allows them outside of blocks, so anyplace at the top level.

Note that declarations are additive, so you can have an @base declaration use a relative IRI which makes it relative to either the document location or a previous @base. Scoping should be to the block in which it is contained, although I don’t believe there are any tests for this.

In actual use, there’s little reason to have declarations anywhere but at the top of the document; anything else could lead to at least human misinterpretation and doesn’t add any semantic value.

@william-vw
Copy link
Collaborator

Also remark that this behaviour is also needed for the namespace prefixes declared in graphs obtained via log:semantics.

In that case, I would expect the namespace declaration to only be applicable within the quoted graph, and not beyond it, as in @jeswr 's example.

@TallTed
Copy link
Member

TallTed commented Apr 17, 2023

@william-vw — Please edit #175 (comment) and wrap each instance of @base and @prefix in backticks (like `@base`), so that those GitHub users are not drawn into this thread without their consent or interest.

@TallTed
Copy link
Member

TallTed commented Apr 17, 2023

@gkellogg — Please edit #175 (comment) and wrap each instance of @base in backticks (like `@base`), so that those GitHub users are not drawn into this thread without their consent or interest.

@TallTed
Copy link
Member

TallTed commented Apr 17, 2023

In actual use, there’s little reason to have declarations anywhere but at the top of the document

Concatenating files is a common cause of declarations being elsewhere, and seems (based on conversation and thread content; I have no empirical data) to be a fairly common actual use case.

@william-vw william-vw added the defer Deferring this issue until we have established the N3 standard. label Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defer Deferring this issue until we have established the N3 standard.
Projects
None yet
Development

No branches or pull requests

5 participants