Use concrete value for quad.Quad
Comparison of -short benchmarks in cayley.
$ benchcmp pointer.bench concrete.bench
benchmark old ns/op new ns/op delta
BenchmarkNamePredicate 1673276 1655093 -1.09%
BenchmarkLargeSetsNoIntersection 318985907 261499984 -18.02%
BenchmarkNetAndSpeed 104403743 41516981 -60.23%
BenchmarkKeanuAndNet 17309258 16857513 -2.61%
BenchmarkKeanuAndSpeed 20159161 19282833 -4.35%
Comparison of pathological cases are not so happy.
benchmark old ns/op new ns/op delta
BenchmarkVeryLargeSetsSmallIntersection 55269775527 246084606672 +345.24%
BenchmarkHelplessContainsChecker 23436501319 24308906949 +3.72%
Profiling the worst case:
Pointer:
Total: 6121 samples
1973 32.2% 32.2% 1973 32.2% runtime.findfunc
773 12.6% 44.9% 773 12.6% readvarint
510 8.3% 53.2% 511 8.3% step
409 6.7% 59.9% 410 6.7% runtime.gentraceback
390 6.4% 66.2% 391 6.4% pcvalue
215 3.5% 69.8% 215 3.5% runtime.funcdata
181 3.0% 72.7% 181 3.0% checkframecopy
118 1.9% 74.6% 119 1.9% runtime.funcspdelta
96 1.6% 76.2% 96 1.6% runtime.topofstack
76 1.2% 77.5% 76 1.2% scanblock
Concrete:
Total: 25027 samples
9437 37.7% 37.7% 9437 37.7% runtime.findfunc
3853 15.4% 53.1% 3853 15.4% readvarint
2366 9.5% 62.6% 2366 9.5% step
2186 8.7% 71.3% 2186 8.7% runtime.gentraceback
1816 7.3% 78.5% 1816 7.3% pcvalue
1016 4.1% 82.6% 1016 4.1% runtime.funcdata
859 3.4% 86.0% 859 3.4% checkframecopy
506 2.0% 88.1% 506 2.0% runtime.funcspdelta
410 1.6% 89.7% 410 1.6% runtime.topofstack
303 1.2% 90.9% 303 1.2% runtime.newstack
This commit is contained in:
parent
1ae81e6d00
commit
6acfdcc5d6
19 changed files with 183 additions and 183 deletions
|
|
@ -57,7 +57,7 @@ func Load(ts graph.TripleStore, cfg *config.Config, path string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
block := make([]*quad.Quad, 0, cfg.LoadSize)
|
block := make([]quad.Quad, 0, cfg.LoadSize)
|
||||||
for {
|
for {
|
||||||
t, err := dec.Unmarshal()
|
t, err := dec.Unmarshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) error
|
||||||
if bytes.HasPrefix(line, []byte(":a")) {
|
if bytes.HasPrefix(line, []byte(":a")) {
|
||||||
var tripleStmt = line[3:]
|
var tripleStmt = line[3:]
|
||||||
triple, err := cquads.Parse(string(tripleStmt))
|
triple, err := cquads.Parse(string(tripleStmt))
|
||||||
if triple == nil {
|
if !triple.IsValid() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("not a valid triple: %v\n", err)
|
fmt.Printf("not a valid triple: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) error
|
||||||
if bytes.HasPrefix(line, []byte(":d")) {
|
if bytes.HasPrefix(line, []byte(":d")) {
|
||||||
var tripleStmt = line[3:]
|
var tripleStmt = line[3:]
|
||||||
triple, err := cquads.Parse(string(tripleStmt))
|
triple, err := cquads.Parse(string(tripleStmt))
|
||||||
if triple == nil {
|
if !triple.IsValid() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("not a valid triple: %v\n", err)
|
fmt.Printf("not a valid triple: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ func (qs *store) ValueOf(s string) graph.Value {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *store) AddTriple(*quad.Quad) {}
|
func (qs *store) AddTriple(quad.Quad) {}
|
||||||
|
|
||||||
func (qs *store) AddTripleSet([]*quad.Quad) {}
|
func (qs *store) AddTripleSet([]quad.Quad) {}
|
||||||
|
|
||||||
func (qs *store) Quad(graph.Value) *quad.Quad { return &quad.Quad{} }
|
func (qs *store) Quad(graph.Value) quad.Quad { return quad.Quad{} }
|
||||||
|
|
||||||
func (qs *store) TripleIterator(d quad.Direction, i graph.Value) graph.Iterator {
|
func (qs *store) TripleIterator(d quad.Direction, i graph.Value) graph.Iterator {
|
||||||
return qs.iter
|
return qs.iter
|
||||||
|
|
@ -74,4 +74,4 @@ func (qs *store) Close() {}
|
||||||
|
|
||||||
func (qs *store) TripleDirection(graph.Value, quad.Direction) graph.Value { return 0 }
|
func (qs *store) TripleDirection(graph.Value, quad.Direction) graph.Value { return 0 }
|
||||||
|
|
||||||
func (qs *store) RemoveTriple(t *quad.Quad) {}
|
func (qs *store) RemoveTriple(t quad.Quad) {}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"github.com/google/cayley/quad"
|
"github.com/google/cayley/quad"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeTripleSet() []*quad.Quad {
|
func makeTripleSet() []quad.Quad {
|
||||||
tripleSet := []*quad.Quad{
|
tripleSet := []quad.Quad{
|
||||||
{"A", "follows", "B", ""},
|
{"A", "follows", "B", ""},
|
||||||
{"C", "follows", "B", ""},
|
{"C", "follows", "B", ""},
|
||||||
{"C", "follows", "D", ""},
|
{"C", "follows", "D", ""},
|
||||||
|
|
@ -43,7 +43,7 @@ func makeTripleSet() []*quad.Quad {
|
||||||
return tripleSet
|
return tripleSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func iteratedTriples(qs graph.TripleStore, it graph.Iterator) []*quad.Quad {
|
func iteratedTriples(qs graph.TripleStore, it graph.Iterator) []quad.Quad {
|
||||||
var res ordered
|
var res ordered
|
||||||
for {
|
for {
|
||||||
val, ok := graph.Next(it)
|
val, ok := graph.Next(it)
|
||||||
|
|
@ -56,7 +56,7 @@ func iteratedTriples(qs graph.TripleStore, it graph.Iterator) []*quad.Quad {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
type ordered []*quad.Quad
|
type ordered []quad.Quad
|
||||||
|
|
||||||
func (o ordered) Len() int { return len(o) }
|
func (o ordered) Len() int { return len(o) }
|
||||||
func (o ordered) Less(i, j int) bool {
|
func (o ordered) Less(i, j int) bool {
|
||||||
|
|
@ -143,7 +143,7 @@ func TestLoadDatabase(t *testing.T) {
|
||||||
t.Error("Failed to create leveldb TripleStore.")
|
t.Error("Failed to create leveldb TripleStore.")
|
||||||
}
|
}
|
||||||
|
|
||||||
qs.AddTriple(&quad.Quad{"Something", "points_to", "Something Else", "context"})
|
qs.AddTriple(quad.Quad{"Something", "points_to", "Something Else", "context"})
|
||||||
for _, pq := range []string{"Something", "points_to", "Something Else", "context"} {
|
for _, pq := range []string{"Something", "points_to", "Something Else", "context"} {
|
||||||
if got := qs.NameOf(qs.ValueOf(pq)); got != pq {
|
if got := qs.NameOf(qs.ValueOf(pq)); got != pq {
|
||||||
t.Errorf("Failed to roundtrip %q, got:%q expect:%q", pq, got, pq)
|
t.Errorf("Failed to roundtrip %q, got:%q expect:%q", pq, got, pq)
|
||||||
|
|
@ -176,7 +176,7 @@ func TestLoadDatabase(t *testing.T) {
|
||||||
t.Errorf("Unexpected triplestore size, got:%d expect:5", s)
|
t.Errorf("Unexpected triplestore size, got:%d expect:5", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
qs.RemoveTriple(&quad.Quad{"A", "follows", "B", ""})
|
qs.RemoveTriple(quad.Quad{"A", "follows", "B", ""})
|
||||||
if s := qs.Size(); s != 10 {
|
if s := qs.Size(); s != 10 {
|
||||||
t.Errorf("Unexpected triplestore size after RemoveTriple, got:%d expect:10", s)
|
t.Errorf("Unexpected triplestore size after RemoveTriple, got:%d expect:10", s)
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +301,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
|
|
||||||
qs.AddTripleSet(makeTripleSet())
|
qs.AddTripleSet(makeTripleSet())
|
||||||
|
|
||||||
expect := []*quad.Quad{
|
expect := []quad.Quad{
|
||||||
{"C", "follows", "B", ""},
|
{"C", "follows", "B", ""},
|
||||||
{"C", "follows", "D", ""},
|
{"C", "follows", "D", ""},
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +326,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
// Object iterator.
|
// Object iterator.
|
||||||
it = qs.TripleIterator(quad.Object, qs.ValueOf("F"))
|
it = qs.TripleIterator(quad.Object, qs.ValueOf("F"))
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "follows", "F", ""},
|
{"B", "follows", "F", ""},
|
||||||
{"E", "follows", "F", ""},
|
{"E", "follows", "F", ""},
|
||||||
}
|
}
|
||||||
|
|
@ -339,7 +339,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "follows", "F", ""},
|
{"B", "follows", "F", ""},
|
||||||
}
|
}
|
||||||
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
||||||
|
|
@ -349,7 +349,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
// Predicate iterator.
|
// Predicate iterator.
|
||||||
it = qs.TripleIterator(quad.Predicate, qs.ValueOf("status"))
|
it = qs.TripleIterator(quad.Predicate, qs.ValueOf("status"))
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "status", "cool", "status_graph"},
|
{"B", "status", "cool", "status_graph"},
|
||||||
{"D", "status", "cool", "status_graph"},
|
{"D", "status", "cool", "status_graph"},
|
||||||
{"G", "status", "cool", "status_graph"},
|
{"G", "status", "cool", "status_graph"},
|
||||||
|
|
@ -362,7 +362,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
// Label iterator.
|
// Label iterator.
|
||||||
it = qs.TripleIterator(quad.Label, qs.ValueOf("status_graph"))
|
it = qs.TripleIterator(quad.Label, qs.ValueOf("status_graph"))
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "status", "cool", "status_graph"},
|
{"B", "status", "cool", "status_graph"},
|
||||||
{"D", "status", "cool", "status_graph"},
|
{"D", "status", "cool", "status_graph"},
|
||||||
{"G", "status", "cool", "status_graph"},
|
{"G", "status", "cool", "status_graph"},
|
||||||
|
|
@ -378,7 +378,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "status", "cool", "status_graph"},
|
{"B", "status", "cool", "status_graph"},
|
||||||
}
|
}
|
||||||
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
||||||
|
|
@ -391,7 +391,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
and.AddSubIterator(qs.TripleIterator(quad.Subject, qs.ValueOf("B")))
|
||||||
|
|
||||||
expect = []*quad.Quad{
|
expect = []quad.Quad{
|
||||||
{"B", "status", "cool", "status_graph"},
|
{"B", "status", "cool", "status_graph"},
|
||||||
}
|
}
|
||||||
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
if got := iteratedTriples(qs, and); !reflect.DeepEqual(got, expect) {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func (qs *TripleStore) Size() int64 {
|
||||||
return qs.size
|
return qs.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) createKeyFor(d [3]quad.Direction, triple *quad.Quad) []byte {
|
func (qs *TripleStore) createKeyFor(d [3]quad.Direction, triple quad.Quad) []byte {
|
||||||
key := make([]byte, 0, 2+(qs.hasher.Size()*3))
|
key := make([]byte, 0, 2+(qs.hasher.Size()*3))
|
||||||
// TODO(kortschak) Remove dependence on String() method.
|
// TODO(kortschak) Remove dependence on String() method.
|
||||||
key = append(key, []byte{d[0].Prefix(), d[1].Prefix()}...)
|
key = append(key, []byte{d[0].Prefix(), d[1].Prefix()}...)
|
||||||
|
|
@ -126,7 +126,7 @@ func (qs *TripleStore) createKeyFor(d [3]quad.Direction, triple *quad.Quad) []by
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) createProvKeyFor(d [3]quad.Direction, triple *quad.Quad) []byte {
|
func (qs *TripleStore) createProvKeyFor(d [3]quad.Direction, triple quad.Quad) []byte {
|
||||||
key := make([]byte, 0, 2+(qs.hasher.Size()*4))
|
key := make([]byte, 0, 2+(qs.hasher.Size()*4))
|
||||||
// TODO(kortschak) Remove dependence on String() method.
|
// TODO(kortschak) Remove dependence on String() method.
|
||||||
key = append(key, []byte{quad.Label.Prefix(), d[0].Prefix()}...)
|
key = append(key, []byte{quad.Label.Prefix(), d[0].Prefix()}...)
|
||||||
|
|
@ -144,7 +144,7 @@ func (qs *TripleStore) createValueKeyFor(s string) []byte {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) AddTriple(t *quad.Quad) {
|
func (qs *TripleStore) AddTriple(t quad.Quad) {
|
||||||
batch := &leveldb.Batch{}
|
batch := &leveldb.Batch{}
|
||||||
qs.buildWrite(batch, t)
|
qs.buildWrite(batch, t)
|
||||||
err := qs.db.Write(batch, qs.writeopts)
|
err := qs.db.Write(batch, qs.writeopts)
|
||||||
|
|
@ -163,7 +163,7 @@ var (
|
||||||
pso = [3]quad.Direction{quad.Predicate, quad.Subject, quad.Object}
|
pso = [3]quad.Direction{quad.Predicate, quad.Subject, quad.Object}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
func (qs *TripleStore) RemoveTriple(t quad.Quad) {
|
||||||
_, err := qs.db.Get(qs.createKeyFor(spo, t), qs.readopts)
|
_, err := qs.db.Get(qs.createKeyFor(spo, t), qs.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
glog.Error("Couldn't access DB to confirm deletion")
|
glog.Error("Couldn't access DB to confirm deletion")
|
||||||
|
|
@ -192,8 +192,8 @@ func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
||||||
qs.size--
|
qs.size--
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *quad.Quad) {
|
func (qs *TripleStore) buildTripleWrite(batch *leveldb.Batch, t quad.Quad) {
|
||||||
bytes, err := json.Marshal(*t)
|
bytes, err := json.Marshal(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't write to buffer for triple %s: %s", t, err)
|
glog.Errorf("Couldn't write to buffer for triple %s: %s", t, err)
|
||||||
return
|
return
|
||||||
|
|
@ -206,7 +206,7 @@ func (qs *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *quad.Quad) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) buildWrite(batch *leveldb.Batch, t *quad.Quad) {
|
func (qs *TripleStore) buildWrite(batch *leveldb.Batch, t quad.Quad) {
|
||||||
qs.buildTripleWrite(batch, t)
|
qs.buildTripleWrite(batch, t)
|
||||||
qs.UpdateValueKeyBy(t.Get(quad.Subject), 1, nil)
|
qs.UpdateValueKeyBy(t.Get(quad.Subject), 1, nil)
|
||||||
qs.UpdateValueKeyBy(t.Get(quad.Predicate), 1, nil)
|
qs.UpdateValueKeyBy(t.Get(quad.Predicate), 1, nil)
|
||||||
|
|
@ -267,7 +267,7 @@ func (qs *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) AddTripleSet(t_s []*quad.Quad) {
|
func (qs *TripleStore) AddTripleSet(t_s []quad.Quad) {
|
||||||
batch := &leveldb.Batch{}
|
batch := &leveldb.Batch{}
|
||||||
newTs := len(t_s)
|
newTs := len(t_s)
|
||||||
resizeMap := make(map[string]int)
|
resizeMap := make(map[string]int)
|
||||||
|
|
@ -306,23 +306,23 @@ func (qs *TripleStore) Close() {
|
||||||
qs.open = false
|
qs.open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) Quad(k graph.Value) *quad.Quad {
|
func (qs *TripleStore) Quad(k graph.Value) quad.Quad {
|
||||||
var triple quad.Quad
|
var triple quad.Quad
|
||||||
b, err := qs.db.Get(k.([]byte), qs.readopts)
|
b, err := qs.db.Get(k.([]byte), qs.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
glog.Error("Error: couldn't get triple from DB.")
|
glog.Error("Error: couldn't get triple from DB.")
|
||||||
return &quad.Quad{}
|
return quad.Quad{}
|
||||||
}
|
}
|
||||||
if err == leveldb.ErrNotFound {
|
if err == leveldb.ErrNotFound {
|
||||||
// No harm, no foul.
|
// No harm, no foul.
|
||||||
return &quad.Quad{}
|
return quad.Quad{}
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(b, &triple)
|
err = json.Unmarshal(b, &triple)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("Error: couldn't reconstruct triple.")
|
glog.Error("Error: couldn't reconstruct triple.")
|
||||||
return &quad.Quad{}
|
return quad.Quad{}
|
||||||
}
|
}
|
||||||
return &triple
|
return triple
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) convertStringToByteHash(s string) []byte {
|
func (qs *TripleStore) convertStringToByteHash(s string) []byte {
|
||||||
|
|
|
||||||
|
|
@ -101,13 +101,13 @@ func newTripleStore() *TripleStore {
|
||||||
return &ts
|
return &ts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) AddTripleSet(triples []*quad.Quad) {
|
func (ts *TripleStore) AddTripleSet(triples []quad.Quad) {
|
||||||
for _, t := range triples {
|
for _, t := range triples {
|
||||||
ts.AddTriple(t)
|
ts.AddTriple(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) tripleExists(t *quad.Quad) (bool, int64) {
|
func (ts *TripleStore) tripleExists(t quad.Quad) (bool, int64) {
|
||||||
smallest := -1
|
smallest := -1
|
||||||
var smallest_tree *llrb.LLRB
|
var smallest_tree *llrb.LLRB
|
||||||
for d := quad.Subject; d <= quad.Label; d++ {
|
for d := quad.Subject; d <= quad.Label; d++ {
|
||||||
|
|
@ -137,19 +137,19 @@ func (ts *TripleStore) tripleExists(t *quad.Quad) (bool, int64) {
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if t.Equals(&ts.triples[val.(int64)]) {
|
if t.Equals(ts.triples[val.(int64)]) {
|
||||||
return true, val.(int64)
|
return true, val.(int64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) AddTriple(t *quad.Quad) {
|
func (ts *TripleStore) AddTriple(t quad.Quad) {
|
||||||
if exists, _ := ts.tripleExists(t); exists {
|
if exists, _ := ts.tripleExists(t); exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var tripleID int64
|
var tripleID int64
|
||||||
ts.triples = append(ts.triples, *t)
|
ts.triples = append(ts.triples, t)
|
||||||
tripleID = ts.tripleIdCounter
|
tripleID = ts.tripleIdCounter
|
||||||
ts.size++
|
ts.size++
|
||||||
ts.tripleIdCounter++
|
ts.tripleIdCounter++
|
||||||
|
|
@ -178,7 +178,7 @@ func (ts *TripleStore) AddTriple(t *quad.Quad) {
|
||||||
// TODO(barakmich): Add VIP indexing
|
// TODO(barakmich): Add VIP indexing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) RemoveTriple(t *quad.Quad) {
|
func (ts *TripleStore) RemoveTriple(t quad.Quad) {
|
||||||
var tripleID int64
|
var tripleID int64
|
||||||
var exists bool
|
var exists bool
|
||||||
tripleID = 0
|
tripleID = 0
|
||||||
|
|
@ -224,8 +224,8 @@ func (ts *TripleStore) RemoveTriple(t *quad.Quad) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) Quad(index graph.Value) *quad.Quad {
|
func (ts *TripleStore) Quad(index graph.Value) quad.Quad {
|
||||||
return &ts.triples[index.(int64)]
|
return ts.triples[index.(int64)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) TripleIterator(d quad.Direction, value graph.Value) graph.Iterator {
|
func (ts *TripleStore) TripleIterator(d quad.Direction, value graph.Value) graph.Iterator {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import (
|
||||||
// \-->|#D#|------------->+---+
|
// \-->|#D#|------------->+---+
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
var simpleGraph = []*quad.Quad{
|
var simpleGraph = []quad.Quad{
|
||||||
{"A", "follows", "B", ""},
|
{"A", "follows", "B", ""},
|
||||||
{"C", "follows", "B", ""},
|
{"C", "follows", "B", ""},
|
||||||
{"C", "follows", "D", ""},
|
{"C", "follows", "D", ""},
|
||||||
|
|
@ -51,7 +51,7 @@ var simpleGraph = []*quad.Quad{
|
||||||
{"G", "status", "cool", "status_graph"},
|
{"G", "status", "cool", "status_graph"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestStore(data []*quad.Quad) (*TripleStore, []pair) {
|
func makeTestStore(data []quad.Quad) (*TripleStore, []pair) {
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
ts := newTripleStore()
|
ts := newTripleStore()
|
||||||
var (
|
var (
|
||||||
|
|
@ -175,7 +175,7 @@ func TestLinksToOptimization(t *testing.T) {
|
||||||
func TestRemoveTriple(t *testing.T) {
|
func TestRemoveTriple(t *testing.T) {
|
||||||
ts, _ := makeTestStore(simpleGraph)
|
ts, _ := makeTestStore(simpleGraph)
|
||||||
|
|
||||||
ts.RemoveTriple(&quad.Quad{"E", "follows", "F", ""})
|
ts.RemoveTriple(quad.Quad{"E", "follows", "F", ""})
|
||||||
|
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.Add(ts.ValueOf("E"))
|
fixed.Add(ts.ValueOf("E"))
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func newTripleStore(addr string, options graph.Options) (graph.TripleStore, erro
|
||||||
return &qs, nil
|
return &qs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) getIdForTriple(t *quad.Quad) string {
|
func (qs *TripleStore) getIdForTriple(t quad.Quad) string {
|
||||||
id := qs.ConvertStringToByteHash(t.Subject)
|
id := qs.ConvertStringToByteHash(t.Subject)
|
||||||
id += qs.ConvertStringToByteHash(t.Predicate)
|
id += qs.ConvertStringToByteHash(t.Predicate)
|
||||||
id += qs.ConvertStringToByteHash(t.Object)
|
id += qs.ConvertStringToByteHash(t.Object)
|
||||||
|
|
@ -150,7 +150,7 @@ func (qs *TripleStore) updateNodeBy(node_name string, inc int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) writeTriple(t *quad.Quad) bool {
|
func (qs *TripleStore) writeTriple(t quad.Quad) bool {
|
||||||
tripledoc := bson.M{
|
tripledoc := bson.M{
|
||||||
"_id": qs.getIdForTriple(t),
|
"_id": qs.getIdForTriple(t),
|
||||||
"Subject": t.Subject,
|
"Subject": t.Subject,
|
||||||
|
|
@ -170,7 +170,7 @@ func (qs *TripleStore) writeTriple(t *quad.Quad) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) AddTriple(t *quad.Quad) {
|
func (qs *TripleStore) AddTriple(t quad.Quad) {
|
||||||
_ = qs.writeTriple(t)
|
_ = qs.writeTriple(t)
|
||||||
qs.updateNodeBy(t.Subject, 1)
|
qs.updateNodeBy(t.Subject, 1)
|
||||||
qs.updateNodeBy(t.Predicate, 1)
|
qs.updateNodeBy(t.Predicate, 1)
|
||||||
|
|
@ -180,7 +180,7 @@ func (qs *TripleStore) AddTriple(t *quad.Quad) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) AddTripleSet(in []*quad.Quad) {
|
func (qs *TripleStore) AddTripleSet(in []quad.Quad) {
|
||||||
qs.session.SetSafe(nil)
|
qs.session.SetSafe(nil)
|
||||||
ids := make(map[string]int)
|
ids := make(map[string]int)
|
||||||
for _, t := range in {
|
for _, t := range in {
|
||||||
|
|
@ -200,7 +200,7 @@ func (qs *TripleStore) AddTripleSet(in []*quad.Quad) {
|
||||||
qs.session.SetSafe(&mgo.Safe{})
|
qs.session.SetSafe(&mgo.Safe{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
func (qs *TripleStore) RemoveTriple(t quad.Quad) {
|
||||||
err := qs.db.C("triples").RemoveId(qs.getIdForTriple(t))
|
err := qs.db.C("triples").RemoveId(qs.getIdForTriple(t))
|
||||||
if err == mgo.ErrNotFound {
|
if err == mgo.ErrNotFound {
|
||||||
return
|
return
|
||||||
|
|
@ -216,13 +216,13 @@ func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *TripleStore) Quad(val graph.Value) *quad.Quad {
|
func (qs *TripleStore) Quad(val graph.Value) quad.Quad {
|
||||||
var bsonDoc bson.M
|
var bsonDoc bson.M
|
||||||
err := qs.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
err := qs.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error: Couldn't retrieve triple %s %v", val, err)
|
glog.Errorf("Error: Couldn't retrieve triple %s %v", val, err)
|
||||||
}
|
}
|
||||||
return &quad.Quad{
|
return quad.Quad{
|
||||||
bsonDoc["Subject"].(string),
|
bsonDoc["Subject"].(string),
|
||||||
bsonDoc["Predicate"].(string),
|
bsonDoc["Predicate"].(string),
|
||||||
bsonDoc["Object"].(string),
|
bsonDoc["Object"].(string),
|
||||||
|
|
|
||||||
|
|
@ -40,17 +40,17 @@ type Value interface{}
|
||||||
|
|
||||||
type TripleStore interface {
|
type TripleStore interface {
|
||||||
// Add a triple to the store.
|
// Add a triple to the store.
|
||||||
AddTriple(*quad.Quad)
|
AddTriple(quad.Quad)
|
||||||
|
|
||||||
// Add a set of triples to the store, atomically if possible.
|
// Add a set of triples to the store, atomically if possible.
|
||||||
AddTripleSet([]*quad.Quad)
|
AddTripleSet([]quad.Quad)
|
||||||
|
|
||||||
// Removes a triple matching the given one from the database,
|
// Removes a triple matching the given one from the database,
|
||||||
// if it exists. Does nothing otherwise.
|
// if it exists. Does nothing otherwise.
|
||||||
RemoveTriple(*quad.Quad)
|
RemoveTriple(quad.Quad)
|
||||||
|
|
||||||
// Given an opaque token, returns the triple for that token from the store.
|
// Given an opaque token, returns the triple for that token from the store.
|
||||||
Quad(Value) *quad.Quad
|
Quad(Value) quad.Quad
|
||||||
|
|
||||||
// Given a direction and a token, creates an iterator of links which have
|
// Given a direction and a token, creates an iterator of links which have
|
||||||
// that node token in that directional field.
|
// that node token in that directional field.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
var parseTests = []struct {
|
var parseTests = []struct {
|
||||||
message string
|
message string
|
||||||
input string
|
input string
|
||||||
expect []*quad.Quad
|
expect []quad.Quad
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +34,7 @@ var parseTests = []struct {
|
||||||
{"subject": "foo", "predicate": "bar", "object": "baz"},
|
{"subject": "foo", "predicate": "bar", "object": "baz"},
|
||||||
{"subject": "foo", "predicate": "bar", "object": "baz", "label": "graph"}
|
{"subject": "foo", "predicate": "bar", "object": "baz", "label": "graph"}
|
||||||
]`,
|
]`,
|
||||||
expect: []*quad.Quad{
|
expect: []quad.Quad{
|
||||||
{"foo", "bar", "baz", ""},
|
{"foo", "bar", "baz", ""},
|
||||||
{"foo", "bar", "baz", "graph"},
|
{"foo", "bar", "baz", "graph"},
|
||||||
},
|
},
|
||||||
|
|
@ -45,7 +45,7 @@ var parseTests = []struct {
|
||||||
input: `[
|
input: `[
|
||||||
{"subject": "foo", "predicate": "bar", "object": "foo", "something_else": "extra data"}
|
{"subject": "foo", "predicate": "bar", "object": "foo", "something_else": "extra data"}
|
||||||
]`,
|
]`,
|
||||||
expect: []*quad.Quad{
|
expect: []quad.Quad{
|
||||||
{"foo", "bar", "foo", ""},
|
{"foo", "bar", "foo", ""},
|
||||||
},
|
},
|
||||||
err: nil,
|
err: nil,
|
||||||
|
|
@ -56,7 +56,7 @@ var parseTests = []struct {
|
||||||
{"subject": "foo", "predicate": "bar"}
|
{"subject": "foo", "predicate": "bar"}
|
||||||
]`,
|
]`,
|
||||||
expect: nil,
|
expect: nil,
|
||||||
err: fmt.Errorf("Invalid triple at index %d. %v", 0, &quad.Quad{"foo", "bar", "", ""}),
|
err: fmt.Errorf("Invalid triple at index %d. %v", 0, quad.Quad{"foo", "bar", "", ""}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import (
|
||||||
"github.com/google/cayley/quad/nquads"
|
"github.com/google/cayley/quad/nquads"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseJsonToTripleList(jsonBody []byte) ([]*quad.Quad, error) {
|
func ParseJsonToTripleList(jsonBody []byte) ([]quad.Quad, error) {
|
||||||
var tripleList []*quad.Quad
|
var tripleList []quad.Quad
|
||||||
err := json.Unmarshal(jsonBody, &tripleList)
|
err := json.Unmarshal(jsonBody, &tripleList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -83,7 +83,7 @@ func (api *Api) ServeV1WriteNQuad(w http.ResponseWriter, r *http.Request, params
|
||||||
var (
|
var (
|
||||||
n int
|
n int
|
||||||
|
|
||||||
block = make([]*quad.Quad, 0, blockSize)
|
block = make([]quad.Quad, 0, blockSize)
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
t, err := dec.Unmarshal()
|
t, err := dec.Unmarshal()
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ import (
|
||||||
// Parse returns a valid quad.Quad or a non-nil error. Parse does
|
// Parse returns a valid quad.Quad or a non-nil error. Parse does
|
||||||
// handle comments except where the comment placement does not prevent
|
// handle comments except where the comment placement does not prevent
|
||||||
// a complete valid quad.Quad from being defined.
|
// a complete valid quad.Quad from being defined.
|
||||||
func Parse(str string) (*quad.Quad, error) {
|
func Parse(str string) (quad.Quad, error) {
|
||||||
q, err := parse([]rune(str))
|
q, err := parse([]rune(str))
|
||||||
return &q, err
|
return q, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decoder implements simplified N-Quad document parsing.
|
// Decoder implements simplified N-Quad document parsing.
|
||||||
|
|
@ -52,14 +52,14 @@ func NewDecoder(r io.Reader) *Decoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal returns the next valid N-Quad as a quad.Quad, or an error.
|
// Unmarshal returns the next valid N-Quad as a quad.Quad, or an error.
|
||||||
func (dec *Decoder) Unmarshal() (*quad.Quad, error) {
|
func (dec *Decoder) Unmarshal() (quad.Quad, error) {
|
||||||
dec.line = dec.line[:0]
|
dec.line = dec.line[:0]
|
||||||
var line []byte
|
var line []byte
|
||||||
for {
|
for {
|
||||||
for {
|
for {
|
||||||
l, pre, err := dec.r.ReadLine()
|
l, pre, err := dec.r.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return quad.Quad{}, err
|
||||||
}
|
}
|
||||||
dec.line = append(dec.line, l...)
|
dec.line = append(dec.line, l...)
|
||||||
if !pre {
|
if !pre {
|
||||||
|
|
@ -73,9 +73,9 @@ func (dec *Decoder) Unmarshal() (*quad.Quad, error) {
|
||||||
}
|
}
|
||||||
triple, err := Parse(string(line))
|
triple, err := Parse(string(line))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse %q: %v", dec.line, err)
|
return quad.Quad{}, fmt.Errorf("failed to parse %q: %v", dec.line, err)
|
||||||
}
|
}
|
||||||
if triple == nil {
|
if !triple.IsValid() {
|
||||||
return dec.Unmarshal()
|
return dec.Unmarshal()
|
||||||
}
|
}
|
||||||
return triple, nil
|
return triple, nil
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import (
|
||||||
var testNTriples = []struct {
|
var testNTriples = []struct {
|
||||||
message string
|
message string
|
||||||
input string
|
input string
|
||||||
expect *quad.Quad
|
expect quad.Quad
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
// Tests from original nquads.
|
// Tests from original nquads.
|
||||||
|
|
@ -40,7 +40,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse simple triples",
|
message: "parse simple triples",
|
||||||
input: "this is valid .",
|
input: "this is valid .",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "this",
|
Subject: "this",
|
||||||
Predicate: "is",
|
Predicate: "is",
|
||||||
Object: "valid",
|
Object: "valid",
|
||||||
|
|
@ -50,7 +50,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quoted triples",
|
message: "parse quoted triples",
|
||||||
input: `this is "valid too" .`,
|
input: `this is "valid too" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "this",
|
Subject: "this",
|
||||||
Predicate: "is",
|
Predicate: "is",
|
||||||
Object: "valid too",
|
Object: "valid too",
|
||||||
|
|
@ -60,7 +60,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse escaped quoted triples",
|
message: "parse escaped quoted triples",
|
||||||
input: `he said "\"That's all folks\"" .`,
|
input: `he said "\"That's all folks\"" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "he",
|
Subject: "he",
|
||||||
Predicate: "said",
|
Predicate: "said",
|
||||||
Object: `"That's all folks"`,
|
Object: `"That's all folks"`,
|
||||||
|
|
@ -70,7 +70,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse an example real triple",
|
message: "parse an example real triple",
|
||||||
input: `":/guid/9202a8c04000641f80000000010c843c" "name" "George Morris" .`,
|
input: `":/guid/9202a8c04000641f80000000010c843c" "name" "George Morris" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: ":/guid/9202a8c04000641f80000000010c843c",
|
Subject: ":/guid/9202a8c04000641f80000000010c843c",
|
||||||
Predicate: "name",
|
Predicate: "name",
|
||||||
Object: "George Morris",
|
Object: "George Morris",
|
||||||
|
|
@ -80,7 +80,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse a pathologically spaced triple",
|
message: "parse a pathologically spaced triple",
|
||||||
input: "foo is \"\\tA big tough\\r\\nDeal\\\\\" .",
|
input: "foo is \"\\tA big tough\\r\\nDeal\\\\\" .",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "foo",
|
Subject: "foo",
|
||||||
Predicate: "is",
|
Predicate: "is",
|
||||||
Object: "\tA big tough\r\nDeal\\",
|
Object: "\tA big tough\r\nDeal\\",
|
||||||
|
|
@ -92,7 +92,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse a simple quad",
|
message: "parse a simple quad",
|
||||||
input: "this is valid quad .",
|
input: "this is valid quad .",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "this",
|
Subject: "this",
|
||||||
Predicate: "is",
|
Predicate: "is",
|
||||||
Object: "valid",
|
Object: "valid",
|
||||||
|
|
@ -102,7 +102,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse a quoted quad",
|
message: "parse a quoted quad",
|
||||||
input: `this is valid "quad thing" .`,
|
input: `this is valid "quad thing" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "this",
|
Subject: "this",
|
||||||
Predicate: "is",
|
Predicate: "is",
|
||||||
Object: "valid",
|
Object: "valid",
|
||||||
|
|
@ -112,7 +112,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse crazy escaped quads",
|
message: "parse crazy escaped quads",
|
||||||
input: `"\"this" "\"is" "\"valid" "\"quad thing".`,
|
input: `"\"this" "\"is" "\"valid" "\"quad thing".`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: `"this`,
|
Subject: `"this`,
|
||||||
Predicate: `"is`,
|
Predicate: `"is`,
|
||||||
Object: `"valid`,
|
Object: `"valid`,
|
||||||
|
|
@ -124,7 +124,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "handle simple case with comments",
|
message: "handle simple case with comments",
|
||||||
input: "<http://example/s> <http://example/p> <http://example/o> . # comment",
|
input: "<http://example/s> <http://example/p> <http://example/o> . # comment",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example/s",
|
Subject: "http://example/s",
|
||||||
Predicate: "http://example/p",
|
Predicate: "http://example/p",
|
||||||
Object: "http://example/o",
|
Object: "http://example/o",
|
||||||
|
|
@ -134,7 +134,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "handle simple case with comments",
|
message: "handle simple case with comments",
|
||||||
input: "<http://example/s> <http://example/p> _:o . # comment",
|
input: "<http://example/s> <http://example/p> _:o . # comment",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example/s",
|
Subject: "http://example/s",
|
||||||
Predicate: "http://example/p",
|
Predicate: "http://example/p",
|
||||||
Object: "_:o",
|
Object: "_:o",
|
||||||
|
|
@ -144,7 +144,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "handle simple case with comments",
|
message: "handle simple case with comments",
|
||||||
input: "<http://example/s> <http://example/p> \"o\" . # comment",
|
input: "<http://example/s> <http://example/p> \"o\" . # comment",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example/s",
|
Subject: "http://example/s",
|
||||||
Predicate: "http://example/p",
|
Predicate: "http://example/p",
|
||||||
Object: "o",
|
Object: "o",
|
||||||
|
|
@ -154,7 +154,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "handle simple case with comments",
|
message: "handle simple case with comments",
|
||||||
input: "<http://example/s> <http://example/p> \"o\"^^<http://example/dt> . # comment",
|
input: "<http://example/s> <http://example/p> \"o\"^^<http://example/dt> . # comment",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example/s",
|
Subject: "http://example/s",
|
||||||
Predicate: "http://example/p",
|
Predicate: "http://example/p",
|
||||||
Object: `"o"^^<http://example/dt>`,
|
Object: `"o"^^<http://example/dt>`,
|
||||||
|
|
@ -164,7 +164,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "handle simple case with comments",
|
message: "handle simple case with comments",
|
||||||
input: "<http://example/s> <http://example/p> \"o\"@en . # comment",
|
input: "<http://example/s> <http://example/p> \"o\"@en . # comment",
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example/s",
|
Subject: "http://example/s",
|
||||||
Predicate: "http://example/p",
|
Predicate: "http://example/p",
|
||||||
Object: `"o"@en`,
|
Object: `"o"@en`,
|
||||||
|
|
@ -177,7 +177,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `_:100000 </film/performance/actor> </en/larry_fine_1902> . # example from 30movies`,
|
input: `_:100000 </film/performance/actor> </en/larry_fine_1902> . # example from 30movies`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:100000",
|
Subject: "_:100000",
|
||||||
Predicate: "/film/performance/actor",
|
Predicate: "/film/performance/actor",
|
||||||
Object: "/en/larry_fine_1902",
|
Object: "/en/larry_fine_1902",
|
||||||
|
|
@ -189,7 +189,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `_:10011 </film/performance/character> "Tomás de Torquemada" . # example from 30movies with unicode`,
|
input: `_:10011 </film/performance/character> "Tomás de Torquemada" . # example from 30movies with unicode`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:10011",
|
Subject: "_:10011",
|
||||||
Predicate: "/film/performance/character",
|
Predicate: "/film/performance/character",
|
||||||
Object: "Tomás de Torquemada",
|
Object: "Tomás de Torquemada",
|
||||||
|
|
@ -202,7 +202,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
|
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://one.example/subject1",
|
Subject: "http://one.example/subject1",
|
||||||
Predicate: "http://one.example/predicate1",
|
Predicate: "http://one.example/predicate1",
|
||||||
Object: "http://one.example/object1",
|
Object: "http://one.example/object1",
|
||||||
|
|
@ -213,7 +213,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank subject node, literal object and no comment (1)",
|
message: "parse triple with blank subject node, literal object and no comment (1)",
|
||||||
input: `_:subject1 <http://an.example/predicate1> "object1" .`,
|
input: `_:subject1 <http://an.example/predicate1> "object1" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject1",
|
Subject: "_:subject1",
|
||||||
Predicate: "http://an.example/predicate1",
|
Predicate: "http://an.example/predicate1",
|
||||||
Object: "object1",
|
Object: "object1",
|
||||||
|
|
@ -224,7 +224,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank subject node, literal object and no comment (2)",
|
message: "parse triple with blank subject node, literal object and no comment (2)",
|
||||||
input: `_:subject2 <http://an.example/predicate2> "object2" .`,
|
input: `_:subject2 <http://an.example/predicate2> "object2" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject2",
|
Subject: "_:subject2",
|
||||||
Predicate: "http://an.example/predicate2",
|
Predicate: "http://an.example/predicate2",
|
||||||
Object: "object2",
|
Object: "object2",
|
||||||
|
|
@ -237,7 +237,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with three IRIREFs",
|
message: "parse triple with three IRIREFs",
|
||||||
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .`,
|
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/#spiderman",
|
Subject: "http://example.org/#spiderman",
|
||||||
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
|
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
|
||||||
Object: "http://example.org/#green-goblin",
|
Object: "http://example.org/#green-goblin",
|
||||||
|
|
@ -250,7 +250,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank node labelled subject and object and IRIREF predicate (1)",
|
message: "parse triple with blank node labelled subject and object and IRIREF predicate (1)",
|
||||||
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .`,
|
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:alice",
|
Subject: "_:alice",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "_:bob",
|
Object: "_:bob",
|
||||||
|
|
@ -261,7 +261,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank node labelled subject and object and IRIREF predicate (2)",
|
message: "parse triple with blank node labelled subject and object and IRIREF predicate (2)",
|
||||||
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice .`,
|
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:bob",
|
Subject: "_:bob",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "_:alice",
|
Object: "_:alice",
|
||||||
|
|
@ -274,7 +274,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with commment",
|
message: "parse quad with commment",
|
||||||
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3> . # comments here`,
|
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3> . # comments here`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://one.example/subject1",
|
Subject: "http://one.example/subject1",
|
||||||
Predicate: "http://one.example/predicate1",
|
Predicate: "http://one.example/predicate1",
|
||||||
Object: "http://one.example/object1",
|
Object: "http://one.example/object1",
|
||||||
|
|
@ -285,7 +285,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (1)",
|
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (1)",
|
||||||
input: `_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .`,
|
input: `_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject1",
|
Subject: "_:subject1",
|
||||||
Predicate: "http://an.example/predicate1",
|
Predicate: "http://an.example/predicate1",
|
||||||
Object: "object1",
|
Object: "object1",
|
||||||
|
|
@ -296,7 +296,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (2)",
|
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (2)",
|
||||||
input: `_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .`,
|
input: `_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject2",
|
Subject: "_:subject2",
|
||||||
Predicate: "http://an.example/predicate2",
|
Predicate: "http://an.example/predicate2",
|
||||||
Object: "object2",
|
Object: "object2",
|
||||||
|
|
@ -309,7 +309,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with all IRIREF parts",
|
message: "parse quad with all IRIREF parts",
|
||||||
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .`,
|
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/#spiderman",
|
Subject: "http://example.org/#spiderman",
|
||||||
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
|
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
|
||||||
Object: "http://example.org/#green-goblin",
|
Object: "http://example.org/#green-goblin",
|
||||||
|
|
@ -322,7 +322,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (1)",
|
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (1)",
|
||||||
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob <http://example.org/graphs/john> .`,
|
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob <http://example.org/graphs/john> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:alice",
|
Subject: "_:alice",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "_:bob",
|
Object: "_:bob",
|
||||||
|
|
@ -333,7 +333,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (2)",
|
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (2)",
|
||||||
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice <http://example.org/graphs/james> .`,
|
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice <http://example.org/graphs/james> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:bob",
|
Subject: "_:bob",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "_:alice",
|
Object: "_:alice",
|
||||||
|
|
@ -346,7 +346,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts",
|
message: "parse triple with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
||||||
Object: "http://xmlns.com/foaf/0.1/Person",
|
Object: "http://xmlns.com/foaf/0.1/Person",
|
||||||
|
|
@ -357,7 +357,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts",
|
message: "parse triple with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "http://example.org/alice#me",
|
Object: "http://example.org/alice#me",
|
||||||
|
|
@ -368,7 +368,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with IRIREF schema on literal object",
|
message: "parse triple with IRIREF schema on literal object",
|
||||||
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .`,
|
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://schema.org/birthDate",
|
Predicate: "http://schema.org/birthDate",
|
||||||
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
||||||
|
|
@ -379,7 +379,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in triple",
|
message: "parse commented IRIREF in triple",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
|
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
|
||||||
Object: "http://www.wikidata.org/entity/Q12418",
|
Object: "http://www.wikidata.org/entity/Q12418",
|
||||||
|
|
@ -390,7 +390,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with literal subject",
|
message: "parse triple with literal subject",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://www.wikidata.org/entity/Q12418",
|
Subject: "http://www.wikidata.org/entity/Q12418",
|
||||||
Predicate: "http://purl.org/dc/terms/title",
|
Predicate: "http://purl.org/dc/terms/title",
|
||||||
Object: "Mona Lisa",
|
Object: "Mona Lisa",
|
||||||
|
|
@ -401,7 +401,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts (1)",
|
message: "parse triple with all IRIREF parts (1)",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://www.wikidata.org/entity/Q12418",
|
Subject: "http://www.wikidata.org/entity/Q12418",
|
||||||
Predicate: "http://purl.org/dc/terms/creator",
|
Predicate: "http://purl.org/dc/terms/creator",
|
||||||
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
|
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
|
||||||
|
|
@ -412,7 +412,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts (2)",
|
message: "parse triple with all IRIREF parts (2)",
|
||||||
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .`,
|
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
|
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
|
||||||
Predicate: "http://purl.org/dc/terms/subject",
|
Predicate: "http://purl.org/dc/terms/subject",
|
||||||
Object: "http://www.wikidata.org/entity/Q12418",
|
Object: "http://www.wikidata.org/entity/Q12418",
|
||||||
|
|
@ -425,7 +425,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in quad (1)",
|
message: "parse commented IRIREF in quad (1)",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
||||||
Object: "http://xmlns.com/foaf/0.1/Person",
|
Object: "http://xmlns.com/foaf/0.1/Person",
|
||||||
|
|
@ -436,7 +436,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with all IRIREF parts",
|
message: "parse quad with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
Predicate: "http://xmlns.com/foaf/0.1/knows",
|
||||||
Object: "http://example.org/alice#me",
|
Object: "http://example.org/alice#me",
|
||||||
|
|
@ -447,7 +447,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with IRIREF schema on literal object",
|
message: "parse quad with IRIREF schema on literal object",
|
||||||
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://schema.org/birthDate",
|
Predicate: "http://schema.org/birthDate",
|
||||||
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
||||||
|
|
@ -458,7 +458,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in quad (2)",
|
message: "parse commented IRIREF in quad (2)",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
|
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
|
||||||
Object: "http://www.wikidata.org/entity/Q12418",
|
Object: "http://www.wikidata.org/entity/Q12418",
|
||||||
|
|
@ -469,7 +469,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse literal object and colon qualified label in quad",
|
message: "parse literal object and colon qualified label in quad",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://www.wikidata.org/entity/Q12418",
|
Subject: "http://www.wikidata.org/entity/Q12418",
|
||||||
Predicate: "http://purl.org/dc/terms/title",
|
Predicate: "http://purl.org/dc/terms/title",
|
||||||
Object: "Mona Lisa",
|
Object: "Mona Lisa",
|
||||||
|
|
@ -480,7 +480,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts with colon qualified label in quad (1)",
|
message: "parse all IRIREF parts with colon qualified label in quad (1)",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://www.wikidata.org/entity/Q12418",
|
Subject: "http://www.wikidata.org/entity/Q12418",
|
||||||
Predicate: "http://purl.org/dc/terms/creator",
|
Predicate: "http://purl.org/dc/terms/creator",
|
||||||
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
|
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
|
||||||
|
|
@ -491,7 +491,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts with colon qualified label in quad (2)",
|
message: "parse all IRIREF parts with colon qualified label in quad (2)",
|
||||||
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
|
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
|
||||||
Predicate: "http://purl.org/dc/terms/subject",
|
Predicate: "http://purl.org/dc/terms/subject",
|
||||||
Object: "http://www.wikidata.org/entity/Q12418",
|
Object: "http://www.wikidata.org/entity/Q12418",
|
||||||
|
|
@ -502,7 +502,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts (quad section - 1)",
|
message: "parse all IRIREF parts (quad section - 1)",
|
||||||
input: `<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .`,
|
input: `<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob",
|
Subject: "http://example.org/bob",
|
||||||
Predicate: "http://purl.org/dc/terms/publisher",
|
Predicate: "http://purl.org/dc/terms/publisher",
|
||||||
Object: "http://example.org",
|
Object: "http://example.org",
|
||||||
|
|
@ -513,7 +513,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts (quad section - 2)",
|
message: "parse all IRIREF parts (quad section - 2)",
|
||||||
input: `<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .`,
|
input: `<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob",
|
Subject: "http://example.org/bob",
|
||||||
Predicate: "http://purl.org/dc/terms/rights",
|
Predicate: "http://purl.org/dc/terms/rights",
|
||||||
Object: "http://creativecommons.org/licenses/by/3.0/",
|
Object: "http://creativecommons.org/licenses/by/3.0/",
|
||||||
|
|
@ -526,31 +526,31 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse empty",
|
message: "parse empty",
|
||||||
input: ``,
|
input: ``,
|
||||||
expect: &quad.Quad{},
|
expect: quad.Quad{},
|
||||||
err: quad.ErrIncomplete,
|
err: quad.ErrIncomplete,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse commented",
|
message: "parse commented",
|
||||||
input: `# is a comment`,
|
input: `# is a comment`,
|
||||||
expect: &quad.Quad{},
|
expect: quad.Quad{},
|
||||||
err: fmt.Errorf("%v: unexpected rune '#' at 0", quad.ErrInvalid),
|
err: fmt.Errorf("%v: unexpected rune '#' at 0", quad.ErrInvalid),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse commented internal (1)",
|
message: "parse commented internal (1)",
|
||||||
input: `is # a comment`,
|
input: `is # a comment`,
|
||||||
expect: &quad.Quad{Subject: "is"},
|
expect: quad.Quad{Subject: "is"},
|
||||||
err: fmt.Errorf("%v: unexpected rune '#' at 3", quad.ErrInvalid),
|
err: fmt.Errorf("%v: unexpected rune '#' at 3", quad.ErrInvalid),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse commented internal (2)",
|
message: "parse commented internal (2)",
|
||||||
input: `is a # comment`,
|
input: `is a # comment`,
|
||||||
expect: &quad.Quad{Subject: "is", Predicate: "a"},
|
expect: quad.Quad{Subject: "is", Predicate: "a"},
|
||||||
err: fmt.Errorf("%v: unexpected rune '#' at 5", quad.ErrInvalid),
|
err: fmt.Errorf("%v: unexpected rune '#' at 5", quad.ErrInvalid),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse incomplete quad (1)",
|
message: "parse incomplete quad (1)",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
||||||
Object: "",
|
Object: "",
|
||||||
|
|
@ -561,7 +561,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse incomplete quad (2)",
|
message: "parse incomplete quad (2)",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "http://example.org/bob#me",
|
Subject: "http://example.org/bob#me",
|
||||||
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
|
||||||
Object: "",
|
Object: "",
|
||||||
|
|
@ -773,7 +773,7 @@ func TestUnescape(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var result *quad.Quad
|
var result quad.Quad
|
||||||
|
|
||||||
func BenchmarkParser(b *testing.B) {
|
func BenchmarkParser(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ import (
|
||||||
// Parse returns a valid quad.Quad or a non-nil error. Parse does
|
// Parse returns a valid quad.Quad or a non-nil error. Parse does
|
||||||
// handle comments except where the comment placement does not prevent
|
// handle comments except where the comment placement does not prevent
|
||||||
// a complete valid quad.Quad from being defined.
|
// a complete valid quad.Quad from being defined.
|
||||||
func Parse(str string) (*quad.Quad, error) {
|
func Parse(str string) (quad.Quad, error) {
|
||||||
q, err := parse([]rune(str))
|
q, err := parse([]rune(str))
|
||||||
return &q, err
|
return q, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decoder implements N-Quad document parsing according to the RDF
|
// Decoder implements N-Quad document parsing according to the RDF
|
||||||
|
|
@ -52,14 +52,14 @@ func NewDecoder(r io.Reader) *Decoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal returns the next valid N-Quad as a quad.Quad, or an error.
|
// Unmarshal returns the next valid N-Quad as a quad.Quad, or an error.
|
||||||
func (dec *Decoder) Unmarshal() (*quad.Quad, error) {
|
func (dec *Decoder) Unmarshal() (quad.Quad, error) {
|
||||||
dec.line = dec.line[:0]
|
dec.line = dec.line[:0]
|
||||||
var line []byte
|
var line []byte
|
||||||
for {
|
for {
|
||||||
for {
|
for {
|
||||||
l, pre, err := dec.r.ReadLine()
|
l, pre, err := dec.r.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return quad.Quad{}, err
|
||||||
}
|
}
|
||||||
dec.line = append(dec.line, l...)
|
dec.line = append(dec.line, l...)
|
||||||
if !pre {
|
if !pre {
|
||||||
|
|
@ -73,9 +73,9 @@ func (dec *Decoder) Unmarshal() (*quad.Quad, error) {
|
||||||
}
|
}
|
||||||
triple, err := Parse(string(line))
|
triple, err := Parse(string(line))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse %q: %v", dec.line, err)
|
return quad.Quad{}, fmt.Errorf("failed to parse %q: %v", dec.line, err)
|
||||||
}
|
}
|
||||||
if triple == nil {
|
if !triple.IsValid() {
|
||||||
return dec.Unmarshal()
|
return dec.Unmarshal()
|
||||||
}
|
}
|
||||||
return triple, nil
|
return triple, nil
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import (
|
||||||
var testNTriples = []struct {
|
var testNTriples = []struct {
|
||||||
message string
|
message string
|
||||||
input string
|
input string
|
||||||
expect *quad.Quad
|
expect quad.Quad
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
// Tests taken from http://www.w3.org/TR/n-quads/ and http://www.w3.org/TR/n-triples/.
|
// Tests taken from http://www.w3.org/TR/n-quads/ and http://www.w3.org/TR/n-triples/.
|
||||||
|
|
@ -40,7 +40,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `_:100000 </film/performance/actor> </en/larry_fine_1902> . # example from 30movies`,
|
input: `_:100000 </film/performance/actor> </en/larry_fine_1902> . # example from 30movies`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:100000",
|
Subject: "_:100000",
|
||||||
Predicate: "</film/performance/actor>",
|
Predicate: "</film/performance/actor>",
|
||||||
Object: "</en/larry_fine_1902>",
|
Object: "</en/larry_fine_1902>",
|
||||||
|
|
@ -52,7 +52,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `_:10011 </film/performance/character> "Tomás de Torquemada" . # example from 30movies with unicode`,
|
input: `_:10011 </film/performance/character> "Tomás de Torquemada" . # example from 30movies with unicode`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:10011",
|
Subject: "_:10011",
|
||||||
Predicate: "</film/performance/character>",
|
Predicate: "</film/performance/character>",
|
||||||
Object: `"Tomás de Torquemada"`,
|
Object: `"Tomás de Torquemada"`,
|
||||||
|
|
@ -65,7 +65,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with commment",
|
message: "parse triple with commment",
|
||||||
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
|
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://one.example/subject1>",
|
Subject: "<http://one.example/subject1>",
|
||||||
Predicate: "<http://one.example/predicate1>",
|
Predicate: "<http://one.example/predicate1>",
|
||||||
Object: "<http://one.example/object1>",
|
Object: "<http://one.example/object1>",
|
||||||
|
|
@ -76,7 +76,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank subject node, literal object and no comment (1)",
|
message: "parse triple with blank subject node, literal object and no comment (1)",
|
||||||
input: `_:subject1 <http://an.example/predicate1> "object1" .`,
|
input: `_:subject1 <http://an.example/predicate1> "object1" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject1",
|
Subject: "_:subject1",
|
||||||
Predicate: "<http://an.example/predicate1>",
|
Predicate: "<http://an.example/predicate1>",
|
||||||
Object: `"object1"`,
|
Object: `"object1"`,
|
||||||
|
|
@ -87,7 +87,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank subject node, literal object and no comment (2)",
|
message: "parse triple with blank subject node, literal object and no comment (2)",
|
||||||
input: `_:subject2 <http://an.example/predicate2> "object2" .`,
|
input: `_:subject2 <http://an.example/predicate2> "object2" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject2",
|
Subject: "_:subject2",
|
||||||
Predicate: "<http://an.example/predicate2>",
|
Predicate: "<http://an.example/predicate2>",
|
||||||
Object: `"object2"`,
|
Object: `"object2"`,
|
||||||
|
|
@ -100,7 +100,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with three IRIREFs",
|
message: "parse triple with three IRIREFs",
|
||||||
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .`,
|
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/#spiderman>",
|
Subject: "<http://example.org/#spiderman>",
|
||||||
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
|
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
|
||||||
Object: "<http://example.org/#green-goblin>",
|
Object: "<http://example.org/#green-goblin>",
|
||||||
|
|
@ -113,7 +113,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank node labelled subject and object and IRIREF predicate (1)",
|
message: "parse triple with blank node labelled subject and object and IRIREF predicate (1)",
|
||||||
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .`,
|
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:alice",
|
Subject: "_:alice",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "_:bob",
|
Object: "_:bob",
|
||||||
|
|
@ -124,7 +124,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with blank node labelled subject and object and IRIREF predicate (2)",
|
message: "parse triple with blank node labelled subject and object and IRIREF predicate (2)",
|
||||||
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice .`,
|
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:bob",
|
Subject: "_:bob",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "_:alice",
|
Object: "_:alice",
|
||||||
|
|
@ -137,7 +137,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with commment",
|
message: "parse quad with commment",
|
||||||
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3> . # comments here`,
|
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3> . # comments here`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://one.example/subject1>",
|
Subject: "<http://one.example/subject1>",
|
||||||
Predicate: "<http://one.example/predicate1>",
|
Predicate: "<http://one.example/predicate1>",
|
||||||
Object: "<http://one.example/object1>",
|
Object: "<http://one.example/object1>",
|
||||||
|
|
@ -148,7 +148,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (1)",
|
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (1)",
|
||||||
input: `_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .`,
|
input: `_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject1",
|
Subject: "_:subject1",
|
||||||
Predicate: "<http://an.example/predicate1>",
|
Predicate: "<http://an.example/predicate1>",
|
||||||
Object: `"object1"`,
|
Object: `"object1"`,
|
||||||
|
|
@ -159,7 +159,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (2)",
|
message: "parse quad with blank subject node, literal object, IRIREF predicate and label, and no comment (2)",
|
||||||
input: `_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .`,
|
input: `_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:subject2",
|
Subject: "_:subject2",
|
||||||
Predicate: "<http://an.example/predicate2>",
|
Predicate: "<http://an.example/predicate2>",
|
||||||
Object: `"object2"`,
|
Object: `"object2"`,
|
||||||
|
|
@ -172,7 +172,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with all IRIREF parts",
|
message: "parse quad with all IRIREF parts",
|
||||||
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .`,
|
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/#spiderman>",
|
Subject: "<http://example.org/#spiderman>",
|
||||||
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
|
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
|
||||||
Object: "<http://example.org/#green-goblin>",
|
Object: "<http://example.org/#green-goblin>",
|
||||||
|
|
@ -185,7 +185,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (1)",
|
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (1)",
|
||||||
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob <http://example.org/graphs/john> .`,
|
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob <http://example.org/graphs/john> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:alice",
|
Subject: "_:alice",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "_:bob",
|
Object: "_:bob",
|
||||||
|
|
@ -196,7 +196,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (2)",
|
message: "parse quad with blank node labelled subject and object and IRIREF predicate and label (2)",
|
||||||
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice <http://example.org/graphs/james> .`,
|
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice <http://example.org/graphs/james> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "_:bob",
|
Subject: "_:bob",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "_:alice",
|
Object: "_:alice",
|
||||||
|
|
@ -209,7 +209,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts",
|
message: "parse triple with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
||||||
Object: "<http://xmlns.com/foaf/0.1/Person>",
|
Object: "<http://xmlns.com/foaf/0.1/Person>",
|
||||||
|
|
@ -220,7 +220,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts",
|
message: "parse triple with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "<http://example.org/alice#me>",
|
Object: "<http://example.org/alice#me>",
|
||||||
|
|
@ -231,7 +231,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with IRIREF schema on literal object",
|
message: "parse triple with IRIREF schema on literal object",
|
||||||
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .`,
|
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://schema.org/birthDate>",
|
Predicate: "<http://schema.org/birthDate>",
|
||||||
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
||||||
|
|
@ -242,7 +242,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in triple",
|
message: "parse commented IRIREF in triple",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
|
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
|
||||||
Object: "<http://www.wikidata.org/entity/Q12418>",
|
Object: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
|
|
@ -253,7 +253,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with literal subject",
|
message: "parse triple with literal subject",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
Predicate: "<http://purl.org/dc/terms/title>",
|
Predicate: "<http://purl.org/dc/terms/title>",
|
||||||
Object: `"Mona Lisa"`,
|
Object: `"Mona Lisa"`,
|
||||||
|
|
@ -264,7 +264,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts (1)",
|
message: "parse triple with all IRIREF parts (1)",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
Predicate: "<http://purl.org/dc/terms/creator>",
|
Predicate: "<http://purl.org/dc/terms/creator>",
|
||||||
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
|
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
|
||||||
|
|
@ -275,7 +275,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse triple with all IRIREF parts (2)",
|
message: "parse triple with all IRIREF parts (2)",
|
||||||
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .`,
|
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
|
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
|
||||||
Predicate: "<http://purl.org/dc/terms/subject>",
|
Predicate: "<http://purl.org/dc/terms/subject>",
|
||||||
Object: "<http://www.wikidata.org/entity/Q12418>",
|
Object: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
|
|
@ -288,7 +288,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in quad (1)",
|
message: "parse commented IRIREF in quad (1)",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
||||||
Object: "<http://xmlns.com/foaf/0.1/Person>",
|
Object: "<http://xmlns.com/foaf/0.1/Person>",
|
||||||
|
|
@ -299,7 +299,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with all IRIREF parts",
|
message: "parse quad with all IRIREF parts",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
|
||||||
Object: "<http://example.org/alice#me>",
|
Object: "<http://example.org/alice#me>",
|
||||||
|
|
@ -310,7 +310,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse quad with IRIREF schema on literal object",
|
message: "parse quad with IRIREF schema on literal object",
|
||||||
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://schema.org/birthDate>",
|
Predicate: "<http://schema.org/birthDate>",
|
||||||
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
|
||||||
|
|
@ -321,7 +321,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse commented IRIREF in quad (2)",
|
message: "parse commented IRIREF in quad (2)",
|
||||||
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> <http://example.org/bob> .`,
|
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> <http://example.org/bob> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
|
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
|
||||||
Object: "<http://www.wikidata.org/entity/Q12418>",
|
Object: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
|
|
@ -332,7 +332,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse literal object and colon qualified label in quad",
|
message: "parse literal object and colon qualified label in quad",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
Predicate: "<http://purl.org/dc/terms/title>",
|
Predicate: "<http://purl.org/dc/terms/title>",
|
||||||
Object: `"Mona Lisa"`,
|
Object: `"Mona Lisa"`,
|
||||||
|
|
@ -343,7 +343,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts with colon qualified label in quad (1)",
|
message: "parse all IRIREF parts with colon qualified label in quad (1)",
|
||||||
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
Subject: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
Predicate: "<http://purl.org/dc/terms/creator>",
|
Predicate: "<http://purl.org/dc/terms/creator>",
|
||||||
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
|
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
|
||||||
|
|
@ -354,7 +354,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts with colon qualified label in quad (2)",
|
message: "parse all IRIREF parts with colon qualified label in quad (2)",
|
||||||
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
|
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
|
||||||
Predicate: "<http://purl.org/dc/terms/subject>",
|
Predicate: "<http://purl.org/dc/terms/subject>",
|
||||||
Object: "<http://www.wikidata.org/entity/Q12418>",
|
Object: "<http://www.wikidata.org/entity/Q12418>",
|
||||||
|
|
@ -365,7 +365,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts (quad section - 1)",
|
message: "parse all IRIREF parts (quad section - 1)",
|
||||||
input: `<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .`,
|
input: `<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob>",
|
Subject: "<http://example.org/bob>",
|
||||||
Predicate: "<http://purl.org/dc/terms/publisher>",
|
Predicate: "<http://purl.org/dc/terms/publisher>",
|
||||||
Object: "<http://example.org>",
|
Object: "<http://example.org>",
|
||||||
|
|
@ -376,7 +376,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse all IRIREF parts (quad section - 2)",
|
message: "parse all IRIREF parts (quad section - 2)",
|
||||||
input: `<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .`,
|
input: `<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob>",
|
Subject: "<http://example.org/bob>",
|
||||||
Predicate: "<http://purl.org/dc/terms/rights>",
|
Predicate: "<http://purl.org/dc/terms/rights>",
|
||||||
Object: "<http://creativecommons.org/licenses/by/3.0/>",
|
Object: "<http://creativecommons.org/licenses/by/3.0/>",
|
||||||
|
|
@ -389,19 +389,19 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse empty",
|
message: "parse empty",
|
||||||
input: ``,
|
input: ``,
|
||||||
expect: &quad.Quad{},
|
expect: quad.Quad{},
|
||||||
err: quad.ErrIncomplete,
|
err: quad.ErrIncomplete,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse commented",
|
message: "parse commented",
|
||||||
input: `# comment`,
|
input: `# comment`,
|
||||||
expect: &quad.Quad{},
|
expect: quad.Quad{},
|
||||||
err: fmt.Errorf("%v: unexpected rune '#' at 0", quad.ErrInvalid),
|
err: fmt.Errorf("%v: unexpected rune '#' at 0", quad.ErrInvalid),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "parse incomplete quad",
|
message: "parse incomplete quad",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
||||||
Object: "",
|
Object: "",
|
||||||
|
|
@ -412,7 +412,7 @@ var testNTriples = []struct {
|
||||||
{
|
{
|
||||||
message: "parse incomplete quad",
|
message: "parse incomplete quad",
|
||||||
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
|
||||||
expect: &quad.Quad{
|
expect: quad.Quad{
|
||||||
Subject: "<http://example.org/bob#me>",
|
Subject: "<http://example.org/bob#me>",
|
||||||
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
|
||||||
Object: "",
|
Object: "",
|
||||||
|
|
@ -580,7 +580,7 @@ func TestUnescape(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var result *quad.Quad
|
var result quad.Quad
|
||||||
|
|
||||||
func BenchmarkParser(b *testing.B) {
|
func BenchmarkParser(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
|
|
|
||||||
14
quad/quad.go
14
quad/quad.go
|
|
@ -104,7 +104,7 @@ func (d Direction) String() string {
|
||||||
// instead of the pointer. This needs benchmarking to make the decision.
|
// instead of the pointer. This needs benchmarking to make the decision.
|
||||||
|
|
||||||
// Per-field accessor for triples
|
// Per-field accessor for triples
|
||||||
func (q *Quad) Get(d Direction) string {
|
func (q Quad) Get(d Direction) string {
|
||||||
switch d {
|
switch d {
|
||||||
case Subject:
|
case Subject:
|
||||||
return q.Subject
|
return q.Subject
|
||||||
|
|
@ -119,16 +119,16 @@ func (q *Quad) Get(d Direction) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Quad) Equals(o *Quad) bool {
|
func (q Quad) Equals(o Quad) bool {
|
||||||
return *q == *o
|
return q == o
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pretty-prints a triple.
|
// Pretty-prints a triple.
|
||||||
func (q *Quad) String() string {
|
func (q Quad) String() string {
|
||||||
return fmt.Sprintf("%s -- %s -> %s", q.Subject, q.Predicate, q.Object)
|
return fmt.Sprintf("%s -- %s -> %s", q.Subject, q.Predicate, q.Object)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Quad) IsValid() bool {
|
func (q Quad) IsValid() bool {
|
||||||
return q.Subject != "" && q.Predicate != "" && q.Object != ""
|
return q.Subject != "" && q.Predicate != "" && q.Object != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ func (q *Quad) IsValid() bool {
|
||||||
// from nquads to here to provide UnmarshalText(text []byte) error.
|
// from nquads to here to provide UnmarshalText(text []byte) error.
|
||||||
|
|
||||||
// Prints a triple in N-Quad format.
|
// Prints a triple in N-Quad format.
|
||||||
func (q *Quad) NTriple() string {
|
func (q Quad) NTriple() string {
|
||||||
if q.Label == "" {
|
if q.Label == "" {
|
||||||
//TODO(barakmich): Proper escaping.
|
//TODO(barakmich): Proper escaping.
|
||||||
return fmt.Sprintf("%s %s %s .", q.Subject, q.Predicate, q.Object)
|
return fmt.Sprintf("%s %s %s .", q.Subject, q.Predicate, q.Object)
|
||||||
|
|
@ -147,5 +147,5 @@ func (q *Quad) NTriple() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Unmarshaler interface {
|
type Unmarshaler interface {
|
||||||
Unmarshal() (*Quad, error)
|
Unmarshal() (Quad, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import (
|
||||||
// \-->|#D#|------------->+---+
|
// \-->|#D#|------------->+---+
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
var simpleGraph = []*quad.Quad{
|
var simpleGraph = []quad.Quad{
|
||||||
{"A", "follows", "B", ""},
|
{"A", "follows", "B", ""},
|
||||||
{"C", "follows", "B", ""},
|
{"C", "follows", "B", ""},
|
||||||
{"C", "follows", "D", ""},
|
{"C", "follows", "D", ""},
|
||||||
|
|
@ -52,7 +52,7 @@ var simpleGraph = []*quad.Quad{
|
||||||
{"G", "status", "cool", "status_graph"},
|
{"G", "status", "cool", "status_graph"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestSession(data []*quad.Quad) *Session {
|
func makeTestSession(data []quad.Quad) *Session {
|
||||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||||
for _, t := range data {
|
for _, t := range data {
|
||||||
ts.AddTriple(t)
|
ts.AddTriple(t)
|
||||||
|
|
@ -246,7 +246,7 @@ var testQueries = []struct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func runQueryGetTag(g []*quad.Quad, query string, tag string) []string {
|
func runQueryGetTag(g []quad.Quad, query string, tag string) []string {
|
||||||
js := makeTestSession(g)
|
js := makeTestSession(g)
|
||||||
c := make(chan interface{}, 5)
|
c := make(chan interface{}, 5)
|
||||||
js.ExecInput(query, c, -1)
|
js.ExecInput(query, c, -1)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import (
|
||||||
// \-->|#D#|------------->+---+
|
// \-->|#D#|------------->+---+
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
var simpleGraph = []*quad.Quad{
|
var simpleGraph = []quad.Quad{
|
||||||
{"A", "follows", "B", ""},
|
{"A", "follows", "B", ""},
|
||||||
{"C", "follows", "B", ""},
|
{"C", "follows", "B", ""},
|
||||||
{"C", "follows", "D", ""},
|
{"C", "follows", "D", ""},
|
||||||
|
|
@ -51,7 +51,7 @@ var simpleGraph = []*quad.Quad{
|
||||||
{"G", "status", "cool", "status_graph"},
|
{"G", "status", "cool", "status_graph"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestSession(data []*quad.Quad) *Session {
|
func makeTestSession(data []quad.Quad) *Session {
|
||||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||||
for _, t := range data {
|
for _, t := range data {
|
||||||
ts.AddTriple(t)
|
ts.AddTriple(t)
|
||||||
|
|
@ -165,7 +165,7 @@ var testQueries = []struct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func runQuery(g []*quad.Quad, query string) interface{} {
|
func runQuery(g []quad.Quad, query string) interface{} {
|
||||||
s := makeTestSession(g)
|
s := makeTestSession(g)
|
||||||
c := make(chan interface{}, 5)
|
c := make(chan interface{}, 5)
|
||||||
go s.ExecInput(query, c, -1)
|
go s.ExecInput(query, c, -1)
|
||||||
|
|
|
||||||
|
|
@ -32,21 +32,21 @@ func TestBadParse(t *testing.T) {
|
||||||
|
|
||||||
var testQueries = []struct {
|
var testQueries = []struct {
|
||||||
message string
|
message string
|
||||||
add *quad.Quad
|
add quad.Quad
|
||||||
query string
|
query string
|
||||||
typ graph.Type
|
typ graph.Type
|
||||||
expect string
|
expect string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
message: "get a single triple linkage",
|
message: "get a single triple linkage",
|
||||||
add: &quad.Quad{"i", "can", "win", ""},
|
add: quad.Quad{"i", "can", "win", ""},
|
||||||
query: "($a (:can \"win\"))",
|
query: "($a (:can \"win\"))",
|
||||||
typ: graph.And,
|
typ: graph.And,
|
||||||
expect: "i",
|
expect: "i",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "get a single triple linkage",
|
message: "get a single triple linkage",
|
||||||
add: &quad.Quad{"i", "can", "win", ""},
|
add: quad.Quad{"i", "can", "win", ""},
|
||||||
query: "(\"i\" (:can $a))",
|
query: "(\"i\" (:can $a))",
|
||||||
typ: graph.And,
|
typ: graph.And,
|
||||||
expect: "i",
|
expect: "i",
|
||||||
|
|
@ -60,7 +60,7 @@ func TestMemstoreBackedSexp(t *testing.T) {
|
||||||
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
|
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
|
||||||
}
|
}
|
||||||
for _, test := range testQueries {
|
for _, test := range testQueries {
|
||||||
if test.add != nil {
|
if test.add.IsValid() {
|
||||||
ts.AddTriple(test.add)
|
ts.AddTriple(test.add)
|
||||||
}
|
}
|
||||||
it := BuildIteratorTreeForQuery(ts, test.query)
|
it := BuildIteratorTreeForQuery(ts, test.query)
|
||||||
|
|
@ -79,8 +79,8 @@ func TestMemstoreBackedSexp(t *testing.T) {
|
||||||
|
|
||||||
func TestTreeConstraintParse(t *testing.T) {
|
func TestTreeConstraintParse(t *testing.T) {
|
||||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||||
ts.AddTriple(&quad.Quad{"i", "like", "food", ""})
|
ts.AddTriple(quad.Quad{"i", "like", "food", ""})
|
||||||
ts.AddTriple(&quad.Quad{"food", "is", "good", ""})
|
ts.AddTriple(quad.Quad{"food", "is", "good", ""})
|
||||||
query := "(\"i\"\n" +
|
query := "(\"i\"\n" +
|
||||||
"(:like\n" +
|
"(:like\n" +
|
||||||
"($a (:is :good))))"
|
"($a (:is :good))))"
|
||||||
|
|
@ -99,8 +99,8 @@ func TestTreeConstraintParse(t *testing.T) {
|
||||||
|
|
||||||
func TestTreeConstraintTagParse(t *testing.T) {
|
func TestTreeConstraintTagParse(t *testing.T) {
|
||||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||||
ts.AddTriple(&quad.Quad{"i", "like", "food", ""})
|
ts.AddTriple(quad.Quad{"i", "like", "food", ""})
|
||||||
ts.AddTriple(&quad.Quad{"food", "is", "good", ""})
|
ts.AddTriple(quad.Quad{"food", "is", "good", ""})
|
||||||
query := "(\"i\"\n" +
|
query := "(\"i\"\n" +
|
||||||
"(:like\n" +
|
"(:like\n" +
|
||||||
"($a (:is :good))))"
|
"($a (:is :good))))"
|
||||||
|
|
@ -119,7 +119,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
||||||
|
|
||||||
func TestMultipleConstraintParse(t *testing.T) {
|
func TestMultipleConstraintParse(t *testing.T) {
|
||||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||||
for _, tv := range []*quad.Quad{
|
for _, tv := range []quad.Quad{
|
||||||
{"i", "like", "food", ""},
|
{"i", "like", "food", ""},
|
||||||
{"i", "like", "beer", ""},
|
{"i", "like", "beer", ""},
|
||||||
{"you", "like", "beer", ""},
|
{"you", "like", "beer", ""},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue