Reduce TripleStore interface names

This commit is contained in:
kortschak 2014-07-02 11:40:33 +09:30
parent 8576f66d20
commit b89d4f392c
29 changed files with 156 additions and 156 deletions

View file

@ -126,13 +126,13 @@ func (it *HasA) DebugString(indent int) string {
func (it *HasA) Check(val graph.TSVal) bool {
graph.CheckLogIn(it, val)
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
if it.resultIt != nil {
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())
}
@ -146,10 +146,10 @@ func (it *HasA) GetCheckResult() bool {
break
}
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) {
it.Last = it.ts.GetTripleDirection(linkVal, it.dir)
it.Last = it.ts.TripleDirection(linkVal, it.dir)
return true
}
}
@ -184,8 +184,8 @@ func (it *HasA) Next() (graph.TSVal, bool) {
if !ok {
return graph.NextLogOut(it, 0, false)
}
name := it.ts.GetTriple(tID).Get(it.dir)
val := it.ts.GetIdFor(name)
name := it.ts.Triple(tID).Get(it.dir)
val := it.ts.ValueOf(name)
it.Last = val
return graph.NextLogOut(it, val, true)
}

View file

@ -100,7 +100,7 @@ func (it *LinksTo) DebugString(indent int) string {
// for the LinksTo.
func (it *LinksTo) Check(val graph.TSVal) bool {
graph.CheckLogIn(it, val)
node := it.ts.GetTripleDirection(val, it.dir)
node := it.ts.TripleDirection(val, it.dir)
if it.primaryIt.Check(node) {
it.Last = val
return graph.CheckLogOut(it, val, true)
@ -146,7 +146,7 @@ func (it *LinksTo) Next() (graph.TSVal, bool) {
return graph.NextLogOut(it, 0, false)
}
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.
return it.Next()
}

View file

@ -24,16 +24,16 @@ func TestLinksTo(t *testing.T) {
ts := new(TestTripleStore)
tsFixed := newFixed()
tsFixed.AddValue(2)
ts.On("GetIdFor", "cool").Return(1)
ts.On("GetTripleIterator", graph.Object, 1).Return(tsFixed)
ts.On("ValueOf", "cool").Return(1)
ts.On("TripleIterator", graph.Object, 1).Return(tsFixed)
fixed := newFixed()
fixed.AddValue(ts.GetIdFor("cool"))
fixed.AddValue(ts.ValueOf("cool"))
lto := NewLinksTo(ts, fixed, graph.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.GetTriple(2), ts.GetTriple(val))
t.Errorf("Triple index 2, such as %s, should match %s", ts.Triple(2), ts.Triple(val))
}
}

View file

@ -27,23 +27,23 @@ type TestTripleStore struct {
mock.Mock
}
func (ts *TestTripleStore) GetIdFor(s string) graph.TSVal {
func (ts *TestTripleStore) ValueOf(s string) graph.TSVal {
args := ts.Mock.Called(s)
return args.Get(0)
}
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
func (ts *TestTripleStore) GetTriple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
func (ts *TestTripleStore) GetTripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
func (ts *TestTripleStore) Triple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
args := ts.Mock.Called(d, i)
return args.Get(0).(graph.Iterator)
}
func (ts *TestTripleStore) GetNodesAllIterator() graph.Iterator { return &Null{} }
func (ts *TestTripleStore) GetTriplesAllIterator() graph.Iterator { return &Null{} }
func (ts *TestTripleStore) NodesAllIterator() graph.Iterator { return &Null{} }
func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{} }
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
return &Null{}
}
func (ts *TestTripleStore) GetNameFor(v graph.TSVal) string {
func (ts *TestTripleStore) NameOf(v graph.TSVal) string {
args := ts.Mock.Called(v)
return args.Get(0).(string)
}
@ -55,6 +55,6 @@ func (ts *TestTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator,
func (ts *TestTripleStore) FixedIterator() graph.FixedIterator {
return NewFixedIteratorWithCompare(BasicEquality)
}
func (ts *TestTripleStore) Close() {}
func (ts *TestTripleStore) GetTripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
func (ts *TestTripleStore) Close() {}
func (ts *TestTripleStore) TripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}

View file

@ -133,7 +133,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
if !more {
break
}
n.Values = append(n.Values, qs.ts.GetNameFor(val))
n.Values = append(n.Values, qs.ts.NameOf(val))
}
case "hasa":
hasa := it.(*HasA)

View file

@ -25,8 +25,8 @@ import (
func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
fixed_obj := ts.FixedIterator()
fixed_pred := ts.FixedIterator()
fixed_obj.AddValue(ts.GetIdFor(target))
fixed_pred.AddValue(ts.GetIdFor("status"))
fixed_obj.AddValue(ts.ValueOf(target))
fixed_pred.AddValue(ts.ValueOf("status"))
fixed_obj.AddTag(tag)
lto1 := NewLinksTo(ts, fixed_obj, graph.Object)
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) {
var queryShape map[string]interface{}
ts := new(TestTripleStore)
ts.On("GetIdFor", "cool").Return(1)
ts.On("GetNameFor", 1).Return("cool")
ts.On("GetIdFor", "status").Return(2)
ts.On("GetNameFor", 2).Return("status")
ts.On("GetIdFor", "fun").Return(3)
ts.On("GetNameFor", 3).Return("fun")
ts.On("GetIdFor", "name").Return(4)
ts.On("GetNameFor", 4).Return("name")
ts.On("ValueOf", "cool").Return(1)
ts.On("NameOf", 1).Return("cool")
ts.On("ValueOf", "status").Return(2)
ts.On("NameOf", 2).Return("status")
ts.On("ValueOf", "fun").Return(3)
ts.On("NameOf", 3).Return("fun")
ts.On("ValueOf", "name").Return(4)
ts.On("NameOf", 4).Return("name")
Convey("Given a single linkage iterator's shape", t, func() {
queryShape = make(map[string]interface{})
@ -92,7 +92,7 @@ func TestQueryShape(t *testing.T) {
andInternal.AddSubIterator(hasa1)
andInternal.AddSubIterator(hasa2)
fixed_pred := ts.FixedIterator()
fixed_pred.AddValue(ts.GetIdFor("name"))
fixed_pred.AddValue(ts.ValueOf("name"))
lto1 := NewLinksTo(ts, andInternal, graph.Subject)
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
and := NewAnd()

View file

@ -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.
func (it *Comparison) doComparison(val graph.TSVal) bool {
//TODO(barakmich): Implement string comparison.
nodeStr := it.ts.GetNameFor(val)
nodeStr := it.ts.NameOf(val)
switch cVal := it.val.(type) {
case int:
cInt := int64(cVal)

View file

@ -23,8 +23,8 @@ import (
func SetupMockTripleStore(nameMap map[string]int) *TestTripleStore {
ts := new(TestTripleStore)
for k, v := range nameMap {
ts.On("GetIdFor", k).Return(v)
ts.On("GetNameFor", v).Return(k)
ts.On("ValueOf", k).Return(v)
ts.On("NameOf", v).Return(k)
}
return ts
}
@ -59,7 +59,7 @@ func checkIteratorContains(ts graph.TripleStore, it graph.Iterator, expected []s
if !ok {
break
}
actual = append(actual, ts.GetNameFor(val))
actual = append(actual, ts.NameOf(val))
}
actualSet := actual[:]
for _, a := range expected {

View file

@ -177,8 +177,8 @@ func (it *Iterator) Check(v graph.TSVal) bool {
return true
}
} else {
nameForDir := it.ts.GetTriple(v).Get(it.dir)
hashForDir := it.ts.GetIdFor(nameForDir).([]byte)
nameForDir := it.ts.Triple(v).Get(it.dir)
hashForDir := it.ts.ValueOf(nameForDir).([]byte)
if bytes.Equal(hashForDir, it.checkId) {
return true
}
@ -192,7 +192,7 @@ func (it *Iterator) Size() (int64, bool) {
func (it *Iterator) DebugString(indent int) string {
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" }

View file

@ -50,7 +50,7 @@ func extractTripleFromIterator(ts graph.TripleStore, it graph.Iterator) []string
if !ok {
break
}
output = append(output, ts.GetTriple(val).String())
output = append(output, ts.Triple(val).String())
}
return output
}
@ -62,7 +62,7 @@ func extractValuesFromIterator(ts graph.TripleStore, it graph.Iterator) []string
if !ok {
break
}
output = append(output, ts.GetNameFor(val))
output = append(output, ts.NameOf(val))
}
return output
}
@ -113,7 +113,7 @@ func TestLoadDatabase(t *testing.T) {
Convey("Can load a single triple", func() {
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)
})
@ -121,12 +121,12 @@ func TestLoadDatabase(t *testing.T) {
ts.AddTripleSet(makeTripleSet())
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() {
ts.RemoveTriple(&graph.Triple{"A", "follows", "B", ""})
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
Convey("Can create an all iterator for nodes", func() {
it = ts.GetNodesAllIterator()
it = ts.NodesAllIterator()
So(it, ShouldNotBeNil)
Convey("Has basics", func() {
@ -192,9 +192,9 @@ func TestIterator(t *testing.T) {
})
Convey("Contains a couple nodes", func() {
So(it.Check(ts.GetIdFor("A")), ShouldBeTrue)
So(it.Check(ts.GetIdFor("cool")), ShouldBeTrue)
//So(it.Check(ts.GetIdFor("baller")), ShouldBeFalse)
So(it.Check(ts.ValueOf("A")), ShouldBeTrue)
So(it.Check(ts.ValueOf("cool")), ShouldBeTrue)
//So(it.Check(ts.ValueOf("baller")), ShouldBeFalse)
})
Reset(func() {
@ -203,7 +203,7 @@ func TestIterator(t *testing.T) {
})
Convey("Can create an all iterator for edges", func() {
it := ts.GetTriplesAllIterator()
it := ts.TriplesAllIterator()
So(it, ShouldNotBeNil)
Convey("Has basics", func() {
size, accurate := it.Size()
@ -217,7 +217,7 @@ func TestIterator(t *testing.T) {
Convey("Iterates an edge", func() {
edge_val, _ := it.Next()
triple := ts.GetTriple(edge_val)
triple := ts.Triple(edge_val)
set := makeTripleSet()
var string_set []string
for _, t := range set {
@ -249,7 +249,7 @@ func TestSetIterator(t *testing.T) {
var it graph.Iterator
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() {
expected := []string{
@ -264,7 +264,7 @@ func TestSetIterator(t *testing.T) {
Convey("And checkable", func() {
and := iterator.NewAnd()
and.AddSubIterator(ts.GetTriplesAllIterator())
and.AddSubIterator(ts.TriplesAllIterator())
and.AddSubIterator(it)
expected := []string{
@ -283,7 +283,7 @@ func TestSetIterator(t *testing.T) {
})
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() {
expected := []string{
@ -298,7 +298,7 @@ func TestSetIterator(t *testing.T) {
Convey("Mutually and-checkable", func() {
and := iterator.NewAnd()
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
and.AddSubIterator(it)
expected := []string{
@ -313,7 +313,7 @@ func TestSetIterator(t *testing.T) {
})
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() {
expected := []string{
@ -330,7 +330,7 @@ func TestSetIterator(t *testing.T) {
})
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() {
expected := []string{
@ -347,7 +347,7 @@ func TestSetIterator(t *testing.T) {
Convey("Can be cross-checked", func() {
and := iterator.NewAnd()
// Order is important
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
and.AddSubIterator(it)
expected := []string{
@ -361,7 +361,7 @@ func TestSetIterator(t *testing.T) {
and := iterator.NewAnd()
// Order is important
and.AddSubIterator(it)
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
expected := []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() {
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("F"))
fixed.AddValue(ts.ValueOf("F"))
fixed.AddTag("internal")
lto = iterator.NewLinksTo(ts, fixed, graph.Object)

View file

@ -65,11 +65,11 @@ func CreateNewLevelDB(path string) bool {
return true
}
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
func NewTripleStore(path string, options graph.Options) *TripleStore {
var ts TripleStore
ts.path = path
cache_size := DefaultCacheSize
if val, ok := options.GetIntKey("cache_size_mb"); ok {
if val, ok := options.IntKey("cache_size_mb"); ok {
cache_size = val
}
ts.dbOpts = &opt.Options{
@ -78,7 +78,7 @@ func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
ts.dbOpts.ErrorIfMissing = true
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
}
ts.dbOpts.WriteBuffer = write_buffer_mb * opt.MiB
@ -301,7 +301,7 @@ func (ts *TripleStore) Close() {
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
b, err := ts.db.Get(k.([]byte), ts.readopts)
if err != nil && err != leveldb.ErrNotFound {
@ -328,7 +328,7 @@ func (ts *TripleStore) convertStringToByteHash(s string) []byte {
return key
}
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
return ts.createValueKeyFor(s)
}
@ -352,7 +352,7 @@ func (ts *TripleStore) getValueData(value_key []byte) ValueData {
return out
}
func (ts *TripleStore) GetNameFor(k graph.TSVal) string {
func (ts *TripleStore) NameOf(k graph.TSVal) string {
if k == nil {
glog.V(2).Infoln("k was nil")
return ""
@ -401,7 +401,7 @@ func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
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
switch d {
case graph.Subject:
@ -418,21 +418,21 @@ func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) gra
return NewIterator(prefix, d, val, ts)
}
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
return NewAllIterator("z", graph.Any, ts)
}
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
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)
offset := GetPositionFromPrefix(v[0:2], d, ts)
if offset != -1 {
return append([]byte("z"), v[offset:offset+ts.hasher.Size()]...)
} else {
return ts.GetTriple(val).Get(d)
return ts.Triple(val).Get(d)
}
}

View file

@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
if !ok {
panic("Sizes lie")
}
newIt := ts.GetTripleIterator(it.Direction(), val)
newIt := ts.TripleIterator(it.Direction(), val)
newIt.CopyTagsFrom(it)
for _, tag := range primary.Tags() {
newIt.AddFixedTag(tag, val)

View file

@ -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)]
}
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))
data := fmt.Sprintf("dir:%s val:%d", d, value.(int64))
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]
}
func (ts *TripleStore) GetNameFor(id graph.TSVal) string {
func (ts *TripleStore) NameOf(id graph.TSVal) string {
return ts.revIdMap[id.(int64)]
}
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
return iterator.NewInt64(0, ts.Size())
}
@ -259,12 +259,12 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator {
return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality)
}
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
name := ts.GetTriple(val).Get(d)
return ts.GetIdFor(name)
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
name := ts.Triple(val).Get(d)
return ts.ValueOf(name)
}
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
return NewMemstoreAllIterator(ts)
}
func (ts *TripleStore) Close() {}

View file

@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
if !ok {
panic("Sizes lie")
}
newIt := ts.GetTripleIterator(it.Direction(), val)
newIt := ts.TripleIterator(it.Direction(), val)
newIt.CopyTagsFrom(it)
for _, tag := range primary.Tags() {
newIt.AddFixedTag(tag, val)

View file

@ -31,7 +31,7 @@ func TestMemstore(t *testing.T) {
So(ts.Size(), ShouldEqual, 11)
})
Convey("It should have an Id Space that makes sense", func() {
v := ts.GetIdFor("C")
v := ts.ValueOf("C")
So(v.(int64), ShouldEqual, 4)
})
})
@ -40,13 +40,13 @@ func TestMemstore(t *testing.T) {
func TestIteratorsAndNextResultOrderA(t *testing.T) {
ts := MakeTestingMemstore()
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("C"))
all := ts.GetNodesAllIterator()
fixed.AddValue(ts.ValueOf("C"))
all := ts.NodesAllIterator()
lto := iterator.NewLinksTo(ts, all, graph.Object)
innerAnd := iterator.NewAnd()
fixed2 := ts.FixedIterator()
fixed2.AddValue(ts.GetIdFor("follows"))
fixed2.AddValue(ts.ValueOf("follows"))
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
innerAnd.AddSubIterator(lto2)
innerAnd.AddSubIterator(lto)
@ -58,19 +58,19 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
if !ok {
t.Error("Expected one matching subtree")
}
if ts.GetNameFor(val) != "C" {
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.GetNameFor(val))
if ts.NameOf(val) != "C" {
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.NameOf(val))
}
expected := make([]string, 2)
expected[0] = "B"
expected[1] = "D"
actualOut := make([]string, 2)
actualOut[0] = ts.GetNameFor(all.LastResult())
actualOut[0] = ts.NameOf(all.LastResult())
nresultOk := outerAnd.NextResult()
if !nresultOk {
t.Error("Expected two results got one")
}
actualOut[1] = ts.GetNameFor(all.LastResult())
actualOut[1] = ts.NameOf(all.LastResult())
nresultOk = outerAnd.NextResult()
if nresultOk {
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) {
ts := MakeTestingMemstore()
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("cool"))
fixed.AddValue(ts.ValueOf("cool"))
lto := iterator.NewLinksTo(ts, fixed, graph.Object)
lto.AddTag("foo")
newIt, changed := lto.Optimize()
@ -122,10 +122,10 @@ func TestRemoveTriple(t *testing.T) {
ts := MakeTestingMemstore()
ts.RemoveTriple(&graph.Triple{"E", "follows", "F", ""})
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("E"))
fixed.AddValue(ts.ValueOf("E"))
lto := iterator.NewLinksTo(ts, fixed, graph.Subject)
fixed2 := ts.FixedIterator()
fixed2.AddValue(ts.GetIdFor("follows"))
fixed2.AddValue(ts.ValueOf("follows"))
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
innerAnd := iterator.NewAnd()
innerAnd.AddSubIterator(lto2)

View file

@ -43,7 +43,7 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap
var m Iterator
iterator.BaseInit(&m.Base)
m.name = ts.GetNameFor(val)
m.name = ts.NameOf(val)
m.collection = collection
switch d {
case graph.Subject:

View file

@ -37,7 +37,7 @@ type TripleStore struct {
idCache *IDLru
}
func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
func CreateNewMongoGraph(addr string, options graph.Options) bool {
conn, err := mgo.Dial(addr)
if err != nil {
glog.Fatal("Error connecting: ", err)
@ -45,7 +45,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
}
conn.SetSafe(&mgo.Safe{})
dbName := DefaultDBName
if val, ok := options.GetStringKey("database_name"); ok {
if val, ok := options.StringKey("database_name"); ok {
dbName = val
}
db := conn.DB(dbName)
@ -66,7 +66,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
return true
}
func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
func NewTripleStore(addr string, options graph.Options) *TripleStore {
var ts TripleStore
conn, err := mgo.Dial(addr)
if err != nil {
@ -74,7 +74,7 @@ func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
}
conn.SetSafe(&mgo.Safe{})
dbName := DefaultDBName
if val, ok := options.GetStringKey("database_name"); ok {
if val, ok := options.StringKey("database_name"); ok {
dbName = val
}
ts.db = conn.DB(dbName)
@ -108,7 +108,7 @@ type MongoNode struct {
func (ts *TripleStore) updateNodeBy(node_name string, inc int) {
var size MongoNode
node := ts.GetIdFor(node_name)
node := ts.ValueOf(node_name)
err := ts.db.C("nodes").FindId(node).One(&size)
if err != nil {
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
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
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)
}
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
return NewAllIterator(ts, "nodes")
}
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
return NewAllIterator(ts, "triples")
}
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
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))
if ok {
return val
@ -274,7 +274,7 @@ func (ts *TripleStore) 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
var offset int
switch d {

View file

@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
if !ok {
panic("Sizes lie")
}
newIt := ts.GetTripleIterator(it.Direction(), val)
newIt := ts.TripleIterator(it.Direction(), val)
newIt.CopyTagsFrom(it)
for _, tag := range primary.Tags() {
newIt.AddFixedTag(tag, val)

View file

@ -188,7 +188,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
var out graph.Iterator
nodeID := getIdentString(tree)
if tree.Children[0].Name == "Variable" {
allIt := ts.GetNodesAllIterator()
allIt := ts.NodesAllIterator()
allIt.AddTag(nodeID)
out = allIt
} else {
@ -197,7 +197,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
n = nodeID[1:]
}
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor(n))
fixed.AddValue(ts.ValueOf(n))
out = fixed
}
return out

View file

@ -47,7 +47,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
So(it.Type(), ShouldEqual, "and")
out, ok := it.Next()
So(ok, ShouldBeTrue)
So(out, ShouldEqual, ts.GetIdFor("i"))
So(out, ShouldEqual, ts.ValueOf("i"))
})
Convey("It can get an internal linkage", func() {
@ -57,7 +57,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
So(it.Type(), ShouldEqual, "and")
out, ok := it.Next()
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 {
t.Error("Got no results")
}
if out != ts.GetIdFor("i") {
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
if out != ts.ValueOf("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)
it.TagResults(&tags)
if ts.GetNameFor(tags["$a"]) != "food" {
t.Errorf("Got %s, expected food", ts.GetNameFor(tags["$a"]))
if ts.NameOf(tags["$a"]) != "food" {
t.Errorf("Got %s, expected food", ts.NameOf(tags["$a"]))
}
}
@ -119,8 +119,8 @@ func TestMultipleConstraintParse(t *testing.T) {
if !ok {
t.Error("Got no results")
}
if out != ts.GetIdFor("i") {
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
if out != ts.ValueOf("i") {
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
}
_, ok = it.Next()
if ok {

View file

@ -115,7 +115,7 @@ func (s *Session) ToText(result interface{}) string {
if k == "$_" {
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
}

View file

@ -47,24 +47,24 @@ type TripleStore interface {
RemoveTriple(*Triple)
// 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
// that node token in that directional field.
GetTripleIterator(Direction, TSVal) Iterator
TripleIterator(Direction, TSVal) Iterator
// Returns an iterator enumerating all nodes in the graph.
GetNodesAllIterator() Iterator
NodesAllIterator() Iterator
// 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
// to represent that id.
GetIdFor(string) TSVal
ValueOf(string) TSVal
// Given an opaque token, return the node that it represents.
GetNameFor(TSVal) string
NameOf(TSVal) string
// Returns the number of triples currently stored.
Size() int64
@ -88,13 +88,13 @@ type TripleStore interface {
// gives the TripleStore the opportunity to make this optimization.
//
// Iterators will call this. At worst, a valid implementation is
// self.GetIdFor(self.GetTriple(triple_id).Get(dir))
GetTripleDirection(triple_id TSVal, d Direction) TSVal
// ts.IdFor(ts.Triple(triple_id).Get(dir))
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 {
switch vv := val.(type) {
case float64:
@ -106,7 +106,7 @@ func (d OptionsDict) GetIntKey(key string) (int, bool) {
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 {
switch vv := val.(type) {
case string:

View file

@ -68,14 +68,14 @@ func makeListOfStringsFromArrayValue(obj *otto.Object) []string {
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
if val.IsNull() || val.IsUndefined() {
return ts.GetNodesAllIterator()
return ts.NodesAllIterator()
}
if val.IsPrimitive() {
thing, _ := val.Export()
switch v := thing.(type) {
case string:
it := ts.FixedIterator()
it.AddValue(ts.GetIdFor(v))
it.AddValue(ts.ValueOf(v))
return it
default:
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())
it := ts.FixedIterator()
for _, x := range strings {
it.AddValue(ts.GetIdFor(x))
it.AddValue(ts.ValueOf(x))
}
return it
case "Number":
@ -101,7 +101,7 @@ func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator
case "String":
it := ts.FixedIterator()
str, _ := val.ToString()
it.AddValue(ts.GetIdFor(str))
it.AddValue(ts.ValueOf(str))
return it
default:
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()
var predicateNodeIterator graph.Iterator
if length == 0 {
predicateNodeIterator = ts.GetNodesAllIterator()
predicateNodeIterator = ts.NodesAllIterator()
} else {
zero, _ := argArray.Get("0")
predicateNodeIterator = buildIteratorFromValue(zero, ts)
@ -168,11 +168,11 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
switch kind {
case "vertex":
if len(stringArgs) == 0 {
it = ts.GetNodesAllIterator()
it = ts.NodesAllIterator()
} else {
fixed := ts.FixedIterator()
for _, name := range stringArgs {
fixed.AddValue(ts.GetIdFor(name))
fixed.AddValue(ts.ValueOf(name))
}
it = fixed
}
@ -182,7 +182,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
it.AddTag(tag)
}
case "save":
all := ts.GetNodesAllIterator()
all := ts.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
@ -192,7 +192,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
all.AddTag(stringArgs[0])
}
predFixed := ts.FixedIterator()
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
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)
it = and
case "saver":
all := ts.GetNodesAllIterator()
all := ts.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
@ -212,7 +212,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
all.AddTag(stringArgs[0])
}
predFixed := ts.FixedIterator()
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
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()
}
for _, name := range stringArgs[1:] {
fixed.AddValue(ts.GetIdFor(name))
fixed.AddValue(ts.ValueOf(name))
}
predFixed := ts.FixedIterator()
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
predFixed.AddValue(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed, graph.Object))
@ -263,7 +263,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
case "is":
fixed := ts.FixedIterator()
for _, name := range stringArgs {
fixed.AddValue(ts.GetIdFor(name))
fixed.AddValue(ts.ValueOf(name))
}
and := iterator.NewAnd()
and.AddSubIterator(fixed)

View file

@ -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 {
outputMap := make(map[string]string)
for k, v := range m {
outputMap[k] = ses.ts.GetNameFor(v)
outputMap[k] = ses.ts.NameOf(v)
}
return outputMap
}
@ -191,7 +191,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri
if !ok {
break
}
output = append(output, ses.ts.GetNameFor(val))
output = append(output, ses.ts.NameOf(val))
count++
if limit >= 0 && count >= limit {
break

View file

@ -63,7 +63,7 @@ func runQueryGetTag(query string, tag string) ([]string, int) {
if data.val == nil {
val := (*data.actualResults)[tag]
if val != nil {
output = append(output, js.ts.GetNameFor(val))
output = append(output, js.ts.NameOf(val))
}
}
}

View file

@ -202,7 +202,7 @@ func (s *Session) ToText(result interface{}) string {
if k == "$_" {
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 {
if data.val.IsObject() {
@ -234,7 +234,7 @@ func (ses *Session) BuildJson(result interface{}) {
}
sort.Strings(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)
} else {

View file

@ -27,12 +27,12 @@ import (
func (q *Query) buildFixed(s string) graph.Iterator {
f := q.ses.ts.FixedIterator()
f.AddValue(q.ses.ts.GetIdFor(s))
f.AddValue(q.ses.ts.ValueOf(s))
return f
}
func (q *Query) buildResultIterator(path Path) graph.Iterator {
all := q.ses.ts.GetNodesAllIterator()
all := q.ses.ts.NodesAllIterator()
all.AddTag(string(path))
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) {
it := iterator.NewAnd()
it.AddSubIterator(q.ses.ts.GetNodesAllIterator())
it.AddSubIterator(q.ses.ts.NodesAllIterator())
var err error
err = nil
outputStructure := make(map[string]interface{})
@ -138,7 +138,7 @@ func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path
}
subAnd := iterator.NewAnd()
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))
if reverse {
lto := iterator.NewLinksTo(q.ses.ts, builtIt, graph.Subject)

View file

@ -27,7 +27,7 @@ func (q *Query) treeifyResult(tags map[string]graph.TSVal) map[ResultPath]string
if v == nil {
continue
}
results[Path(k)] = q.ses.ts.GetNameFor(v)
results[Path(k)] = q.ses.ts.NameOf(v)
}
resultPaths := make(map[ResultPath]string)
for k, v := range results {

View file

@ -121,7 +121,7 @@ func (s *Session) ToText(result interface{}) string {
if k == "$_" {
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
}