Create quads hierarchy
* Move nquads into quad. * Create cquads simplified parser in quad. * Move Triple (renamed Quad) to quad. Also made sure mongo actually implements BulkLoader.
This commit is contained in:
parent
01bc63810b
commit
401c58426f
51 changed files with 13400 additions and 5495 deletions
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/barakmich/glog"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
// A HasA consists of a reference back to the graph.TripleStore that it references,
|
||||
|
|
@ -49,13 +50,13 @@ type HasA struct {
|
|||
Base
|
||||
ts graph.TripleStore
|
||||
primaryIt graph.Iterator
|
||||
dir graph.Direction
|
||||
dir quad.Direction
|
||||
resultIt graph.Iterator
|
||||
}
|
||||
|
||||
// Construct a new HasA iterator, given the triple subiterator, and the triple
|
||||
// direction for which it stands.
|
||||
func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d graph.Direction) *HasA {
|
||||
func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d quad.Direction) *HasA {
|
||||
var hasa HasA
|
||||
BaseInit(&hasa.Base)
|
||||
hasa.ts = ts
|
||||
|
|
@ -83,7 +84,7 @@ func (it *HasA) Clone() graph.Iterator {
|
|||
}
|
||||
|
||||
// Direction accessor.
|
||||
func (it *HasA) Direction() graph.Direction { return it.dir }
|
||||
func (it *HasA) Direction() quad.Direction { return it.dir }
|
||||
|
||||
// Pass the Optimize() call along to the subiterator. If it becomes Null,
|
||||
// then the HasA becomes Null (there are no triples that have any directions).
|
||||
|
|
@ -146,7 +147,7 @@ func (it *HasA) GetCheckResult() bool {
|
|||
break
|
||||
}
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Triple is", it.ts.Triple(linkVal))
|
||||
glog.V(4).Infoln("Quad is", it.ts.Quad(linkVal))
|
||||
}
|
||||
if it.primaryIt.Check(linkVal) {
|
||||
it.Last = it.ts.TripleDirection(linkVal, it.dir)
|
||||
|
|
@ -184,7 +185,7 @@ func (it *HasA) Next() (graph.Value, bool) {
|
|||
if !ok {
|
||||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
name := it.ts.Triple(tID).Get(it.dir)
|
||||
name := it.ts.Quad(tID).Get(it.dir)
|
||||
val := it.ts.ValueOf(name)
|
||||
it.Last = val
|
||||
return graph.NextLogOut(it, val, true)
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
// A LinksTo has a reference back to the graph.TripleStore (to create the iterators
|
||||
|
|
@ -43,13 +44,13 @@ type LinksTo struct {
|
|||
Base
|
||||
ts graph.TripleStore
|
||||
primaryIt graph.Iterator
|
||||
dir graph.Direction
|
||||
dir quad.Direction
|
||||
nextIt graph.Iterator
|
||||
}
|
||||
|
||||
// Construct a new LinksTo iterator around a direction and a subiterator of
|
||||
// nodes.
|
||||
func NewLinksTo(ts graph.TripleStore, it graph.Iterator, d graph.Direction) *LinksTo {
|
||||
func NewLinksTo(ts graph.TripleStore, it graph.Iterator, d quad.Direction) *LinksTo {
|
||||
var lto LinksTo
|
||||
BaseInit(<o.Base)
|
||||
lto.ts = ts
|
||||
|
|
@ -74,7 +75,7 @@ func (it *LinksTo) Clone() graph.Iterator {
|
|||
}
|
||||
|
||||
// Return the direction under consideration.
|
||||
func (it *LinksTo) Direction() graph.Direction { return it.dir }
|
||||
func (it *LinksTo) Direction() quad.Direction { return it.dir }
|
||||
|
||||
// Tag these results, and our subiterator's results.
|
||||
func (it *LinksTo) TagResults(dst map[string]graph.Value) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ package iterator
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
func TestLinksTo(t *testing.T) {
|
||||
|
|
@ -32,12 +32,12 @@ func TestLinksTo(t *testing.T) {
|
|||
t.Fatalf("Failed to return correct value, got:%v expect:1", val)
|
||||
}
|
||||
fixed.Add(val)
|
||||
lto := NewLinksTo(ts, fixed, graph.Object)
|
||||
lto := NewLinksTo(ts, fixed, quad.Object)
|
||||
val, ok := lto.Next()
|
||||
if !ok {
|
||||
t.Error("At least one triple matches the fixed object")
|
||||
}
|
||||
if val != 2 {
|
||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.Triple(2), ts.Triple(val))
|
||||
t.Errorf("Quad index 2, such as %s, should match %s", ts.Quad(2), ts.Quad(val))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,18 @@ package iterator
|
|||
// A quickly mocked version of the TripleStore interface, for use in tests.
|
||||
// Can better used Mock.Called but will fill in as needed.
|
||||
|
||||
import "github.com/google/cayley/graph"
|
||||
import (
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
type store struct {
|
||||
data []string
|
||||
iter graph.Iterator
|
||||
}
|
||||
|
||||
func (ts *store) ValueOf(s string) graph.Value {
|
||||
for i, v := range ts.data {
|
||||
func (qs *store) ValueOf(s string) graph.Value {
|
||||
for i, v := range qs.data {
|
||||
if s == v {
|
||||
return i
|
||||
}
|
||||
|
|
@ -33,42 +36,42 @@ func (ts *store) ValueOf(s string) graph.Value {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ts *store) AddTriple(*graph.Triple) {}
|
||||
func (qs *store) AddTriple(*quad.Quad) {}
|
||||
|
||||
func (ts *store) AddTripleSet([]*graph.Triple) {}
|
||||
func (qs *store) AddTripleSet([]*quad.Quad) {}
|
||||
|
||||
func (ts *store) Triple(graph.Value) *graph.Triple { return &graph.Triple{} }
|
||||
func (qs *store) Quad(graph.Value) *quad.Quad { return &quad.Quad{} }
|
||||
|
||||
func (ts *store) TripleIterator(d graph.Direction, i graph.Value) graph.Iterator {
|
||||
return ts.iter
|
||||
func (qs *store) TripleIterator(d quad.Direction, i graph.Value) graph.Iterator {
|
||||
return qs.iter
|
||||
}
|
||||
|
||||
func (ts *store) NodesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (qs *store) NodesAllIterator() graph.Iterator { return &Null{} }
|
||||
|
||||
func (ts *store) TriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (qs *store) TriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
|
||||
func (ts *store) NameOf(v graph.Value) string {
|
||||
func (qs *store) NameOf(v graph.Value) string {
|
||||
i := v.(int)
|
||||
if i < 0 || i >= len(ts.data) {
|
||||
if i < 0 || i >= len(qs.data) {
|
||||
return ""
|
||||
}
|
||||
return ts.data[i]
|
||||
return qs.data[i]
|
||||
}
|
||||
|
||||
func (ts *store) Size() int64 { return 0 }
|
||||
func (qs *store) Size() int64 { return 0 }
|
||||
|
||||
func (ts *store) DebugPrint() {}
|
||||
func (qs *store) DebugPrint() {}
|
||||
|
||||
func (ts *store) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||
func (qs *store) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||
return &Null{}, false
|
||||
}
|
||||
|
||||
func (ts *store) FixedIterator() graph.FixedIterator {
|
||||
func (qs *store) FixedIterator() graph.FixedIterator {
|
||||
return NewFixedIteratorWithCompare(BasicEquality)
|
||||
}
|
||||
|
||||
func (ts *store) Close() {}
|
||||
func (qs *store) Close() {}
|
||||
|
||||
func (ts *store) TripleDirection(graph.Value, graph.Direction) graph.Value { return 0 }
|
||||
func (qs *store) TripleDirection(graph.Value, quad.Direction) graph.Value { return 0 }
|
||||
|
||||
func (ts *store) RemoveTriple(t *graph.Triple) {}
|
||||
func (qs *store) RemoveTriple(t *quad.Quad) {}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package iterator
|
|||
|
||||
import (
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
|
|
@ -39,7 +40,7 @@ type queryShape struct {
|
|||
ts graph.TripleStore
|
||||
nodeId int
|
||||
hasaIds []int
|
||||
hasaDirs []graph.Direction
|
||||
hasaDirs []quad.Direction
|
||||
}
|
||||
|
||||
func OutputQueryShapeForIterator(it graph.Iterator, ts graph.TripleStore, outputMap map[string]interface{}) {
|
||||
|
|
@ -62,11 +63,11 @@ func (qs *queryShape) AddLink(l *Link) {
|
|||
qs.links = append(qs.links, *l)
|
||||
}
|
||||
|
||||
func (qs *queryShape) LastHasa() (int, graph.Direction) {
|
||||
func (qs *queryShape) LastHasa() (int, quad.Direction) {
|
||||
return qs.hasaIds[len(qs.hasaIds)-1], qs.hasaDirs[len(qs.hasaDirs)-1]
|
||||
}
|
||||
|
||||
func (qs *queryShape) PushHasa(i int, d graph.Direction) {
|
||||
func (qs *queryShape) PushHasa(i int, d quad.Direction) {
|
||||
qs.hasaIds = append(qs.hasaIds, i)
|
||||
qs.hasaDirs = append(qs.hasaDirs, d)
|
||||
}
|
||||
|
|
@ -159,10 +160,10 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
|||
qs.nodeId++
|
||||
newNode := qs.MakeNode(lto.primaryIt)
|
||||
hasaID, hasaDir := qs.LastHasa()
|
||||
if (hasaDir == graph.Subject && lto.dir == graph.Object) ||
|
||||
(hasaDir == graph.Object && lto.dir == graph.Subject) {
|
||||
if (hasaDir == quad.Subject && lto.dir == quad.Object) ||
|
||||
(hasaDir == quad.Object && lto.dir == quad.Subject) {
|
||||
qs.AddNode(newNode)
|
||||
if hasaDir == graph.Subject {
|
||||
if hasaDir == quad.Subject {
|
||||
qs.AddLink(&Link{hasaID, newNode.Id, 0, n.Id})
|
||||
} else {
|
||||
qs.AddLink(&Link{newNode.Id, hasaID, 0, n.Id})
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
func hasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
||||
|
|
@ -27,13 +28,13 @@ func hasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
|||
obj := ts.FixedIterator()
|
||||
obj.Add(ts.ValueOf(target))
|
||||
obj.AddTag(tag)
|
||||
and.AddSubIterator(NewLinksTo(ts, obj, graph.Object))
|
||||
and.AddSubIterator(NewLinksTo(ts, obj, quad.Object))
|
||||
|
||||
pred := ts.FixedIterator()
|
||||
pred.Add(ts.ValueOf("status"))
|
||||
and.AddSubIterator(NewLinksTo(ts, pred, graph.Predicate))
|
||||
and.AddSubIterator(NewLinksTo(ts, pred, quad.Predicate))
|
||||
|
||||
return NewHasA(ts, and, graph.Subject)
|
||||
return NewHasA(ts, and, quad.Subject)
|
||||
}
|
||||
|
||||
func TestQueryShape(t *testing.T) {
|
||||
|
|
@ -104,11 +105,11 @@ func TestQueryShape(t *testing.T) {
|
|||
pred.Add(ts.ValueOf("name"))
|
||||
|
||||
and := NewAnd()
|
||||
and.AddSubIterator(NewLinksTo(ts, andInternal, graph.Subject))
|
||||
and.AddSubIterator(NewLinksTo(ts, pred, graph.Predicate))
|
||||
and.AddSubIterator(NewLinksTo(ts, andInternal, quad.Subject))
|
||||
and.AddSubIterator(NewLinksTo(ts, pred, quad.Predicate))
|
||||
|
||||
shape = make(map[string]interface{})
|
||||
OutputQueryShapeForIterator(NewHasA(ts, and, graph.Object), ts, shape)
|
||||
OutputQueryShapeForIterator(NewHasA(ts, and, quad.Object), ts, shape)
|
||||
|
||||
links = shape["links"].([]Link)
|
||||
if len(links) != 3 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue