Rename triple entities were relevant
This commit is contained in:
parent
ddf8849e60
commit
443a091b72
62 changed files with 664 additions and 664 deletions
|
|
@ -22,9 +22,9 @@ import (
|
|||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
func BuildIteratorTreeForQuery(ts graph.TripleStore, query string) graph.Iterator {
|
||||
func BuildIteratorTreeForQuery(qs graph.QuadStore, query string) graph.Iterator {
|
||||
tree := parseQuery(query)
|
||||
return buildIteratorTree(tree, ts)
|
||||
return buildIteratorTree(tree, qs)
|
||||
}
|
||||
|
||||
func ParseString(input string) string {
|
||||
|
|
@ -181,15 +181,15 @@ func getIdentString(tree *peg.ExpressionTree) string {
|
|||
return out
|
||||
}
|
||||
|
||||
func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Iterator {
|
||||
func buildIteratorTree(tree *peg.ExpressionTree, qs graph.QuadStore) graph.Iterator {
|
||||
switch tree.Name {
|
||||
case "Start":
|
||||
return buildIteratorTree(tree.Children[0], ts)
|
||||
return buildIteratorTree(tree.Children[0], qs)
|
||||
case "NodeIdentifier":
|
||||
var out graph.Iterator
|
||||
nodeID := getIdentString(tree)
|
||||
if tree.Children[0].Name == "Variable" {
|
||||
allIt := ts.NodesAllIterator()
|
||||
allIt := qs.NodesAllIterator()
|
||||
allIt.Tagger().Add(nodeID)
|
||||
out = allIt
|
||||
} else {
|
||||
|
|
@ -197,8 +197,8 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
if tree.Children[0].Children[0].Name == "ColonIdentifier" {
|
||||
n = nodeID[1:]
|
||||
}
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.Add(ts.ValueOf(n))
|
||||
fixed := qs.FixedIterator()
|
||||
fixed.Add(qs.ValueOf(n))
|
||||
out = fixed
|
||||
}
|
||||
return out
|
||||
|
|
@ -208,8 +208,8 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
//Taken care of below
|
||||
i++
|
||||
}
|
||||
it := buildIteratorTree(tree.Children[i], ts)
|
||||
lto := iterator.NewLinksTo(ts, it, quad.Predicate)
|
||||
it := buildIteratorTree(tree.Children[i], qs)
|
||||
lto := iterator.NewLinksTo(qs, it, quad.Predicate)
|
||||
return lto
|
||||
case "RootConstraint":
|
||||
constraintCount := 0
|
||||
|
|
@ -219,7 +219,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
case "NodeIdentifier":
|
||||
fallthrough
|
||||
case "Constraint":
|
||||
it := buildIteratorTree(c, ts)
|
||||
it := buildIteratorTree(c, qs)
|
||||
and.AddSubIterator(it)
|
||||
constraintCount++
|
||||
continue
|
||||
|
|
@ -241,7 +241,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
topLevelDir = quad.Object
|
||||
subItDir = quad.Subject
|
||||
}
|
||||
it := buildIteratorTree(c, ts)
|
||||
it := buildIteratorTree(c, qs)
|
||||
subAnd.AddSubIterator(it)
|
||||
continue
|
||||
case "PredicateKeyword":
|
||||
|
|
@ -252,15 +252,15 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
case "NodeIdentifier":
|
||||
fallthrough
|
||||
case "RootConstraint":
|
||||
it := buildIteratorTree(c, ts)
|
||||
l := iterator.NewLinksTo(ts, it, subItDir)
|
||||
it := buildIteratorTree(c, qs)
|
||||
l := iterator.NewLinksTo(qs, it, subItDir)
|
||||
subAnd.AddSubIterator(l)
|
||||
continue
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
hasa = iterator.NewHasA(ts, subAnd, topLevelDir)
|
||||
hasa = iterator.NewHasA(qs, subAnd, topLevelDir)
|
||||
if isOptional {
|
||||
optional := iterator.NewOptional(hasa)
|
||||
return optional
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ var testQueries = []struct {
|
|||
expect string
|
||||
}{
|
||||
{
|
||||
message: "get a single triple linkage",
|
||||
message: "get a single quad linkage",
|
||||
add: quad.Quad{"i", "can", "win", ""},
|
||||
query: "($a (:can \"win\"))",
|
||||
typ: graph.And,
|
||||
expect: "i",
|
||||
},
|
||||
{
|
||||
message: "get a single triple linkage",
|
||||
message: "get a single quad linkage",
|
||||
add: quad.Quad{"i", "can", "win", ""},
|
||||
query: "(\"i\" (:can $a))",
|
||||
typ: graph.And,
|
||||
|
|
@ -55,9 +55,9 @@ var testQueries = []struct {
|
|||
}
|
||||
|
||||
func TestMemstoreBackedSexp(t *testing.T) {
|
||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", ts, nil)
|
||||
it := BuildIteratorTreeForQuery(ts, "()")
|
||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", qs, nil)
|
||||
it := BuildIteratorTreeForQuery(qs, "()")
|
||||
if it.Type() != graph.Null {
|
||||
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ func TestMemstoreBackedSexp(t *testing.T) {
|
|||
if test.add.IsValid() {
|
||||
w.AddQuad(test.add)
|
||||
}
|
||||
it := BuildIteratorTreeForQuery(ts, test.query)
|
||||
it := BuildIteratorTreeForQuery(qs, test.query)
|
||||
if it.Type() != test.typ {
|
||||
t.Errorf("Incorrect type for %s, got:%q expect %q", test.message, it.Type(), test.expect)
|
||||
}
|
||||
|
|
@ -73,21 +73,21 @@ func TestMemstoreBackedSexp(t *testing.T) {
|
|||
t.Errorf("Failed to %s", test.message)
|
||||
}
|
||||
got := it.Result()
|
||||
if expect := ts.ValueOf(test.expect); got != expect {
|
||||
if expect := qs.ValueOf(test.expect); got != expect {
|
||||
t.Errorf("Incorrect result for %s, got:%v expect %v", test.message, got, expect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeConstraintParse(t *testing.T) {
|
||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", ts, nil)
|
||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", qs, nil)
|
||||
w.AddQuad(quad.Quad{"i", "like", "food", ""})
|
||||
w.AddQuad(quad.Quad{"food", "is", "good", ""})
|
||||
query := "(\"i\"\n" +
|
||||
"(:like\n" +
|
||||
"($a (:is :good))))"
|
||||
it := BuildIteratorTreeForQuery(ts, query)
|
||||
it := BuildIteratorTreeForQuery(qs, query)
|
||||
if it.Type() != graph.And {
|
||||
t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
|
||||
}
|
||||
|
|
@ -95,34 +95,34 @@ func TestTreeConstraintParse(t *testing.T) {
|
|||
t.Error("Got no results")
|
||||
}
|
||||
out := it.Result()
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
if out != qs.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, qs.ValueOf("i"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeConstraintTagParse(t *testing.T) {
|
||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", ts, nil)
|
||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", qs, nil)
|
||||
w.AddQuad(quad.Quad{"i", "like", "food", ""})
|
||||
w.AddQuad(quad.Quad{"food", "is", "good", ""})
|
||||
query := "(\"i\"\n" +
|
||||
"(:like\n" +
|
||||
"($a (:is :good))))"
|
||||
it := BuildIteratorTreeForQuery(ts, query)
|
||||
it := BuildIteratorTreeForQuery(qs, query)
|
||||
if !graph.Next(it) {
|
||||
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"]))
|
||||
if qs.NameOf(tags["$a"]) != "food" {
|
||||
t.Errorf("Got %s, expected food", qs.NameOf(tags["$a"]))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMultipleConstraintParse(t *testing.T) {
|
||||
ts, _ := graph.NewTripleStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", ts, nil)
|
||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||
w, _ := graph.NewQuadWriter("single", qs, nil)
|
||||
for _, tv := range []quad.Quad{
|
||||
{"i", "like", "food", ""},
|
||||
{"i", "like", "beer", ""},
|
||||
|
|
@ -135,7 +135,7 @@ func TestMultipleConstraintParse(t *testing.T) {
|
|||
(:like :beer)
|
||||
(:like "food")
|
||||
)`
|
||||
it := BuildIteratorTreeForQuery(ts, query)
|
||||
it := BuildIteratorTreeForQuery(qs, query)
|
||||
if it.Type() != graph.And {
|
||||
t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
|
||||
}
|
||||
|
|
@ -143,8 +143,8 @@ func TestMultipleConstraintParse(t *testing.T) {
|
|||
t.Error("Got no results")
|
||||
}
|
||||
out := it.Result()
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
if out != qs.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, qs.ValueOf("i"))
|
||||
}
|
||||
if graph.Next(it) {
|
||||
t.Error("Too many results")
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ import (
|
|||
)
|
||||
|
||||
type Session struct {
|
||||
ts graph.TripleStore
|
||||
qs graph.QuadStore
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewSession(inputTripleStore graph.TripleStore) *Session {
|
||||
func NewSession(qs graph.QuadStore) *Session {
|
||||
var s Session
|
||||
s.ts = inputTripleStore
|
||||
s.qs = qs
|
||||
return &s
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
|
|||
}
|
||||
|
||||
func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||
it := BuildIteratorTreeForQuery(s.ts, input)
|
||||
it := BuildIteratorTreeForQuery(s.qs, input)
|
||||
newIt, changed := it.Optimize()
|
||||
if changed {
|
||||
it = newIt
|
||||
|
|
@ -112,7 +112,7 @@ func (s *Session) ToText(result interface{}) string {
|
|||
if k == "$_" {
|
||||
continue
|
||||
}
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf(tags[k]))
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.qs.NameOf(tags[k]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue