Reduce TripleStore interface names
This commit is contained in:
parent
8576f66d20
commit
b89d4f392c
29 changed files with 156 additions and 156 deletions
|
|
@ -126,13 +126,13 @@ func (it *HasA) DebugString(indent int) string {
|
||||||
func (it *HasA) Check(val graph.TSVal) bool {
|
func (it *HasA) Check(val graph.TSVal) bool {
|
||||||
graph.CheckLogIn(it, val)
|
graph.CheckLogIn(it, val)
|
||||||
if glog.V(4) {
|
if glog.V(4) {
|
||||||
glog.V(4).Infoln("Id is", it.ts.GetNameFor(val))
|
glog.V(4).Infoln("Id is", it.ts.NameOf(val))
|
||||||
}
|
}
|
||||||
// TODO(barakmich): Optimize this
|
// TODO(barakmich): Optimize this
|
||||||
if it.resultIt != nil {
|
if it.resultIt != nil {
|
||||||
it.resultIt.Close()
|
it.resultIt.Close()
|
||||||
}
|
}
|
||||||
it.resultIt = it.ts.GetTripleIterator(it.dir, val)
|
it.resultIt = it.ts.TripleIterator(it.dir, val)
|
||||||
return graph.CheckLogOut(it, val, it.GetCheckResult())
|
return graph.CheckLogOut(it, val, it.GetCheckResult())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,10 +146,10 @@ func (it *HasA) GetCheckResult() bool {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if glog.V(4) {
|
if glog.V(4) {
|
||||||
glog.V(4).Infoln("Triple is", it.ts.GetTriple(linkVal))
|
glog.V(4).Infoln("Triple is", it.ts.Triple(linkVal))
|
||||||
}
|
}
|
||||||
if it.primaryIt.Check(linkVal) {
|
if it.primaryIt.Check(linkVal) {
|
||||||
it.Last = it.ts.GetTripleDirection(linkVal, it.dir)
|
it.Last = it.ts.TripleDirection(linkVal, it.dir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -184,8 +184,8 @@ func (it *HasA) Next() (graph.TSVal, bool) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return graph.NextLogOut(it, 0, false)
|
return graph.NextLogOut(it, 0, false)
|
||||||
}
|
}
|
||||||
name := it.ts.GetTriple(tID).Get(it.dir)
|
name := it.ts.Triple(tID).Get(it.dir)
|
||||||
val := it.ts.GetIdFor(name)
|
val := it.ts.ValueOf(name)
|
||||||
it.Last = val
|
it.Last = val
|
||||||
return graph.NextLogOut(it, val, true)
|
return graph.NextLogOut(it, val, true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (it *LinksTo) DebugString(indent int) string {
|
||||||
// for the LinksTo.
|
// for the LinksTo.
|
||||||
func (it *LinksTo) Check(val graph.TSVal) bool {
|
func (it *LinksTo) Check(val graph.TSVal) bool {
|
||||||
graph.CheckLogIn(it, val)
|
graph.CheckLogIn(it, val)
|
||||||
node := it.ts.GetTripleDirection(val, it.dir)
|
node := it.ts.TripleDirection(val, it.dir)
|
||||||
if it.primaryIt.Check(node) {
|
if it.primaryIt.Check(node) {
|
||||||
it.Last = val
|
it.Last = val
|
||||||
return graph.CheckLogOut(it, val, true)
|
return graph.CheckLogOut(it, val, true)
|
||||||
|
|
@ -146,7 +146,7 @@ func (it *LinksTo) Next() (graph.TSVal, bool) {
|
||||||
return graph.NextLogOut(it, 0, false)
|
return graph.NextLogOut(it, 0, false)
|
||||||
}
|
}
|
||||||
it.nextIt.Close()
|
it.nextIt.Close()
|
||||||
it.nextIt = it.ts.GetTripleIterator(it.dir, candidate)
|
it.nextIt = it.ts.TripleIterator(it.dir, candidate)
|
||||||
// Recurse -- return the first in the next set.
|
// Recurse -- return the first in the next set.
|
||||||
return it.Next()
|
return it.Next()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,16 @@ func TestLinksTo(t *testing.T) {
|
||||||
ts := new(TestTripleStore)
|
ts := new(TestTripleStore)
|
||||||
tsFixed := newFixed()
|
tsFixed := newFixed()
|
||||||
tsFixed.AddValue(2)
|
tsFixed.AddValue(2)
|
||||||
ts.On("GetIdFor", "cool").Return(1)
|
ts.On("ValueOf", "cool").Return(1)
|
||||||
ts.On("GetTripleIterator", graph.Object, 1).Return(tsFixed)
|
ts.On("TripleIterator", graph.Object, 1).Return(tsFixed)
|
||||||
fixed := newFixed()
|
fixed := newFixed()
|
||||||
fixed.AddValue(ts.GetIdFor("cool"))
|
fixed.AddValue(ts.ValueOf("cool"))
|
||||||
lto := NewLinksTo(ts, fixed, graph.Object)
|
lto := NewLinksTo(ts, fixed, graph.Object)
|
||||||
val, ok := lto.Next()
|
val, ok := lto.Next()
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("At least one triple matches the fixed object")
|
t.Error("At least one triple matches the fixed object")
|
||||||
}
|
}
|
||||||
if val != 2 {
|
if val != 2 {
|
||||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.GetTriple(2), ts.GetTriple(val))
|
t.Errorf("Triple index 2, such as %s, should match %s", ts.Triple(2), ts.Triple(val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,23 +27,23 @@ type TestTripleStore struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TestTripleStore) GetIdFor(s string) graph.TSVal {
|
func (ts *TestTripleStore) ValueOf(s string) graph.TSVal {
|
||||||
args := ts.Mock.Called(s)
|
args := ts.Mock.Called(s)
|
||||||
return args.Get(0)
|
return args.Get(0)
|
||||||
}
|
}
|
||||||
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
||||||
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
||||||
func (ts *TestTripleStore) GetTriple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
func (ts *TestTripleStore) Triple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
||||||
func (ts *TestTripleStore) GetTripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
||||||
args := ts.Mock.Called(d, i)
|
args := ts.Mock.Called(d, i)
|
||||||
return args.Get(0).(graph.Iterator)
|
return args.Get(0).(graph.Iterator)
|
||||||
}
|
}
|
||||||
func (ts *TestTripleStore) GetNodesAllIterator() graph.Iterator { return &Null{} }
|
func (ts *TestTripleStore) NodesAllIterator() graph.Iterator { return &Null{} }
|
||||||
func (ts *TestTripleStore) GetTriplesAllIterator() graph.Iterator { return &Null{} }
|
func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{} }
|
||||||
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
|
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
|
||||||
return &Null{}
|
return &Null{}
|
||||||
}
|
}
|
||||||
func (ts *TestTripleStore) GetNameFor(v graph.TSVal) string {
|
func (ts *TestTripleStore) NameOf(v graph.TSVal) string {
|
||||||
args := ts.Mock.Called(v)
|
args := ts.Mock.Called(v)
|
||||||
return args.Get(0).(string)
|
return args.Get(0).(string)
|
||||||
}
|
}
|
||||||
|
|
@ -56,5 +56,5 @@ func (ts *TestTripleStore) FixedIterator() graph.FixedIterator {
|
||||||
return NewFixedIteratorWithCompare(BasicEquality)
|
return NewFixedIteratorWithCompare(BasicEquality)
|
||||||
}
|
}
|
||||||
func (ts *TestTripleStore) Close() {}
|
func (ts *TestTripleStore) Close() {}
|
||||||
func (ts *TestTripleStore) GetTripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
func (ts *TestTripleStore) TripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
||||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
||||||
if !more {
|
if !more {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
n.Values = append(n.Values, qs.ts.GetNameFor(val))
|
n.Values = append(n.Values, qs.ts.NameOf(val))
|
||||||
}
|
}
|
||||||
case "hasa":
|
case "hasa":
|
||||||
hasa := it.(*HasA)
|
hasa := it.(*HasA)
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import (
|
||||||
func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
||||||
fixed_obj := ts.FixedIterator()
|
fixed_obj := ts.FixedIterator()
|
||||||
fixed_pred := ts.FixedIterator()
|
fixed_pred := ts.FixedIterator()
|
||||||
fixed_obj.AddValue(ts.GetIdFor(target))
|
fixed_obj.AddValue(ts.ValueOf(target))
|
||||||
fixed_pred.AddValue(ts.GetIdFor("status"))
|
fixed_pred.AddValue(ts.ValueOf("status"))
|
||||||
fixed_obj.AddTag(tag)
|
fixed_obj.AddTag(tag)
|
||||||
lto1 := NewLinksTo(ts, fixed_obj, graph.Object)
|
lto1 := NewLinksTo(ts, fixed_obj, graph.Object)
|
||||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||||
|
|
@ -40,14 +40,14 @@ func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
||||||
func TestQueryShape(t *testing.T) {
|
func TestQueryShape(t *testing.T) {
|
||||||
var queryShape map[string]interface{}
|
var queryShape map[string]interface{}
|
||||||
ts := new(TestTripleStore)
|
ts := new(TestTripleStore)
|
||||||
ts.On("GetIdFor", "cool").Return(1)
|
ts.On("ValueOf", "cool").Return(1)
|
||||||
ts.On("GetNameFor", 1).Return("cool")
|
ts.On("NameOf", 1).Return("cool")
|
||||||
ts.On("GetIdFor", "status").Return(2)
|
ts.On("ValueOf", "status").Return(2)
|
||||||
ts.On("GetNameFor", 2).Return("status")
|
ts.On("NameOf", 2).Return("status")
|
||||||
ts.On("GetIdFor", "fun").Return(3)
|
ts.On("ValueOf", "fun").Return(3)
|
||||||
ts.On("GetNameFor", 3).Return("fun")
|
ts.On("NameOf", 3).Return("fun")
|
||||||
ts.On("GetIdFor", "name").Return(4)
|
ts.On("ValueOf", "name").Return(4)
|
||||||
ts.On("GetNameFor", 4).Return("name")
|
ts.On("NameOf", 4).Return("name")
|
||||||
|
|
||||||
Convey("Given a single linkage iterator's shape", t, func() {
|
Convey("Given a single linkage iterator's shape", t, func() {
|
||||||
queryShape = make(map[string]interface{})
|
queryShape = make(map[string]interface{})
|
||||||
|
|
@ -92,7 +92,7 @@ func TestQueryShape(t *testing.T) {
|
||||||
andInternal.AddSubIterator(hasa1)
|
andInternal.AddSubIterator(hasa1)
|
||||||
andInternal.AddSubIterator(hasa2)
|
andInternal.AddSubIterator(hasa2)
|
||||||
fixed_pred := ts.FixedIterator()
|
fixed_pred := ts.FixedIterator()
|
||||||
fixed_pred.AddValue(ts.GetIdFor("name"))
|
fixed_pred.AddValue(ts.ValueOf("name"))
|
||||||
lto1 := NewLinksTo(ts, andInternal, graph.Subject)
|
lto1 := NewLinksTo(ts, andInternal, graph.Subject)
|
||||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||||
and := NewAnd()
|
and := NewAnd()
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.Tr
|
||||||
// and our operator, determine whether or not we meet the requirement.
|
// and our operator, determine whether or not we meet the requirement.
|
||||||
func (it *Comparison) doComparison(val graph.TSVal) bool {
|
func (it *Comparison) doComparison(val graph.TSVal) bool {
|
||||||
//TODO(barakmich): Implement string comparison.
|
//TODO(barakmich): Implement string comparison.
|
||||||
nodeStr := it.ts.GetNameFor(val)
|
nodeStr := it.ts.NameOf(val)
|
||||||
switch cVal := it.val.(type) {
|
switch cVal := it.val.(type) {
|
||||||
case int:
|
case int:
|
||||||
cInt := int64(cVal)
|
cInt := int64(cVal)
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ import (
|
||||||
func SetupMockTripleStore(nameMap map[string]int) *TestTripleStore {
|
func SetupMockTripleStore(nameMap map[string]int) *TestTripleStore {
|
||||||
ts := new(TestTripleStore)
|
ts := new(TestTripleStore)
|
||||||
for k, v := range nameMap {
|
for k, v := range nameMap {
|
||||||
ts.On("GetIdFor", k).Return(v)
|
ts.On("ValueOf", k).Return(v)
|
||||||
ts.On("GetNameFor", v).Return(k)
|
ts.On("NameOf", v).Return(k)
|
||||||
}
|
}
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ func checkIteratorContains(ts graph.TripleStore, it graph.Iterator, expected []s
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
actual = append(actual, ts.GetNameFor(val))
|
actual = append(actual, ts.NameOf(val))
|
||||||
}
|
}
|
||||||
actualSet := actual[:]
|
actualSet := actual[:]
|
||||||
for _, a := range expected {
|
for _, a := range expected {
|
||||||
|
|
|
||||||
|
|
@ -177,8 +177,8 @@ func (it *Iterator) Check(v graph.TSVal) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nameForDir := it.ts.GetTriple(v).Get(it.dir)
|
nameForDir := it.ts.Triple(v).Get(it.dir)
|
||||||
hashForDir := it.ts.GetIdFor(nameForDir).([]byte)
|
hashForDir := it.ts.ValueOf(nameForDir).([]byte)
|
||||||
if bytes.Equal(hashForDir, it.checkId) {
|
if bytes.Equal(hashForDir, it.checkId) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +192,7 @@ func (it *Iterator) Size() (int64, bool) {
|
||||||
|
|
||||||
func (it *Iterator) DebugString(indent int) string {
|
func (it *Iterator) DebugString(indent int) string {
|
||||||
size, _ := it.Size()
|
size, _ := it.Size()
|
||||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.UID(), it.Tags(), it.dir, size, it.ts.GetNameFor(it.checkId))
|
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.UID(), it.Tags(), it.dir, size, it.ts.NameOf(it.checkId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Type() string { return "leveldb" }
|
func (it *Iterator) Type() string { return "leveldb" }
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func extractTripleFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
output = append(output, ts.GetTriple(val).String())
|
output = append(output, ts.Triple(val).String())
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +62,7 @@ func extractValuesFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
output = append(output, ts.GetNameFor(val))
|
output = append(output, ts.NameOf(val))
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +113,7 @@ func TestLoadDatabase(t *testing.T) {
|
||||||
|
|
||||||
Convey("Can load a single triple", func() {
|
Convey("Can load a single triple", func() {
|
||||||
ts.AddTriple(&graph.Triple{"Something", "points_to", "Something Else", "context"})
|
ts.AddTriple(&graph.Triple{"Something", "points_to", "Something Else", "context"})
|
||||||
So(ts.GetNameFor(ts.GetIdFor("Something")), ShouldEqual, "Something")
|
So(ts.NameOf(ts.ValueOf("Something")), ShouldEqual, "Something")
|
||||||
So(ts.Size(), ShouldEqual, 1)
|
So(ts.Size(), ShouldEqual, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -121,12 +121,12 @@ func TestLoadDatabase(t *testing.T) {
|
||||||
|
|
||||||
ts.AddTripleSet(makeTripleSet())
|
ts.AddTripleSet(makeTripleSet())
|
||||||
So(ts.Size(), ShouldEqual, 11)
|
So(ts.Size(), ShouldEqual, 11)
|
||||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 5)
|
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 5)
|
||||||
|
|
||||||
Convey("Can delete triples", func() {
|
Convey("Can delete triples", func() {
|
||||||
ts.RemoveTriple(&graph.Triple{"A", "follows", "B", ""})
|
ts.RemoveTriple(&graph.Triple{"A", "follows", "B", ""})
|
||||||
So(ts.Size(), ShouldEqual, 10)
|
So(ts.Size(), ShouldEqual, 10)
|
||||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 4)
|
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ func TestIterator(t *testing.T) {
|
||||||
var it graph.Iterator
|
var it graph.Iterator
|
||||||
|
|
||||||
Convey("Can create an all iterator for nodes", func() {
|
Convey("Can create an all iterator for nodes", func() {
|
||||||
it = ts.GetNodesAllIterator()
|
it = ts.NodesAllIterator()
|
||||||
So(it, ShouldNotBeNil)
|
So(it, ShouldNotBeNil)
|
||||||
|
|
||||||
Convey("Has basics", func() {
|
Convey("Has basics", func() {
|
||||||
|
|
@ -192,9 +192,9 @@ func TestIterator(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Contains a couple nodes", func() {
|
Convey("Contains a couple nodes", func() {
|
||||||
So(it.Check(ts.GetIdFor("A")), ShouldBeTrue)
|
So(it.Check(ts.ValueOf("A")), ShouldBeTrue)
|
||||||
So(it.Check(ts.GetIdFor("cool")), ShouldBeTrue)
|
So(it.Check(ts.ValueOf("cool")), ShouldBeTrue)
|
||||||
//So(it.Check(ts.GetIdFor("baller")), ShouldBeFalse)
|
//So(it.Check(ts.ValueOf("baller")), ShouldBeFalse)
|
||||||
})
|
})
|
||||||
|
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
|
|
@ -203,7 +203,7 @@ func TestIterator(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can create an all iterator for edges", func() {
|
Convey("Can create an all iterator for edges", func() {
|
||||||
it := ts.GetTriplesAllIterator()
|
it := ts.TriplesAllIterator()
|
||||||
So(it, ShouldNotBeNil)
|
So(it, ShouldNotBeNil)
|
||||||
Convey("Has basics", func() {
|
Convey("Has basics", func() {
|
||||||
size, accurate := it.Size()
|
size, accurate := it.Size()
|
||||||
|
|
@ -217,7 +217,7 @@ func TestIterator(t *testing.T) {
|
||||||
|
|
||||||
Convey("Iterates an edge", func() {
|
Convey("Iterates an edge", func() {
|
||||||
edge_val, _ := it.Next()
|
edge_val, _ := it.Next()
|
||||||
triple := ts.GetTriple(edge_val)
|
triple := ts.Triple(edge_val)
|
||||||
set := makeTripleSet()
|
set := makeTripleSet()
|
||||||
var string_set []string
|
var string_set []string
|
||||||
for _, t := range set {
|
for _, t := range set {
|
||||||
|
|
@ -249,7 +249,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
var it graph.Iterator
|
var it graph.Iterator
|
||||||
|
|
||||||
Convey("Can create a subject iterator", func() {
|
Convey("Can create a subject iterator", func() {
|
||||||
it = ts.GetTripleIterator(graph.Subject, ts.GetIdFor("C"))
|
it = ts.TripleIterator(graph.Subject, ts.ValueOf("C"))
|
||||||
|
|
||||||
Convey("Containing the right things", func() {
|
Convey("Containing the right things", func() {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -264,7 +264,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
|
|
||||||
Convey("And checkable", func() {
|
Convey("And checkable", func() {
|
||||||
and := iterator.NewAnd()
|
and := iterator.NewAnd()
|
||||||
and.AddSubIterator(ts.GetTriplesAllIterator())
|
and.AddSubIterator(ts.TriplesAllIterator())
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -283,7 +283,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can create an object iterator", func() {
|
Convey("Can create an object iterator", func() {
|
||||||
it = ts.GetTripleIterator(graph.Object, ts.GetIdFor("F"))
|
it = ts.TripleIterator(graph.Object, ts.ValueOf("F"))
|
||||||
|
|
||||||
Convey("Containing the right things", func() {
|
Convey("Containing the right things", func() {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -298,7 +298,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
|
|
||||||
Convey("Mutually and-checkable", func() {
|
Convey("Mutually and-checkable", func() {
|
||||||
and := iterator.NewAnd()
|
and := iterator.NewAnd()
|
||||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -313,7 +313,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can create a predicate iterator", func() {
|
Convey("Can create a predicate iterator", func() {
|
||||||
it = ts.GetTripleIterator(graph.Predicate, ts.GetIdFor("status"))
|
it = ts.TripleIterator(graph.Predicate, ts.ValueOf("status"))
|
||||||
|
|
||||||
Convey("Containing the right things", func() {
|
Convey("Containing the right things", func() {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -330,7 +330,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can create a provenance iterator", func() {
|
Convey("Can create a provenance iterator", func() {
|
||||||
it = ts.GetTripleIterator(graph.Provenance, ts.GetIdFor("status_graph"))
|
it = ts.TripleIterator(graph.Provenance, ts.ValueOf("status_graph"))
|
||||||
|
|
||||||
Convey("Containing the right things", func() {
|
Convey("Containing the right things", func() {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -347,7 +347,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
Convey("Can be cross-checked", func() {
|
Convey("Can be cross-checked", func() {
|
||||||
and := iterator.NewAnd()
|
and := iterator.NewAnd()
|
||||||
// Order is important
|
// Order is important
|
||||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
@ -361,7 +361,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
and := iterator.NewAnd()
|
and := iterator.NewAnd()
|
||||||
// Order is important
|
// Order is important
|
||||||
and.AddSubIterator(it)
|
and.AddSubIterator(it)
|
||||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
(&graph.Triple{"B", "status", "cool", "status_graph"}).String(),
|
(&graph.Triple{"B", "status", "cool", "status_graph"}).String(),
|
||||||
|
|
@ -399,7 +399,7 @@ func TestOptimize(t *testing.T) {
|
||||||
|
|
||||||
Convey("With an linksto-fixed pair", func() {
|
Convey("With an linksto-fixed pair", func() {
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.AddValue(ts.GetIdFor("F"))
|
fixed.AddValue(ts.ValueOf("F"))
|
||||||
fixed.AddTag("internal")
|
fixed.AddTag("internal")
|
||||||
lto = iterator.NewLinksTo(ts, fixed, graph.Object)
|
lto = iterator.NewLinksTo(ts, fixed, graph.Object)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,11 @@ func CreateNewLevelDB(path string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
func NewTripleStore(path string, options graph.Options) *TripleStore {
|
||||||
var ts TripleStore
|
var ts TripleStore
|
||||||
ts.path = path
|
ts.path = path
|
||||||
cache_size := DefaultCacheSize
|
cache_size := DefaultCacheSize
|
||||||
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
if val, ok := options.IntKey("cache_size_mb"); ok {
|
||||||
cache_size = val
|
cache_size = val
|
||||||
}
|
}
|
||||||
ts.dbOpts = &opt.Options{
|
ts.dbOpts = &opt.Options{
|
||||||
|
|
@ -78,7 +78,7 @@ func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
||||||
ts.dbOpts.ErrorIfMissing = true
|
ts.dbOpts.ErrorIfMissing = true
|
||||||
|
|
||||||
write_buffer_mb := DefaultWriteBufferSize
|
write_buffer_mb := DefaultWriteBufferSize
|
||||||
if val, ok := options.GetIntKey("write_buffer_mb"); ok {
|
if val, ok := options.IntKey("write_buffer_mb"); ok {
|
||||||
write_buffer_mb = val
|
write_buffer_mb = val
|
||||||
}
|
}
|
||||||
ts.dbOpts.WriteBuffer = write_buffer_mb * opt.MiB
|
ts.dbOpts.WriteBuffer = write_buffer_mb * opt.MiB
|
||||||
|
|
@ -301,7 +301,7 @@ func (ts *TripleStore) Close() {
|
||||||
ts.open = false
|
ts.open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) Triple(k graph.TSVal) *graph.Triple {
|
||||||
var triple graph.Triple
|
var triple graph.Triple
|
||||||
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
|
|
@ -328,7 +328,7 @@ func (ts *TripleStore) convertStringToByteHash(s string) []byte {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
|
||||||
return ts.createValueKeyFor(s)
|
return ts.createValueKeyFor(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,7 +352,7 @@ func (ts *TripleStore) getValueData(value_key []byte) ValueData {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNameFor(k graph.TSVal) string {
|
func (ts *TripleStore) NameOf(k graph.TSVal) string {
|
||||||
if k == nil {
|
if k == nil {
|
||||||
glog.V(2).Infoln("k was nil")
|
glog.V(2).Infoln("k was nil")
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -401,7 +401,7 @@ func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||||
var prefix string
|
var prefix string
|
||||||
switch d {
|
switch d {
|
||||||
case graph.Subject:
|
case graph.Subject:
|
||||||
|
|
@ -418,21 +418,21 @@ func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) gra
|
||||||
return NewIterator(prefix, d, val, ts)
|
return NewIterator(prefix, d, val, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||||
return NewAllIterator("z", graph.Any, ts)
|
return NewAllIterator("z", graph.Any, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||||
return NewAllIterator("po", graph.Predicate, ts)
|
return NewAllIterator("po", graph.Predicate, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||||
v := val.([]uint8)
|
v := val.([]uint8)
|
||||||
offset := GetPositionFromPrefix(v[0:2], d, ts)
|
offset := GetPositionFromPrefix(v[0:2], d, ts)
|
||||||
if offset != -1 {
|
if offset != -1 {
|
||||||
return append([]byte("z"), v[offset:offset+ts.hasher.Size()]...)
|
return append([]byte("z"), v[offset:offset+ts.hasher.Size()]...)
|
||||||
} else {
|
} else {
|
||||||
return ts.GetTriple(val).Get(d)
|
return ts.Triple(val).Get(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("Sizes lie")
|
panic("Sizes lie")
|
||||||
}
|
}
|
||||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
newIt := ts.TripleIterator(it.Direction(), val)
|
||||||
newIt.CopyTagsFrom(it)
|
newIt.CopyTagsFrom(it)
|
||||||
for _, tag := range primary.Tags() {
|
for _, tag := range primary.Tags() {
|
||||||
newIt.AddFixedTag(tag, val)
|
newIt.AddFixedTag(tag, val)
|
||||||
|
|
|
||||||
|
|
@ -217,11 +217,11 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriple(index graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) Triple(index graph.TSVal) *graph.Triple {
|
||||||
return &ts.triples[index.(int64)]
|
return &ts.triples[index.(int64)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleIterator(d graph.Direction, value graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) TripleIterator(d graph.Direction, value graph.TSVal) graph.Iterator {
|
||||||
index, ok := ts.index.Get(d, value.(int64))
|
index, ok := ts.index.Get(d, value.(int64))
|
||||||
data := fmt.Sprintf("dir:%s val:%d", d, value.(int64))
|
data := fmt.Sprintf("dir:%s val:%d", d, value.(int64))
|
||||||
if ok {
|
if ok {
|
||||||
|
|
@ -243,15 +243,15 @@ func (ts *TripleStore) DebugPrint() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetIdFor(name string) graph.TSVal {
|
func (ts *TripleStore) ValueOf(name string) graph.TSVal {
|
||||||
return ts.idMap[name]
|
return ts.idMap[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNameFor(id graph.TSVal) string {
|
func (ts *TripleStore) NameOf(id graph.TSVal) string {
|
||||||
return ts.revIdMap[id.(int64)]
|
return ts.revIdMap[id.(int64)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||||
return iterator.NewInt64(0, ts.Size())
|
return iterator.NewInt64(0, ts.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,12 +259,12 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator {
|
||||||
return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality)
|
return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||||
name := ts.GetTriple(val).Get(d)
|
name := ts.Triple(val).Get(d)
|
||||||
return ts.GetIdFor(name)
|
return ts.ValueOf(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||||
return NewMemstoreAllIterator(ts)
|
return NewMemstoreAllIterator(ts)
|
||||||
}
|
}
|
||||||
func (ts *TripleStore) Close() {}
|
func (ts *TripleStore) Close() {}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("Sizes lie")
|
panic("Sizes lie")
|
||||||
}
|
}
|
||||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
newIt := ts.TripleIterator(it.Direction(), val)
|
||||||
newIt.CopyTagsFrom(it)
|
newIt.CopyTagsFrom(it)
|
||||||
for _, tag := range primary.Tags() {
|
for _, tag := range primary.Tags() {
|
||||||
newIt.AddFixedTag(tag, val)
|
newIt.AddFixedTag(tag, val)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ func TestMemstore(t *testing.T) {
|
||||||
So(ts.Size(), ShouldEqual, 11)
|
So(ts.Size(), ShouldEqual, 11)
|
||||||
})
|
})
|
||||||
Convey("It should have an Id Space that makes sense", func() {
|
Convey("It should have an Id Space that makes sense", func() {
|
||||||
v := ts.GetIdFor("C")
|
v := ts.ValueOf("C")
|
||||||
So(v.(int64), ShouldEqual, 4)
|
So(v.(int64), ShouldEqual, 4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -40,13 +40,13 @@ func TestMemstore(t *testing.T) {
|
||||||
func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
||||||
ts := MakeTestingMemstore()
|
ts := MakeTestingMemstore()
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.AddValue(ts.GetIdFor("C"))
|
fixed.AddValue(ts.ValueOf("C"))
|
||||||
all := ts.GetNodesAllIterator()
|
all := ts.NodesAllIterator()
|
||||||
lto := iterator.NewLinksTo(ts, all, graph.Object)
|
lto := iterator.NewLinksTo(ts, all, graph.Object)
|
||||||
innerAnd := iterator.NewAnd()
|
innerAnd := iterator.NewAnd()
|
||||||
|
|
||||||
fixed2 := ts.FixedIterator()
|
fixed2 := ts.FixedIterator()
|
||||||
fixed2.AddValue(ts.GetIdFor("follows"))
|
fixed2.AddValue(ts.ValueOf("follows"))
|
||||||
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
||||||
innerAnd.AddSubIterator(lto2)
|
innerAnd.AddSubIterator(lto2)
|
||||||
innerAnd.AddSubIterator(lto)
|
innerAnd.AddSubIterator(lto)
|
||||||
|
|
@ -58,19 +58,19 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("Expected one matching subtree")
|
t.Error("Expected one matching subtree")
|
||||||
}
|
}
|
||||||
if ts.GetNameFor(val) != "C" {
|
if ts.NameOf(val) != "C" {
|
||||||
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.GetNameFor(val))
|
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.NameOf(val))
|
||||||
}
|
}
|
||||||
expected := make([]string, 2)
|
expected := make([]string, 2)
|
||||||
expected[0] = "B"
|
expected[0] = "B"
|
||||||
expected[1] = "D"
|
expected[1] = "D"
|
||||||
actualOut := make([]string, 2)
|
actualOut := make([]string, 2)
|
||||||
actualOut[0] = ts.GetNameFor(all.LastResult())
|
actualOut[0] = ts.NameOf(all.LastResult())
|
||||||
nresultOk := outerAnd.NextResult()
|
nresultOk := outerAnd.NextResult()
|
||||||
if !nresultOk {
|
if !nresultOk {
|
||||||
t.Error("Expected two results got one")
|
t.Error("Expected two results got one")
|
||||||
}
|
}
|
||||||
actualOut[1] = ts.GetNameFor(all.LastResult())
|
actualOut[1] = ts.NameOf(all.LastResult())
|
||||||
nresultOk = outerAnd.NextResult()
|
nresultOk = outerAnd.NextResult()
|
||||||
if nresultOk {
|
if nresultOk {
|
||||||
t.Error("Expected two results got three")
|
t.Error("Expected two results got three")
|
||||||
|
|
@ -98,7 +98,7 @@ func CompareStringSlices(t *testing.T, expected []string, actual []string) {
|
||||||
func TestLinksToOptimization(t *testing.T) {
|
func TestLinksToOptimization(t *testing.T) {
|
||||||
ts := MakeTestingMemstore()
|
ts := MakeTestingMemstore()
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.AddValue(ts.GetIdFor("cool"))
|
fixed.AddValue(ts.ValueOf("cool"))
|
||||||
lto := iterator.NewLinksTo(ts, fixed, graph.Object)
|
lto := iterator.NewLinksTo(ts, fixed, graph.Object)
|
||||||
lto.AddTag("foo")
|
lto.AddTag("foo")
|
||||||
newIt, changed := lto.Optimize()
|
newIt, changed := lto.Optimize()
|
||||||
|
|
@ -122,10 +122,10 @@ func TestRemoveTriple(t *testing.T) {
|
||||||
ts := MakeTestingMemstore()
|
ts := MakeTestingMemstore()
|
||||||
ts.RemoveTriple(&graph.Triple{"E", "follows", "F", ""})
|
ts.RemoveTriple(&graph.Triple{"E", "follows", "F", ""})
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.AddValue(ts.GetIdFor("E"))
|
fixed.AddValue(ts.ValueOf("E"))
|
||||||
lto := iterator.NewLinksTo(ts, fixed, graph.Subject)
|
lto := iterator.NewLinksTo(ts, fixed, graph.Subject)
|
||||||
fixed2 := ts.FixedIterator()
|
fixed2 := ts.FixedIterator()
|
||||||
fixed2.AddValue(ts.GetIdFor("follows"))
|
fixed2.AddValue(ts.ValueOf("follows"))
|
||||||
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
||||||
innerAnd := iterator.NewAnd()
|
innerAnd := iterator.NewAnd()
|
||||||
innerAnd.AddSubIterator(lto2)
|
innerAnd.AddSubIterator(lto2)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap
|
||||||
var m Iterator
|
var m Iterator
|
||||||
iterator.BaseInit(&m.Base)
|
iterator.BaseInit(&m.Base)
|
||||||
|
|
||||||
m.name = ts.GetNameFor(val)
|
m.name = ts.NameOf(val)
|
||||||
m.collection = collection
|
m.collection = collection
|
||||||
switch d {
|
switch d {
|
||||||
case graph.Subject:
|
case graph.Subject:
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ type TripleStore struct {
|
||||||
idCache *IDLru
|
idCache *IDLru
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
func CreateNewMongoGraph(addr string, options graph.Options) bool {
|
||||||
conn, err := mgo.Dial(addr)
|
conn, err := mgo.Dial(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("Error connecting: ", err)
|
glog.Fatal("Error connecting: ", err)
|
||||||
|
|
@ -45,7 +45,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
||||||
}
|
}
|
||||||
conn.SetSafe(&mgo.Safe{})
|
conn.SetSafe(&mgo.Safe{})
|
||||||
dbName := DefaultDBName
|
dbName := DefaultDBName
|
||||||
if val, ok := options.GetStringKey("database_name"); ok {
|
if val, ok := options.StringKey("database_name"); ok {
|
||||||
dbName = val
|
dbName = val
|
||||||
}
|
}
|
||||||
db := conn.DB(dbName)
|
db := conn.DB(dbName)
|
||||||
|
|
@ -66,7 +66,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
|
func NewTripleStore(addr string, options graph.Options) *TripleStore {
|
||||||
var ts TripleStore
|
var ts TripleStore
|
||||||
conn, err := mgo.Dial(addr)
|
conn, err := mgo.Dial(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -74,7 +74,7 @@ func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
|
||||||
}
|
}
|
||||||
conn.SetSafe(&mgo.Safe{})
|
conn.SetSafe(&mgo.Safe{})
|
||||||
dbName := DefaultDBName
|
dbName := DefaultDBName
|
||||||
if val, ok := options.GetStringKey("database_name"); ok {
|
if val, ok := options.StringKey("database_name"); ok {
|
||||||
dbName = val
|
dbName = val
|
||||||
}
|
}
|
||||||
ts.db = conn.DB(dbName)
|
ts.db = conn.DB(dbName)
|
||||||
|
|
@ -108,7 +108,7 @@ type MongoNode struct {
|
||||||
|
|
||||||
func (ts *TripleStore) updateNodeBy(node_name string, inc int) {
|
func (ts *TripleStore) updateNodeBy(node_name string, inc int) {
|
||||||
var size MongoNode
|
var size MongoNode
|
||||||
node := ts.GetIdFor(node_name)
|
node := ts.ValueOf(node_name)
|
||||||
err := ts.db.C("nodes").FindId(node).One(&size)
|
err := ts.db.C("nodes").FindId(node).One(&size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "not found" {
|
if err.Error() == "not found" {
|
||||||
|
|
@ -209,7 +209,7 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) Triple(val graph.TSVal) *graph.Triple {
|
||||||
var bsonDoc bson.M
|
var bsonDoc bson.M
|
||||||
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -223,23 +223,23 @@ func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||||
return NewIterator(ts, "triples", d, val)
|
return NewIterator(ts, "triples", d, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||||
return NewAllIterator(ts, "nodes")
|
return NewAllIterator(ts, "nodes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||||
return NewAllIterator(ts, "triples")
|
return NewAllIterator(ts, "triples")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
|
||||||
return ts.ConvertStringToByteHash(s)
|
return ts.ConvertStringToByteHash(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetNameFor(v graph.TSVal) string {
|
func (ts *TripleStore) NameOf(v graph.TSVal) string {
|
||||||
val, ok := ts.idCache.Get(v.(string))
|
val, ok := ts.idCache.Get(v.(string))
|
||||||
if ok {
|
if ok {
|
||||||
return val
|
return val
|
||||||
|
|
@ -274,7 +274,7 @@ func (ts *TripleStore) Close() {
|
||||||
ts.db.Session.Close()
|
ts.db.Session.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TripleStore) GetTripleDirection(in graph.TSVal, d graph.Direction) graph.TSVal {
|
func (ts *TripleStore) TripleDirection(in graph.TSVal, d graph.Direction) graph.TSVal {
|
||||||
// Maybe do the trick here
|
// Maybe do the trick here
|
||||||
var offset int
|
var offset int
|
||||||
switch d {
|
switch d {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("Sizes lie")
|
panic("Sizes lie")
|
||||||
}
|
}
|
||||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
newIt := ts.TripleIterator(it.Direction(), val)
|
||||||
newIt.CopyTagsFrom(it)
|
newIt.CopyTagsFrom(it)
|
||||||
for _, tag := range primary.Tags() {
|
for _, tag := range primary.Tags() {
|
||||||
newIt.AddFixedTag(tag, val)
|
newIt.AddFixedTag(tag, val)
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
||||||
var out graph.Iterator
|
var out graph.Iterator
|
||||||
nodeID := getIdentString(tree)
|
nodeID := getIdentString(tree)
|
||||||
if tree.Children[0].Name == "Variable" {
|
if tree.Children[0].Name == "Variable" {
|
||||||
allIt := ts.GetNodesAllIterator()
|
allIt := ts.NodesAllIterator()
|
||||||
allIt.AddTag(nodeID)
|
allIt.AddTag(nodeID)
|
||||||
out = allIt
|
out = allIt
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -197,7 +197,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
||||||
n = nodeID[1:]
|
n = nodeID[1:]
|
||||||
}
|
}
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
fixed.AddValue(ts.GetIdFor(n))
|
fixed.AddValue(ts.ValueOf(n))
|
||||||
out = fixed
|
out = fixed
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
|
||||||
So(it.Type(), ShouldEqual, "and")
|
So(it.Type(), ShouldEqual, "and")
|
||||||
out, ok := it.Next()
|
out, ok := it.Next()
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
So(out, ShouldEqual, ts.GetIdFor("i"))
|
So(out, ShouldEqual, ts.ValueOf("i"))
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It can get an internal linkage", func() {
|
Convey("It can get an internal linkage", func() {
|
||||||
|
|
@ -57,7 +57,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
|
||||||
So(it.Type(), ShouldEqual, "and")
|
So(it.Type(), ShouldEqual, "and")
|
||||||
out, ok := it.Next()
|
out, ok := it.Next()
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
So(out, ShouldEqual, ts.GetIdFor("i"))
|
So(out, ShouldEqual, ts.ValueOf("i"))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -78,8 +78,8 @@ func TestTreeConstraintParse(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("Got no results")
|
t.Error("Got no results")
|
||||||
}
|
}
|
||||||
if out != ts.GetIdFor("i") {
|
if out != ts.ValueOf("i") {
|
||||||
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
|
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,8 +97,8 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
||||||
}
|
}
|
||||||
tags := make(map[string]graph.TSVal)
|
tags := make(map[string]graph.TSVal)
|
||||||
it.TagResults(&tags)
|
it.TagResults(&tags)
|
||||||
if ts.GetNameFor(tags["$a"]) != "food" {
|
if ts.NameOf(tags["$a"]) != "food" {
|
||||||
t.Errorf("Got %s, expected food", ts.GetNameFor(tags["$a"]))
|
t.Errorf("Got %s, expected food", ts.NameOf(tags["$a"]))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -119,8 +119,8 @@ func TestMultipleConstraintParse(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("Got no results")
|
t.Error("Got no results")
|
||||||
}
|
}
|
||||||
if out != ts.GetIdFor("i") {
|
if out != ts.ValueOf("i") {
|
||||||
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
|
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||||
}
|
}
|
||||||
_, ok = it.Next()
|
_, ok = it.Next()
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func (s *Session) ToText(result interface{}) string {
|
||||||
if k == "$_" {
|
if k == "$_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor((*tags)[k]))
|
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf((*tags)[k]))
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,24 +47,24 @@ type TripleStore interface {
|
||||||
RemoveTriple(*Triple)
|
RemoveTriple(*Triple)
|
||||||
|
|
||||||
// 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.
|
||||||
GetTriple(TSVal) *Triple
|
Triple(TSVal) *Triple
|
||||||
|
|
||||||
// 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.
|
||||||
GetTripleIterator(Direction, TSVal) Iterator
|
TripleIterator(Direction, TSVal) Iterator
|
||||||
|
|
||||||
// Returns an iterator enumerating all nodes in the graph.
|
// Returns an iterator enumerating all nodes in the graph.
|
||||||
GetNodesAllIterator() Iterator
|
NodesAllIterator() Iterator
|
||||||
|
|
||||||
// Returns an iterator enumerating all links in the graph.
|
// Returns an iterator enumerating all links in the graph.
|
||||||
GetTriplesAllIterator() Iterator
|
TriplesAllIterator() Iterator
|
||||||
|
|
||||||
// Given a node ID, return the opaque token used by the TripleStore
|
// Given a node ID, return the opaque token used by the TripleStore
|
||||||
// to represent that id.
|
// to represent that id.
|
||||||
GetIdFor(string) TSVal
|
ValueOf(string) TSVal
|
||||||
|
|
||||||
// Given an opaque token, return the node that it represents.
|
// Given an opaque token, return the node that it represents.
|
||||||
GetNameFor(TSVal) string
|
NameOf(TSVal) string
|
||||||
|
|
||||||
// Returns the number of triples currently stored.
|
// Returns the number of triples currently stored.
|
||||||
Size() int64
|
Size() int64
|
||||||
|
|
@ -88,13 +88,13 @@ type TripleStore interface {
|
||||||
// gives the TripleStore the opportunity to make this optimization.
|
// gives the TripleStore the opportunity to make this optimization.
|
||||||
//
|
//
|
||||||
// Iterators will call this. At worst, a valid implementation is
|
// Iterators will call this. At worst, a valid implementation is
|
||||||
// self.GetIdFor(self.GetTriple(triple_id).Get(dir))
|
// ts.IdFor(ts.Triple(triple_id).Get(dir))
|
||||||
GetTripleDirection(triple_id TSVal, d Direction) TSVal
|
TripleDirection(triple_id TSVal, d Direction) TSVal
|
||||||
}
|
}
|
||||||
|
|
||||||
type OptionsDict map[string]interface{}
|
type Options map[string]interface{}
|
||||||
|
|
||||||
func (d OptionsDict) GetIntKey(key string) (int, bool) {
|
func (d Options) IntKey(key string) (int, bool) {
|
||||||
if val, ok := d[key]; ok {
|
if val, ok := d[key]; ok {
|
||||||
switch vv := val.(type) {
|
switch vv := val.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
|
|
@ -106,7 +106,7 @@ func (d OptionsDict) GetIntKey(key string) (int, bool) {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d OptionsDict) GetStringKey(key string) (string, bool) {
|
func (d Options) StringKey(key string) (string, bool) {
|
||||||
if val, ok := d[key]; ok {
|
if val, ok := d[key]; ok {
|
||||||
switch vv := val.(type) {
|
switch vv := val.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,14 @@ func makeListOfStringsFromArrayValue(obj *otto.Object) []string {
|
||||||
|
|
||||||
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
|
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
|
||||||
if val.IsNull() || val.IsUndefined() {
|
if val.IsNull() || val.IsUndefined() {
|
||||||
return ts.GetNodesAllIterator()
|
return ts.NodesAllIterator()
|
||||||
}
|
}
|
||||||
if val.IsPrimitive() {
|
if val.IsPrimitive() {
|
||||||
thing, _ := val.Export()
|
thing, _ := val.Export()
|
||||||
switch v := thing.(type) {
|
switch v := thing.(type) {
|
||||||
case string:
|
case string:
|
||||||
it := ts.FixedIterator()
|
it := ts.FixedIterator()
|
||||||
it.AddValue(ts.GetIdFor(v))
|
it.AddValue(ts.ValueOf(v))
|
||||||
return it
|
return it
|
||||||
default:
|
default:
|
||||||
glog.Errorln("Trying to build unknown primitive value.")
|
glog.Errorln("Trying to build unknown primitive value.")
|
||||||
|
|
@ -89,7 +89,7 @@ func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator
|
||||||
strings := makeListOfStringsFromArrayValue(val.Object())
|
strings := makeListOfStringsFromArrayValue(val.Object())
|
||||||
it := ts.FixedIterator()
|
it := ts.FixedIterator()
|
||||||
for _, x := range strings {
|
for _, x := range strings {
|
||||||
it.AddValue(ts.GetIdFor(x))
|
it.AddValue(ts.ValueOf(x))
|
||||||
}
|
}
|
||||||
return it
|
return it
|
||||||
case "Number":
|
case "Number":
|
||||||
|
|
@ -101,7 +101,7 @@ func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator
|
||||||
case "String":
|
case "String":
|
||||||
it := ts.FixedIterator()
|
it := ts.FixedIterator()
|
||||||
str, _ := val.ToString()
|
str, _ := val.ToString()
|
||||||
it.AddValue(ts.GetIdFor(str))
|
it.AddValue(ts.ValueOf(str))
|
||||||
return it
|
return it
|
||||||
default:
|
default:
|
||||||
glog.Errorln("Trying to handle unsupported Javascript value.")
|
glog.Errorln("Trying to handle unsupported Javascript value.")
|
||||||
|
|
@ -120,7 +120,7 @@ func buildInOutIterator(obj *otto.Object, ts graph.TripleStore, base graph.Itera
|
||||||
length, _ := lengthVal.ToInteger()
|
length, _ := lengthVal.ToInteger()
|
||||||
var predicateNodeIterator graph.Iterator
|
var predicateNodeIterator graph.Iterator
|
||||||
if length == 0 {
|
if length == 0 {
|
||||||
predicateNodeIterator = ts.GetNodesAllIterator()
|
predicateNodeIterator = ts.NodesAllIterator()
|
||||||
} else {
|
} else {
|
||||||
zero, _ := argArray.Get("0")
|
zero, _ := argArray.Get("0")
|
||||||
predicateNodeIterator = buildIteratorFromValue(zero, ts)
|
predicateNodeIterator = buildIteratorFromValue(zero, ts)
|
||||||
|
|
@ -168,11 +168,11 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
switch kind {
|
switch kind {
|
||||||
case "vertex":
|
case "vertex":
|
||||||
if len(stringArgs) == 0 {
|
if len(stringArgs) == 0 {
|
||||||
it = ts.GetNodesAllIterator()
|
it = ts.NodesAllIterator()
|
||||||
} else {
|
} else {
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
for _, name := range stringArgs {
|
for _, name := range stringArgs {
|
||||||
fixed.AddValue(ts.GetIdFor(name))
|
fixed.AddValue(ts.ValueOf(name))
|
||||||
}
|
}
|
||||||
it = fixed
|
it = fixed
|
||||||
}
|
}
|
||||||
|
|
@ -182,7 +182,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
it.AddTag(tag)
|
it.AddTag(tag)
|
||||||
}
|
}
|
||||||
case "save":
|
case "save":
|
||||||
all := ts.GetNodesAllIterator()
|
all := ts.NodesAllIterator()
|
||||||
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
||||||
return iterator.NewNull()
|
return iterator.NewNull()
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +192,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
all.AddTag(stringArgs[0])
|
all.AddTag(stringArgs[0])
|
||||||
}
|
}
|
||||||
predFixed := ts.FixedIterator()
|
predFixed := ts.FixedIterator()
|
||||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
|
||||||
subAnd := iterator.NewAnd()
|
subAnd := iterator.NewAnd()
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Object))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Object))
|
||||||
|
|
@ -202,7 +202,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
and.AddSubIterator(subIt)
|
and.AddSubIterator(subIt)
|
||||||
it = and
|
it = and
|
||||||
case "saver":
|
case "saver":
|
||||||
all := ts.GetNodesAllIterator()
|
all := ts.NodesAllIterator()
|
||||||
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
||||||
return iterator.NewNull()
|
return iterator.NewNull()
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +212,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
all.AddTag(stringArgs[0])
|
all.AddTag(stringArgs[0])
|
||||||
}
|
}
|
||||||
predFixed := ts.FixedIterator()
|
predFixed := ts.FixedIterator()
|
||||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
|
||||||
subAnd := iterator.NewAnd()
|
subAnd := iterator.NewAnd()
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Subject))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Subject))
|
||||||
|
|
@ -227,10 +227,10 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
return iterator.NewNull()
|
return iterator.NewNull()
|
||||||
}
|
}
|
||||||
for _, name := range stringArgs[1:] {
|
for _, name := range stringArgs[1:] {
|
||||||
fixed.AddValue(ts.GetIdFor(name))
|
fixed.AddValue(ts.ValueOf(name))
|
||||||
}
|
}
|
||||||
predFixed := ts.FixedIterator()
|
predFixed := ts.FixedIterator()
|
||||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
|
||||||
subAnd := iterator.NewAnd()
|
subAnd := iterator.NewAnd()
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed, graph.Object))
|
subAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed, graph.Object))
|
||||||
|
|
@ -263,7 +263,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
case "is":
|
case "is":
|
||||||
fixed := ts.FixedIterator()
|
fixed := ts.FixedIterator()
|
||||||
for _, name := range stringArgs {
|
for _, name := range stringArgs {
|
||||||
fixed.AddValue(ts.GetIdFor(name))
|
fixed.AddValue(ts.ValueOf(name))
|
||||||
}
|
}
|
||||||
and := iterator.NewAnd()
|
and := iterator.NewAnd()
|
||||||
and.AddSubIterator(fixed)
|
and.AddSubIterator(fixed)
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ func mapFunc(env *otto.Otto, ses *Session, obj *otto.Object) func(otto.FunctionC
|
||||||
func tagsToValueMap(m map[string]graph.TSVal, ses *Session) map[string]string {
|
func tagsToValueMap(m map[string]graph.TSVal, ses *Session) map[string]string {
|
||||||
outputMap := make(map[string]string)
|
outputMap := make(map[string]string)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
outputMap[k] = ses.ts.GetNameFor(v)
|
outputMap[k] = ses.ts.NameOf(v)
|
||||||
}
|
}
|
||||||
return outputMap
|
return outputMap
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +191,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
output = append(output, ses.ts.GetNameFor(val))
|
output = append(output, ses.ts.NameOf(val))
|
||||||
count++
|
count++
|
||||||
if limit >= 0 && count >= limit {
|
if limit >= 0 && count >= limit {
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func runQueryGetTag(query string, tag string) ([]string, int) {
|
||||||
if data.val == nil {
|
if data.val == nil {
|
||||||
val := (*data.actualResults)[tag]
|
val := (*data.actualResults)[tag]
|
||||||
if val != nil {
|
if val != nil {
|
||||||
output = append(output, js.ts.GetNameFor(val))
|
output = append(output, js.ts.NameOf(val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ func (s *Session) ToText(result interface{}) string {
|
||||||
if k == "$_" {
|
if k == "$_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor((*tags)[k]))
|
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf((*tags)[k]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if data.val.IsObject() {
|
if data.val.IsObject() {
|
||||||
|
|
@ -234,7 +234,7 @@ func (ses *Session) BuildJson(result interface{}) {
|
||||||
}
|
}
|
||||||
sort.Strings(tagKeys)
|
sort.Strings(tagKeys)
|
||||||
for _, k := range tagKeys {
|
for _, k := range tagKeys {
|
||||||
obj[k] = ses.ts.GetNameFor((*tags)[k])
|
obj[k] = ses.ts.NameOf((*tags)[k])
|
||||||
}
|
}
|
||||||
ses.dataOutput = append(ses.dataOutput, obj)
|
ses.dataOutput = append(ses.dataOutput, obj)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ import (
|
||||||
|
|
||||||
func (q *Query) buildFixed(s string) graph.Iterator {
|
func (q *Query) buildFixed(s string) graph.Iterator {
|
||||||
f := q.ses.ts.FixedIterator()
|
f := q.ses.ts.FixedIterator()
|
||||||
f.AddValue(q.ses.ts.GetIdFor(s))
|
f.AddValue(q.ses.ts.ValueOf(s))
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Query) buildResultIterator(path Path) graph.Iterator {
|
func (q *Query) buildResultIterator(path Path) graph.Iterator {
|
||||||
all := q.ses.ts.GetNodesAllIterator()
|
all := q.ses.ts.NodesAllIterator()
|
||||||
all.AddTag(string(path))
|
all.AddTag(string(path))
|
||||||
return all
|
return all
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ func (q *Query) buildIteratorTreeInternal(query interface{}, path Path) (it grap
|
||||||
|
|
||||||
func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path Path) (graph.Iterator, error) {
|
func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path Path) (graph.Iterator, error) {
|
||||||
it := iterator.NewAnd()
|
it := iterator.NewAnd()
|
||||||
it.AddSubIterator(q.ses.ts.GetNodesAllIterator())
|
it.AddSubIterator(q.ses.ts.NodesAllIterator())
|
||||||
var err error
|
var err error
|
||||||
err = nil
|
err = nil
|
||||||
outputStructure := make(map[string]interface{})
|
outputStructure := make(map[string]interface{})
|
||||||
|
|
@ -138,7 +138,7 @@ func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path
|
||||||
}
|
}
|
||||||
subAnd := iterator.NewAnd()
|
subAnd := iterator.NewAnd()
|
||||||
predFixed := q.ses.ts.FixedIterator()
|
predFixed := q.ses.ts.FixedIterator()
|
||||||
predFixed.AddValue(q.ses.ts.GetIdFor(pred))
|
predFixed.AddValue(q.ses.ts.ValueOf(pred))
|
||||||
subAnd.AddSubIterator(iterator.NewLinksTo(q.ses.ts, predFixed, graph.Predicate))
|
subAnd.AddSubIterator(iterator.NewLinksTo(q.ses.ts, predFixed, graph.Predicate))
|
||||||
if reverse {
|
if reverse {
|
||||||
lto := iterator.NewLinksTo(q.ses.ts, builtIt, graph.Subject)
|
lto := iterator.NewLinksTo(q.ses.ts, builtIt, graph.Subject)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func (q *Query) treeifyResult(tags map[string]graph.TSVal) map[ResultPath]string
|
||||||
if v == nil {
|
if v == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
results[Path(k)] = q.ses.ts.GetNameFor(v)
|
results[Path(k)] = q.ses.ts.NameOf(v)
|
||||||
}
|
}
|
||||||
resultPaths := make(map[ResultPath]string)
|
resultPaths := make(map[ResultPath]string)
|
||||||
for k, v := range results {
|
for k, v := range results {
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ func (s *Session) ToText(result interface{}) string {
|
||||||
if k == "$_" {
|
if k == "$_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor(tags[k]))
|
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf(tags[k]))
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue