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

feat: add eval test cases for empty graph and isImpliedBy #202

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/N3Tests/graph/empty_graph.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@prefix : <http://example.com/> .

:a :b {} .
1 change: 1 addition & 0 deletions tests/N3Tests/graph/empty_graph.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<http://example.com/a> <http://example.com/b> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
5 changes: 5 additions & 0 deletions tests/N3Tests/graph/empty_graph_implies.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@prefix : <http://example.com/> .

{
{} => {}
} => {} .
2 changes: 2 additions & 0 deletions tests/N3Tests/graph/empty_graph_implies.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"true"^^<http://www.w3.org/2001/XMLSchema#boolean> <http://www.w3.org/2000/10/swap/log#implies> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> _:b0 .
_:b0 <http://www.w3.org/2000/10/swap/log#implies> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
3 changes: 3 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@prefix : <http://example.com/> .

:a <= :b .
2 changes: 2 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<http://example.com/a> <http://www.w3.org/2000/10/swap/log#isImpliedBy> <http://example.com/b> .
6 changes: 6 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy_bcRule.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix : <http://example.org/> .
:s :p {
{ ?a :b1 :c1 } <= { ?a :b :c } .
} .
{ :s :p ?O } => ?O .
6 changes: 6 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy_bcRule.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
?a <http://example.org/b1> <http://example.org/c1> _:b0 .
?a <http://example.org/b> <http://example.org/c> _:b1 .
_:b0 <http://www.w3.org/2000/10/swap/log#isImpliedBy> _:b1 _:b2 .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeswr yes I think that makes a lot of sense!

So it turns out that doesn't work on files like this because N3 doesn't fully support n-quads syntax, in particular having a graph term like this one.

Do you think it is worth opening up discussion as to whether this syntax should be supported in the spec @william-vw @josd .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeswr sorry I'm missing something - why do you want to use the n-quads syntax in these tests (as you say, it is not supported by the n3 syntax)?

Copy link
Member Author

@jeswr jeswr Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the results of eval tests are given in an n-quads format (in particular see the rdf-tests repo) as it is straightforward to parse and as such is a good syntax in which to unambiguously provide the expected result of parsing.

In terms of what I'm proposing, it is that in N3 the following:

@prefix : <http://example.org/> .
"a" :b { :c :d :e } .

Be considered equivalent to:

@prefix : <http://example.org/> .
"a" :b _:b0 .
:c :d :e _:b0 .

Parsers over in the RDF/JS world like N3.js already interpret the first statement as the following RDF/JS quads:

const result = [
quad(
  literal("a"),
  namedNode("http://example.org/b"),
  blankNode("b0"),
),
quad(
  namedNode("http://example.org/c"),
  namedNode("http://example.org/d"),
  namedNode("http://example.org/e"),
  blankNode("b0"),
)]

Copy link
Collaborator

@josd josd Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of what I'm proposing, it is that in N3 the following:

@prefix : <http://example.org/> .
"a" :b { :c :d :e } .

Be considered equivalent to:

@prefix : <http://example.org/> .
"a" :b _:b0 .
:c :d :e _:b0 .

They are different, the former uses a graph term, the latter uses a graph by reference.
I have added initial support for n-quads in eye and this example round trips fine:

$ cat nq2.n3
@prefix : <http://example.org/> .

"a" :b _:b0 .
:c :d :e _:b0 .
$ eye --quiet --nope nq2.n3 --pass
@prefix : <http://example.org/>.

"a" :b _:e_b0_1.
:c :d :e _:e_b0_1.

One can of course compose graph terms with the following rule in

$ cat nq3.n3
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix graph: <http://www.w3.org/2000/10/swap/graph#>.
@prefix : <http://example.org/> .

"a" :b _:b0 .
:c :d :e _:b0 .
:f :g :h _:b0 .

{   ?A ?B ?C.
    ({?D ?E ?F} {?D ?E ?F ?C} ?L) log:collectAllIn ?SCOPE.
    ?G graph:list ?L.
} => {
    ?A ?B ?G.
}.
$ eye --quiet --nope nq3.n3 --pass
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix graph: <http://www.w3.org/2000/10/swap/graph#>.
@prefix : <http://example.org/>.

"a" :b _:e_b0_1.
"a" :b {
    :c :d :e.
    :f :g :h.
}.
:c :d :e _:e_b0_1.
:f :g :h _:e_b0_1.
:c :d :e {
    :c :d :e.
    :f :g :h.
}.
:f :g :h {
    :c :d :e.
    :f :g :h.
}.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the results of eval tests are given in an n-quads format (in particular see the rdf-tests repo) as it is straightforward to parse and as such is a good syntax in which to unambiguously provide the expected result of parsing.

Why would n-quads be better to provide expected results - what would the graph label indicate? I'm not finding n-quads result files in the folder you reference (aside from the rdf-n-quads folder, but those are not result files). Not trying to be difficult here, I am just wondering what the added value would be for an individual results file.

It's a much bigger discussion, for sure, but I feel that graph terms can be used to group triples belonging to the same graph (these could be made "referentially transparent" as well).

<http://example.org/s> <http://example.org/p> _:b2 .
<http://example.org/s> <http://example.org/p> ?O _:b3 .
_:b3 <http://www.w3.org/2000/10/swap/log#implies> ?O .
7 changes: 7 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy_graphs.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@prefix : <http://example.com/> .

{
:a :b :c .
} <= {
:d :e :f .
} .
4 changes: 4 additions & 0 deletions tests/N3Tests/isImpliedBy/isImpliedBy_graphs.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<http://example.com/a> <http://example.com/b> <http://example.com/c> _:b0 .
<http://example.com/d> <http://example.com/e> <http://example.com/f> _:b1 .

_:b0 <http://www.w3.org/2000/10/swap/log#isImpliedBy> _:b1 .
40 changes: 40 additions & 0 deletions tests/N3Tests/manifest-parser.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,46 @@
mf:action <cwm_syntax/djb1.n3> ;
mf:name "djb1" .

:empty_graph_eval
a test:TestN3Eval ;
mf:action <graph/empty_graph.n3> ;
mf:result <graph/empty_graph.nq> ;
mf:name "Empty Graph Eval";
rdfs:comment "Empty Graph should be parsed as the the literal true";
rdft:approval rdft:Approved .

:empty_graph_implies_eval
a test:TestN3Eval ;
mf:action <graph/empty_graph_implies.n3> ;
mf:result <graph/empty_graph_implies.nq> ;
mf:name "Empty Graph Implies Eval";
rdfs:comment "Empty Graph should be parsed as the the literal true when in global scope and when in a premise";
rdft:approval rdft:Approved .

:isImpliedBy
a test:TestN3Eval ;
mf:action <isImpliedBy/isImpliedBy.n3> ;
mf:result <isImpliedBy/isImpliedBy.nq> ;
mf:name "isImpliedBy Eval";
rdfs:comment "<= should be parsed as log:isImpliedBy";
rdft:approval rdft:Approved .

:isImpliedBy_graphs
a test:TestN3Eval ;
mf:action <isImpliedBy/isImpliedBy_graphs.n3> ;
mf:result <isImpliedBy/isImpliedBy_graphs.nq> ;
mf:name "isImpliedBy Eval";
rdfs:comment "<= should be parsed as log:isImpliedBy in a complex use case";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure what is meant by complex use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either - resolved in 59f2ae7.

I don't have permissions to merge on this repo so will leave that to you.

jeswr marked this conversation as resolved.
Show resolved Hide resolved
rdft:approval rdft:Approved .

:isImpliedBy_bcRule
a test:TestN3Eval ;
mf:action <isImpliedBy/isImpliedBy_bcRule.n3> ;
mf:result <isImpliedBy/isImpliedBy_bcRule.nq> ;
mf:name "isImpliedBy Eval";
rdfs:comment "<= should be parsed as log:isImpliedBy in a bcRule";
rdft:approval rdft:Approved .

:cwm_syntax_djb1a.n3
a test:TestN3Eval ;
mf:action <cwm_syntax/djb1a.n3> ;
Expand Down