Skip to content

Commit

Permalink
Add trig.
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed Oct 24, 2023
1 parent 6953232 commit b7218d4
Show file tree
Hide file tree
Showing 529 changed files with 8,081 additions and 2,577 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
.PHONY: test fmt
.PHONY: test fmt report download

# Runs the tests.
test:
go test -v -cover ./...

# Formats the code and runs the linter.
fmt:
go mod tidy
gofmt -s -w .
goarrange run -r .
golangci-lint run ./...

# Generates a test report for the W3C test suite.
report:
TEST_SUITE_REPORT=true go test ./...

# Downloads the latest test suite from the W3C website.
download:
rm ntriples/testdata/suite/* && curl -s -L https://www.w3.org/2013/N-TriplesTests/TESTS.tar.gz | tar xvz - -C ntriples/testdata/suite
rm nquads/testdata/suite/* && curl -s -L https://www.w3.org/2013/N-QuadsTests/TESTS.tar.gz | tar xvz - -C nquads/testdata/suite
rm turtle/testdata/suite/* && curl -s -L https://www.w3.org/2013/TurtleTests/TESTS.tar.gz | tar xvz - -C turtle/testdata/suite
mv turtle/testdata/suite/TurtleTests/* turtle/testdata/suite && rmdir turtle/testdata/suite/TurtleTests # move files up one level
rm trig/testdata/suite/* && curl -s -L https://www.w3.org/2013/TrigTests/TESTS.tar.gz | tar xvz - -C trig/testdata/suite
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
|-----------|----------------------------------------------------|------------------|
| N-Triples | [report.ttl](./ntriples/testdata/suite/report.ttl) | 68/68 (100.0%) |
| N-Quads | [report.ttl](./nquads/testdata/suite/report.ttl) | 85/85 (100.0%) |
| Turtle | [report.ttl](./turtle/testdata/suite/report.ttl) | 291/291 (100.0%) |
| Turtle | [report.ttl](./turtle/testdata/suite/report.ttl) | 288/288 (100.0%) |
| Trig | [report.ttl](./trig/testdata/suite/report.ttl) | 332/332 (100.0%) |

## References

- [RDF 1.1 Concepts and Abstract Syntax](https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/)
- [RDF 1.1 Turtle](https://www.w3.org/TR/2014/REC-turtle-20140225/)
- [RDF 1.1 TriG](https://www.w3.org/TR/2014/REC-trig-20140225/)
- [RDF 1.1 N-Triples](https://www.w3.org/TR/2014/REC-n-triples-20140225/)
- [RDF 1.1 N-Quads](https://www.w3.org/TR/2014/REC-n-quads-20140225/)
- [Notation3 Language (Draft)](https://w3c.github.io/N3/reports/20230703/)
- [RDF Test Cases](https://www.w3.org/TR/2014/NOTE-rdf11-testcases-20140225/)
- [RDF-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html)
- [RDF 1.1 Test Cases](https://www.w3.org/TR/2014/NOTE-rdf11-testcases-20140225/)
- [RDF 1.1 Errata](https://www.w3.org/2001/sw/wiki/RDF1.1_Errata)
23 changes: 14 additions & 9 deletions internal/project/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package project
import (
"fmt"
"github.com/0x51-dev/rdf/internal/testsuite"
"github.com/0x51-dev/rdf/turtle"
ttl "github.com/0x51-dev/rdf/turtle"
"time"
)

var (
assertedBy = turtle.IRI{Value: "https://github.com/q-uint"}
subject = turtle.IRI{Value: "https://github.com/0x51-dev/rdf"}
assertedBy = ttl.IRI{Value: "https://github.com/q-uint"}
subject = ttl.IRI{Value: "https://github.com/0x51-dev/rdf"}
)

type Report struct {
test turtle.IRI
test ttl.IRI
r *testsuite.Report
}

func NewReport(test turtle.IRI) *Report {
func NewReport(test ttl.IRI) *Report {
r := testsuite.NewReport()
r.Project = testsuite.Project{
IRI: turtle.IRI{Value: "https://github.com/0x51-dev/rdf"},
IRI: ttl.IRI{Value: "https://github.com/0x51-dev/rdf"},
Name: "RDF",
Homepage: "https://github.com/0x51-dev/rdf",
License: "https://www.apache.org/licenses/LICENSE-2.0",
Expand All @@ -31,10 +31,11 @@ func NewReport(test turtle.IRI) *Report {
"https://www.w3.org/TR/n-triples/",
"https://www.w3.org/TR/n-quads/",
"https://www.w3.org/TR/turtle/",
"https://www.w3.org/TR/trig/",
},
Developer: []testsuite.Developer{
{
IRI: turtle.IRI{Value: "https://github.com/q-uint"},
IRI: ttl.IRI{Value: "https://github.com/q-uint"},
Name: "Quint Daenen",
Title: "Implementor",
MBox: "mailto:[email protected]",
Expand All @@ -46,12 +47,12 @@ func NewReport(test turtle.IRI) *Report {
}

func (r *Report) AddTest(name string, outcome testsuite.OutcomeValue) {
test := turtle.IRI{Prefixed: r.test.Prefixed, Value: fmt.Sprintf("%s%s", r.test.Value, name)}
test := ttl.IRI{Prefixed: r.test.Prefixed, Value: fmt.Sprintf("%s%s", r.test.Value, name)}
r.r.AddTestCase(testsuite.TestCase{
AssertedBy: assertedBy,
Mode: testsuite.Automatic,
Result: testsuite.TestResult{
Date: turtle.StringLiteral{
Date: ttl.StringLiteral{
Value: time.Now().In(time.UTC).Format("2006-01-02-0700"),
DatatypeIRI: "xsd:date",
},
Expand All @@ -62,6 +63,10 @@ func (r *Report) AddTest(name string, outcome testsuite.OutcomeValue) {
})
}

func (r *Report) Len() int {
return r.r.Len()
}

func (r *Report) String() string {
return r.r.String()
}
158 changes: 81 additions & 77 deletions internal/testsuite/report.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package testsuite

import (
"github.com/0x51-dev/rdf/turtle"
ttl "github.com/0x51-dev/rdf/turtle"
"time"
)

type Developer struct {
IRI turtle.IRI
IRI ttl.IRI
Name string
Title string
MBox string
Homepage string
}

func (d Developer) line() turtle.Statement {
var b turtle.Triple
func (d Developer) line() ttl.Statement {
var b ttl.Triple
b.Subject = d.IRI
b.PredicateObjectList = turtle.PredicateObjectList{
b.PredicateObjectList = ttl.PredicateObjectList{
{
Verb: new(turtle.A),
ObjectList: []turtle.Object{
&turtle.IRI{Prefixed: true, Value: "foaf:Person"},
&turtle.IRI{Prefixed: true, Value: "earl:Assertor"},
Verb: new(ttl.A),
ObjectList: []ttl.Object{
&ttl.IRI{Prefixed: true, Value: "foaf:Person"},
&ttl.IRI{Prefixed: true, Value: "earl:Assertor"},
},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "foaf:name"},
ObjectList: []turtle.Object{&turtle.StringLiteral{Value: d.Name}},
Verb: &ttl.IRI{Prefixed: true, Value: "foaf:name"},
ObjectList: []ttl.Object{&ttl.StringLiteral{Value: d.Name}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "foaf:title"},
ObjectList: []turtle.Object{&turtle.StringLiteral{Value: d.Title}},
Verb: &ttl.IRI{Prefixed: true, Value: "foaf:title"},
ObjectList: []ttl.Object{&ttl.StringLiteral{Value: d.Title}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "foaf:mbox"},
ObjectList: []turtle.Object{&turtle.IRI{Value: d.MBox}},
Verb: &ttl.IRI{Prefixed: true, Value: "foaf:mbox"},
ObjectList: []ttl.Object{&ttl.IRI{Value: d.MBox}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "foaf:homepage"},
ObjectList: []turtle.Object{&turtle.IRI{Value: d.Homepage}},
Verb: &ttl.IRI{Prefixed: true, Value: "foaf:homepage"},
ObjectList: []ttl.Object{&ttl.IRI{Value: d.Homepage}},
},
}
return &b
Expand All @@ -61,7 +61,7 @@ const (
)

type Project struct {
IRI turtle.IRI
IRI ttl.IRI
Name string
Homepage string
License string
Expand All @@ -72,76 +72,76 @@ type Project struct {
Developer []Developer
}

func (p Project) line() turtle.Statement {
var t turtle.Triple
func (p Project) line() ttl.Statement {
var t ttl.Triple
t.Subject = p.IRI
var implements []turtle.Object
var implements []ttl.Object
for _, i := range p.Implements {
implements = append(implements, &turtle.IRI{Value: i})
implements = append(implements, &ttl.IRI{Value: i})
}
var developers []turtle.Object
var developers []ttl.Object
for _, d := range p.Developer {
developers = append(developers, &d.IRI)
}
t.PredicateObjectList = []turtle.PredicateObject{
t.PredicateObjectList = []ttl.PredicateObject{
{
Verb: new(turtle.A),
ObjectList: []turtle.Object{&turtle.IRI{Prefixed: true, Value: "doap:Project"}},
Verb: new(ttl.A),
ObjectList: []ttl.Object{&ttl.IRI{Prefixed: true, Value: "doap:Project"}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:name"},
ObjectList: []turtle.Object{&turtle.StringLiteral{Value: p.Name}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:name"},
ObjectList: []ttl.Object{&ttl.StringLiteral{Value: p.Name}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:homepage"},
ObjectList: []turtle.Object{&turtle.IRI{Value: p.Homepage}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:homepage"},
ObjectList: []ttl.Object{&ttl.IRI{Value: p.Homepage}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:license"},
ObjectList: []turtle.Object{&turtle.IRI{Value: p.License}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:license"},
ObjectList: []ttl.Object{&ttl.IRI{Value: p.License}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:description"},
ObjectList: []turtle.Object{&turtle.StringLiteral{Value: p.Description, LanguageTag: "en"}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:description"},
ObjectList: []ttl.Object{&ttl.StringLiteral{Value: p.Description, LanguageTag: "en"}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:created"},
ObjectList: []turtle.Object{&turtle.StringLiteral{Value: p.Created.Format("2006-01-02-0700"), DatatypeIRI: "xsd:date"}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:created"},
ObjectList: []ttl.Object{&ttl.StringLiteral{Value: p.Created.Format("2006-01-02-0700"), DatatypeIRI: "xsd:date"}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:programming-language"},
ObjectList: []turtle.Object{&turtle.IRI{Value: p.ProgrammingLanguage}},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:programming-language"},
ObjectList: []ttl.Object{&ttl.IRI{Value: p.ProgrammingLanguage}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:implements"},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:implements"},
ObjectList: implements,
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "doap:developer"},
Verb: &ttl.IRI{Prefixed: true, Value: "doap:developer"},
ObjectList: developers,
},
}
return t
}

type Report struct {
prefixes []turtle.Statement
prefixes []ttl.Statement
Project Project
testcases []TestCase
}

func NewReport() *Report {
return &Report{
prefixes: []turtle.Statement{
&turtle.Prefix{Name: "dc:", IRI: "http://purl.org/dc/elements/1.1/"},
&turtle.Prefix{Name: "rdft:", IRI: "http://www.w3.org/ns/rdftest#"},
&turtle.Prefix{Name: "earl:", IRI: "http://www.w3.org/ns/earl#"},
&turtle.Prefix{Name: "foaf:", IRI: "http://xmlns.com/foaf/0.1/"},
&turtle.Prefix{Name: "turtletest:", IRI: "http://www.w3.org/2013/TurtleTests/manifest.ttl#"},
&turtle.Prefix{Name: "dct:", IRI: "http://purl.org/dc/terms/"},
&turtle.Prefix{Name: "xsd:", IRI: "http://www.w3.org/2001/XMLSchema#"},
&turtle.Prefix{Name: "rdf:", IRI: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
&turtle.Prefix{Name: "doap:", IRI: "http://usefulinc.com/ns/doap#"},
prefixes: []ttl.Statement{
&ttl.Prefix{Name: "dc:", IRI: "http://purl.org/dc/elements/1.1/"},
&ttl.Prefix{Name: "rdft:", IRI: "http://www.w3.org/ns/rdftest#"},
&ttl.Prefix{Name: "earl:", IRI: "http://www.w3.org/ns/earl#"},
&ttl.Prefix{Name: "foaf:", IRI: "http://xmlns.com/foaf/0.1/"},
&ttl.Prefix{Name: "turtletest:", IRI: "http://www.w3.org/2013/TurtleTests/manifest.ttl#"},
&ttl.Prefix{Name: "dct:", IRI: "http://purl.org/dc/terms/"},
&ttl.Prefix{Name: "xsd:", IRI: "http://www.w3.org/2001/XMLSchema#"},
&ttl.Prefix{Name: "rdf:", IRI: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
&ttl.Prefix{Name: "doap:", IRI: "http://usefulinc.com/ns/doap#"},
},
}
}
Expand All @@ -150,8 +150,12 @@ func (r *Report) AddTestCase(tc TestCase) {
r.testcases = append(r.testcases, tc)
}

func (r *Report) Len() int {
return len(r.testcases)
}

func (r *Report) String() string {
var d turtle.Document
var d ttl.Document
d = append(d, r.prefixes...)
for _, dev := range r.Project.Developer {
d = append(d, dev.line())
Expand All @@ -164,52 +168,52 @@ func (r *Report) String() string {
}

type TestCase struct {
AssertedBy turtle.IRI
AssertedBy ttl.IRI
Mode TestMode
Result TestResult
Subject turtle.IRI
Test turtle.IRI
Subject ttl.IRI
Test ttl.IRI
}

func (tc TestCase) line() turtle.Statement {
var b turtle.Triple
b.BlankNodePropertyList = turtle.BlankNodePropertyList{
func (tc TestCase) line() ttl.Statement {
var b ttl.Triple
b.BlankNodePropertyList = ttl.BlankNodePropertyList{
{
Verb: new(turtle.A),
ObjectList: []turtle.Object{&turtle.IRI{Prefixed: true, Value: "earl:Assertion"}},
Verb: new(ttl.A),
ObjectList: []ttl.Object{&ttl.IRI{Prefixed: true, Value: "earl:Assertion"}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:assertedBy"},
ObjectList: []turtle.Object{&tc.AssertedBy},
Verb: &ttl.IRI{Prefixed: true, Value: "earl:assertedBy"},
ObjectList: []ttl.Object{&tc.AssertedBy},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:mode"},
ObjectList: []turtle.Object{&turtle.IRI{Prefixed: true, Value: string(tc.Mode)}},
Verb: &ttl.IRI{Prefixed: true, Value: "earl:mode"},
ObjectList: []ttl.Object{&ttl.IRI{Prefixed: true, Value: string(tc.Mode)}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:result"},
ObjectList: []turtle.Object{turtle.BlankNodePropertyList{
Verb: &ttl.IRI{Prefixed: true, Value: "earl:result"},
ObjectList: []ttl.Object{ttl.BlankNodePropertyList{
{
Verb: new(turtle.A),
ObjectList: []turtle.Object{&turtle.IRI{Prefixed: true, Value: "earl:TestResult"}},
Verb: new(ttl.A),
ObjectList: []ttl.Object{&ttl.IRI{Prefixed: true, Value: "earl:TestResult"}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "dct:date"},
ObjectList: []turtle.Object{&tc.Result.Date},
Verb: &ttl.IRI{Prefixed: true, Value: "dct:date"},
ObjectList: []ttl.Object{&tc.Result.Date},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:outcome"},
ObjectList: []turtle.Object{&turtle.IRI{Prefixed: true, Value: string(tc.Result.Outcome)}},
Verb: &ttl.IRI{Prefixed: true, Value: "earl:outcome"},
ObjectList: []ttl.Object{&ttl.IRI{Prefixed: true, Value: string(tc.Result.Outcome)}},
},
}},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:subject"},
ObjectList: []turtle.Object{&tc.Subject},
Verb: &ttl.IRI{Prefixed: true, Value: "earl:subject"},
ObjectList: []ttl.Object{&tc.Subject},
},
{
Verb: &turtle.IRI{Prefixed: true, Value: "earl:test"},
ObjectList: []turtle.Object{&tc.Test},
Verb: &ttl.IRI{Prefixed: true, Value: "earl:test"},
ObjectList: []ttl.Object{&tc.Test},
},
}
return &b
Expand All @@ -235,6 +239,6 @@ const (
)

type TestResult struct {
Date turtle.StringLiteral
Date ttl.StringLiteral
Outcome OutcomeValue
}
Loading

0 comments on commit b7218d4

Please sign in to comment.