示例#1
0
func TestMultipleConstraintParse(t *testing.T) {
	ts := memstore.NewTripleStore()
	for _, tv := range []*graph.Triple{
		{"i", "like", "food", ""},
		{"i", "like", "beer", ""},
		{"you", "like", "beer", ""},
	} {
		ts.AddTriple(tv)
	}
	query := `(
		$a
		(:like :beer)
		(:like "food")
	)`
	it := BuildIteratorTreeForQuery(ts, query)
	if it.Type() != graph.And {
		t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
	}
	out, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
	}
	_, ok = it.Next()
	if ok {
		t.Error("Too many results")
	}
}
示例#2
0
func makeTestSession(data []*graph.Triple) *Session {
	ts := memstore.NewTripleStore()
	for _, t := range data {
		ts.AddTriple(t)
	}
	return NewSession(ts, -1, false)
}
示例#3
0
func TestParseSexpWithMemstore(t *testing.T) {
	Convey("With a Memstore", t, func() {
		ts := memstore.NewTripleStore()

		Convey("It should parse an empty query", func() {
			it := BuildIteratorTreeForQuery(ts, "()")
			So(it.Type(), ShouldEqual, "null")
		})

		Convey("It should get a single triple linkage", func() {
			ts.AddTriple(&graph.Triple{"i", "can", "win", ""})
			query := "($a (:can \"win\"))"
			So(len(query), ShouldEqual, 17)
			it := BuildIteratorTreeForQuery(ts, query)
			So(it.Type(), ShouldEqual, "and")
			out, ok := it.Next()
			So(ok, ShouldBeTrue)
			So(out, ShouldEqual, ts.GetIdFor("i"))
		})

		Convey("It can get an internal linkage", func() {
			ts.AddTriple(&graph.Triple{"i", "can", "win", ""})
			query := "(\"i\" (:can $a))"
			it := BuildIteratorTreeForQuery(ts, query)
			So(it.Type(), ShouldEqual, "and")
			out, ok := it.Next()
			So(ok, ShouldBeTrue)
			So(out, ShouldEqual, ts.GetIdFor("i"))
		})

	})
}
示例#4
0
文件: appengine.go 项目: R-007/cayley
func init() {
	glog.SetToStderr(true)
	cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
	ts := memstore.NewTripleStore()
	glog.Errorln(cfg)
	LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
	http.SetupRoutes(ts, cfg)
}
示例#5
0
文件: open.go 项目: heshizhu/cayley
func Open(cfg *config.Config) graph.TripleStore {
	glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
	switch cfg.DatabaseType {
	case "mongo", "mongodb":
		return mongo.NewTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
	case "leveldb":
		return leveldb.NewTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
	case "mem":
		ts := memstore.NewTripleStore()
		Load(ts, cfg, cfg.DatabasePath, true)
		return ts
	}
	panic("Unsupported database backend " + cfg.DatabaseType)
}
示例#6
0
func TestTreeConstraintTagParse(t *testing.T) {
	ts := memstore.NewTripleStore()
	ts.AddTriple(&graph.Triple{"i", "like", "food", ""})
	ts.AddTriple(&graph.Triple{"food", "is", "good", ""})
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(ts, query)
	_, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	tags := make(map[string]graph.Value)
	it.TagResults(tags)
	if ts.NameOf(tags["$a"]) != "food" {
		t.Errorf("Got %s, expected food", ts.NameOf(tags["$a"]))
	}

}
示例#7
0
func TestTreeConstraintParse(t *testing.T) {
	ts := memstore.NewTripleStore()
	ts.AddTriple(&graph.Triple{"i", "like", "food", ""})
	ts.AddTriple(&graph.Triple{"food", "is", "good", ""})
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(ts, query)
	if it.Type() != graph.And {
		t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
	}
	out, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
	}
}
示例#8
0
func TestMemstoreBackedSexp(t *testing.T) {
	ts := memstore.NewTripleStore()
	it := BuildIteratorTreeForQuery(ts, "()")
	if it.Type() != graph.Null {
		t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
	}
	for _, test := range testQueries {
		if test.add != nil {
			ts.AddTriple(test.add)
		}
		it := BuildIteratorTreeForQuery(ts, test.query)
		if it.Type() != test.typ {
			t.Errorf("Incorrect type for %s, got:%q expect %q", test.message, it.Type(), test.expect)
		}
		got, ok := it.Next()
		if !ok {
			t.Errorf("Failed to %s", test.message)
		}
		if expect := ts.ValueOf(test.expect); got != expect {
			t.Errorf("Incorrect result for %s, got:%v expect %v", test.message, got, expect)
		}
	}
}
示例#9
0
func TestMultipleConstraintParse(t *testing.T) {
	ts := memstore.NewTripleStore()
	ts.AddTriple(&graph.Triple{"i", "like", "food", ""})
	ts.AddTriple(&graph.Triple{"i", "like", "beer", ""})
	ts.AddTriple(&graph.Triple{"you", "like", "beer", ""})
	query := "($a \n" +
		"(:like :beer)\n" +
		"(:like \"food\"))"
	it := BuildIteratorTreeForQuery(ts, query)
	if it.Type() != "and" {
		t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
	}
	out, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.GetIdFor("i") {
		t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
	}
	_, ok = it.Next()
	if ok {
		t.Error("Too many results")
	}
}