Пример #1
0
func makeTestSession(data []*quad.Quad) *Session {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	for _, t := range data {
		ts.AddTriple(t)
	}
	return NewSession(ts, -1, false)
}
Пример #2
0
func TestMultipleConstraintParse(t *testing.T) {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	for _, tv := range []*quad.Quad{
		{"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 := graph.Next(it)
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
	}
	_, ok = graph.Next(it)
	if ok {
		t.Error("Too many results")
	}
}
Пример #3
0
func makeTestSession(data []*graph.Triple) *Session {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	for _, t := range data {
		ts.AddTriple(t)
	}
	return NewSession(ts)
}
Пример #4
0
func makeTestSession(data []quad.Quad) *Session {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", ts, nil)
	for _, t := range data {
		w.AddQuad(t)
	}
	return NewSession(ts, -1, false)
}
Пример #5
0
func init() {
	glog.SetToStderr(true)
	cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	glog.Errorln(cfg)
	db.Load(ts, cfg, cfg.DatabasePath)
	http.SetupRoutes(ts, cfg)
}
Пример #6
0
func Open(cfg *config.Config) (graph.TripleStore, error) {
	glog.Infof("Opening database %q at %s", cfg.DatabaseType, cfg.DatabasePath)
	ts, err := graph.NewTripleStore(cfg.DatabaseType, cfg.DatabasePath, cfg.DatabaseOptions)
	if err != nil {
		return nil, err
	}

	return ts, nil
}
Пример #7
0
func Open(cfg *config.Config) (graph.TripleStore, error) {
	glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
	ts, err := graph.NewTripleStore(cfg.DatabaseType, cfg.DatabasePath, cfg.DatabaseOptions)
	if err != nil {
		return nil, err
	}

	// Memstore is not persistent, so it MUST be loaded.
	if cfg.DatabaseType == "memstore" {
		err = Load(ts, cfg, cfg.DatabasePath)
		if err != nil {
			return nil, err
		}
	}

	return ts, nil
}
Пример #8
0
func TestTreeConstraintTagParse(t *testing.T) {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	ts.AddTriple(&quad.Quad{"i", "like", "food", ""})
	ts.AddTriple(&quad.Quad{"food", "is", "good", ""})
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(ts, query)
	_, ok := graph.Next(it)
	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"]))
	}

}
Пример #9
0
func TestTreeConstraintParse(t *testing.T) {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	ts.AddTriple(&quad.Quad{"i", "like", "food", ""})
	ts.AddTriple(&quad.Quad{"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 := graph.Next(it)
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
	}
}
Пример #10
0
func TestMemstoreBackedSexp(t *testing.T) {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	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 := graph.Next(it)
		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)
		}
	}
}