本文整理匯總了Golang中github.com/google/cayley/graph/iterator.NewHasA函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewHasA函數的具體用法?Golang NewHasA怎麽用?Golang NewHasA使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewHasA函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemoveQuad
func TestRemoveQuad(t *testing.T) {
qs, w, _ := makeTestStore(simpleGraph)
err := w.RemoveQuad(quad.Make(
"E",
"follows",
"F",
"",
))
if err != nil {
t.Error("Couldn't remove quad", err)
}
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf(quad.Raw("E")))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf(quad.Raw("follows")))
innerAnd := iterator.NewAnd(qs)
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed, quad.Subject))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
hasa := iterator.NewHasA(qs, innerAnd, quad.Object)
newIt, _ := hasa.Optimize()
if graph.Next(newIt) {
t.Error("E should not have any followers.")
}
}
示例2: TestRemoveQuad
func TestRemoveQuad(t *testing.T) {
qs, w, _ := makeTestStore(simpleGraph)
w.RemoveQuad(quad.Quad{
Subject: "E",
Predicate: "follows",
Object: "F",
Label: "",
})
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf("E"))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf("follows"))
innerAnd := iterator.NewAnd()
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed, quad.Subject))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
hasa := iterator.NewHasA(qs, innerAnd, quad.Object)
newIt, _ := hasa.Optimize()
if graph.Next(newIt) {
t.Error("E should not have any followers.")
}
}
示例3: hasMorphism
func hasMorphism(via interface{}, nodes ...string) morphism {
return morphism{
Name: "has",
Reversal: func() morphism { return hasMorphism(via, nodes...) },
Apply: func(qs graph.QuadStore, it graph.Iterator) graph.Iterator {
var sub graph.Iterator
if len(nodes) == 0 {
sub = qs.NodesAllIterator()
} else {
fixed := qs.FixedIterator()
for _, n := range nodes {
fixed.Add(qs.ValueOf(n))
}
sub = fixed
}
var viaPath *Path
if via != nil {
viaPath = buildViaPath(qs, via)
} else {
viaPath = buildViaPath(qs)
}
subAnd := iterator.NewAnd(qs)
subAnd.AddSubIterator(iterator.NewLinksTo(qs, sub, quad.Object))
subAnd.AddSubIterator(iterator.NewLinksTo(qs, viaPath.BuildIterator(), quad.Predicate))
hasa := iterator.NewHasA(qs, subAnd, quad.Subject)
and := iterator.NewAnd(qs)
and.AddSubIterator(it)
and.AddSubIterator(hasa)
return and
},
}
}
示例4: buildSave
func buildSave(
qs graph.QuadStore, via interface{},
tag string, from graph.Iterator, reverse bool, optional bool,
) graph.Iterator {
allNodes := qs.NodesAllIterator()
allNodes.Tagger().Add(tag)
start, goal := quad.Subject, quad.Object
if reverse {
start, goal = goal, start
}
viaIter := buildViaPath(qs, via).
BuildIterator()
dest := iterator.NewLinksTo(qs, allNodes, goal)
trail := iterator.NewLinksTo(qs, viaIter, quad.Predicate)
route := join(qs, trail, dest)
save := graph.Iterator(iterator.NewHasA(qs, route, start))
if optional {
save = iterator.NewOptional(save)
}
return join(qs, from, save)
}
示例5: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t *testing.T) {
glog.Info("\n-----------\n")
inst, opts, err := createInstance()
defer inst.Close()
if err != nil {
t.Fatalf("failed to create instance: %v", err)
}
qs, _, _ := makeTestStore(simpleGraph, opts)
if qs.Size() != 11 {
t.Fatal("Incorrect number of quads")
}
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf("C"))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf("follows"))
all := qs.NodesAllIterator()
innerAnd := iterator.NewAnd(qs)
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Object))
hasa := iterator.NewHasA(qs, innerAnd, quad.Subject)
outerAnd := iterator.NewAnd(qs)
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
if !outerAnd.Next() {
t.Error("Expected one matching subtree")
}
val := outerAnd.Result()
if qs.NameOf(val) != "C" {
t.Errorf("Matching subtree should be %s, got %s", "barak", qs.NameOf(val))
}
var (
got []string
expect = []string{"B", "D"}
)
for {
got = append(got, qs.NameOf(all.Result()))
if !outerAnd.NextPath() {
break
}
}
sort.Strings(got)
if !reflect.DeepEqual(got, expect) {
t.Errorf("Unexpected result, got:%q expect:%q", got, expect)
}
if outerAnd.Next() {
t.Error("More than one possible top level output?")
}
}
示例6: buildInOutPredicateIterator
func buildInOutPredicateIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterator, isReverse bool) graph.Iterator {
dir := quad.Subject
if isReverse {
dir = quad.Object
}
lto := iterator.NewLinksTo(qs, base, dir)
hasa := iterator.NewHasA(qs, lto, quad.Predicate)
return iterator.NewUnique(hasa)
}
示例7: inOutIterator
func inOutIterator(viaPath *Path, it graph.Iterator, reverse bool) graph.Iterator {
in, out := quad.Subject, quad.Object
if reverse {
in, out = out, in
}
lto := iterator.NewLinksTo(viaPath.qs, it, in)
and := iterator.NewAnd(viaPath.qs)
and.AddSubIterator(iterator.NewLinksTo(viaPath.qs, viaPath.BuildIterator(), quad.Predicate))
and.AddSubIterator(lto)
return iterator.NewHasA(viaPath.qs, and, out)
}
示例8: hasMorphism
// hasMorphism is the set of nodes that is reachable via either a *Path, a
// single node.(string) or a list of nodes.([]string).
func hasMorphism(via interface{}, nodes ...string) morphism {
return morphism{
Name: "has",
Reversal: func(ctx *context) (morphism, *context) { return hasMorphism(via, nodes...), ctx },
Apply: func(qs graph.QuadStore, in graph.Iterator, ctx *context) (graph.Iterator, *context) {
viaIter := buildViaPath(qs, via).
BuildIterator()
ends := func() graph.Iterator {
if len(nodes) == 0 {
return qs.NodesAllIterator()
}
fixed := qs.FixedIterator()
for _, n := range nodes {
fixed.Add(qs.ValueOf(n))
}
return fixed
}()
trail := iterator.NewLinksTo(qs, viaIter, quad.Predicate)
dest := iterator.NewLinksTo(qs, ends, quad.Object)
// If we were given nodes, intersecting with them first will
// be extremely cheap-- otherwise, it will be the most expensive
// (requiring iteration over all nodes). We have enough info to
// make this optimization now since intersections are commutative
if len(nodes) == 0 { // Where dest involves an All iterator.
route := join(qs, trail, dest)
has := iterator.NewHasA(qs, route, quad.Subject)
return join(qs, in, has), ctx
}
// This looks backwards. That's OK-- see the note above.
route := join(qs, dest, trail)
has := iterator.NewHasA(qs, route, quad.Subject)
return join(qs, has, in), ctx
},
}
}
示例9: buildHas
func buildHas(qs graph.QuadStore, via interface{}, in graph.Iterator, reverse bool, nodes []quad.Value) graph.Iterator {
viaIter := buildViaPath(qs, via).
BuildIterator()
ends := func() graph.Iterator {
if len(nodes) == 0 {
return qs.NodesAllIterator()
}
fixed := qs.FixedIterator()
for _, n := range nodes {
fixed.Add(qs.ValueOf(n))
}
return fixed
}()
start, goal := quad.Subject, quad.Object
if reverse {
start, goal = goal, start
}
trail := iterator.NewLinksTo(qs, viaIter, quad.Predicate)
dest := iterator.NewLinksTo(qs, ends, goal)
// If we were given nodes, intersecting with them first will
// be extremely cheap-- otherwise, it will be the most expensive
// (requiring iteration over all nodes). We have enough info to
// make this optimization now since intersections are commutative
if len(nodes) == 0 { // Where dest involves an All iterator.
route := join(qs, trail, dest)
has := iterator.NewHasA(qs, route, start)
return join(qs, in, has)
}
// This looks backwards. That's OK-- see the note above.
route := join(qs, dest, trail)
has := iterator.NewHasA(qs, route, start)
return join(qs, has, in)
}
示例10: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t *testing.T) {
ts, _ := makeTestStore(simpleGraph)
fixed := ts.FixedIterator()
fixed.Add(ts.ValueOf("C"))
fixed2 := ts.FixedIterator()
fixed2.Add(ts.ValueOf("follows"))
all := ts.NodesAllIterator()
innerAnd := iterator.NewAnd()
innerAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed2, graph.Predicate))
innerAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Object))
hasa := iterator.NewHasA(ts, innerAnd, graph.Subject)
outerAnd := iterator.NewAnd()
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
val, ok := outerAnd.Next()
if !ok {
t.Error("Expected one matching subtree")
}
if ts.NameOf(val) != "C" {
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.NameOf(val))
}
var (
got []string
expect = []string{"B", "D"}
)
for {
got = append(got, ts.NameOf(all.Result()))
if !outerAnd.NextResult() {
break
}
}
sort.Strings(got)
if !reflect.DeepEqual(got, expect) {
t.Errorf("Unexpected result, got:%q expect:%q", got, expect)
}
val, ok = outerAnd.Next()
if ok {
t.Error("More than one possible top level output?")
}
}
示例11: inOutIterator
func inOutIterator(viaPath *Path, from graph.Iterator, inIterator bool) graph.Iterator {
start, goal := quad.Subject, quad.Object
if inIterator {
start, goal = goal, start
}
viaIter := viaPath.BuildIterator()
source := iterator.NewLinksTo(viaPath.qs, from, start)
trail := iterator.NewLinksTo(viaPath.qs, viaIter, quad.Predicate)
route := join(viaPath.qs, source, trail)
return iterator.NewHasA(viaPath.qs, route, goal)
}
示例12: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t testing.TB, gen DatabaseFunc) {
qs, opts, closer := gen(t)
defer closer()
MakeWriter(t, qs, opts, MakeQuadSet()...)
require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf(quad.Raw("C")))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf(quad.Raw("follows")))
all := qs.NodesAllIterator()
innerAnd := iterator.NewAnd(qs)
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Object))
hasa := iterator.NewHasA(qs, innerAnd, quad.Subject)
outerAnd := iterator.NewAnd(qs)
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
require.True(t, outerAnd.Next(), "Expected one matching subtree")
val := outerAnd.Result()
require.Equal(t, quad.Raw("C"), qs.NameOf(val))
var (
got []string
expect = []string{"B", "D"}
)
for {
got = append(got, qs.NameOf(all.Result()).String())
if !outerAnd.NextPath() {
break
}
}
sort.Strings(got)
require.Equal(t, expect, got)
require.True(t, !outerAnd.Next(), "More than one possible top level output?")
}
示例13: inOutIterator
func inOutIterator(viaPath *Path, from graph.Iterator, inIterator bool, tags []string) graph.Iterator {
start, goal := quad.Subject, quad.Object
if inIterator {
start, goal = goal, start
}
viaIter := viaPath.BuildIterator()
for _, tag := range tags {
viaIter.Tagger().Add(tag)
}
source := iterator.NewLinksTo(viaPath.qs, from, start)
trail := iterator.NewLinksTo(viaPath.qs, viaIter, quad.Predicate)
route := join(viaPath.qs, source, trail)
return iterator.NewHasA(viaPath.qs, route, goal)
}
示例14: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t *testing.T) {
ts := MakeTestingMemstore()
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("C"))
all := ts.GetNodesAllIterator()
lto := iterator.NewLinksTo(ts, all, graph.Object)
innerAnd := iterator.NewAnd()
fixed2 := ts.FixedIterator()
fixed2.AddValue(ts.GetIdFor("follows"))
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
innerAnd.AddSubIterator(lto2)
innerAnd.AddSubIterator(lto)
hasa := iterator.NewHasA(ts, innerAnd, graph.Subject)
outerAnd := iterator.NewAnd()
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
val, ok := outerAnd.Next()
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))
}
expected := make([]string, 2)
expected[0] = "B"
expected[1] = "D"
actualOut := make([]string, 2)
actualOut[0] = ts.GetNameFor(all.LastResult())
nresultOk := outerAnd.NextResult()
if !nresultOk {
t.Error("Expected two results got one")
}
actualOut[1] = ts.GetNameFor(all.LastResult())
nresultOk = outerAnd.NextResult()
if nresultOk {
t.Error("Expected two results got three")
}
CompareStringSlices(t, expected, actualOut)
val, ok = outerAnd.Next()
if ok {
t.Error("More than one possible top level output?")
}
}
示例15: TestRemoveTriple
func TestRemoveTriple(t *testing.T) {
ts := MakeTestingMemstore()
ts.RemoveTriple(&graph.Triple{"E", "follows", "F", ""})
fixed := ts.FixedIterator()
fixed.AddValue(ts.GetIdFor("E"))
lto := iterator.NewLinksTo(ts, fixed, graph.Subject)
fixed2 := ts.FixedIterator()
fixed2.AddValue(ts.GetIdFor("follows"))
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
innerAnd := iterator.NewAnd()
innerAnd.AddSubIterator(lto2)
innerAnd.AddSubIterator(lto)
hasa := iterator.NewHasA(ts, innerAnd, graph.Object)
newIt, _ := hasa.Optimize()
_, ok := newIt.Next()
if ok {
t.Error("E should not have any followers.")
}
}