本文整理汇总了Golang中github.com/google/cayley/graph/iterator.NewAnd函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAnd函数的具体用法?Golang NewAnd怎么用?Golang NewAnd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAnd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
},
}
}
开发者ID:oliverp19,项目名称:cayley,代码行数:32,代码来源:morphism_apply_functions.go
示例2: 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?")
}
}
开发者ID:e4x,项目名称:cayley,代码行数:58,代码来源:quadstore_test.go
示例3: 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?")
}
}
开发者ID:horryq,项目名称:cayley,代码行数:49,代码来源:triplestore_test.go
示例4: optimizeAndIterator
func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool) {
// Fail fast if nothing can happen
glog.V(4).Infoln("Entering optimizeAndIterator", it.UID())
found := false
for _, it := range it.SubIterators() {
glog.V(4).Infoln(it.Type())
if it.Type() == mongoType {
found = true
}
}
if !found {
glog.V(4).Infoln("Aborting optimizeAndIterator")
return it, false
}
newAnd := iterator.NewAnd(qs)
var mongoIt *Iterator
for _, it := range it.SubIterators() {
switch it.Type() {
case mongoType:
if mongoIt == nil {
mongoIt = it.(*Iterator)
} else {
newAnd.AddSubIterator(it)
}
case graph.LinksTo:
continue
default:
newAnd.AddSubIterator(it)
}
}
stats := mongoIt.Stats()
lset := []graph.Linkage{
{
Dir: mongoIt.dir,
Value: mongoIt.hash,
},
}
n := 0
for _, it := range it.SubIterators() {
if it.Type() == graph.LinksTo {
lto := it.(*iterator.LinksTo)
// Is it more effective to do the replacement, or let the mongo check the linksto?
ltostats := lto.Stats()
if (ltostats.ContainsCost+stats.NextCost)*stats.Size > (ltostats.NextCost+stats.ContainsCost)*ltostats.Size {
continue
}
newLto := NewLinksTo(qs, lto.SubIterators()[0], "quads", lto.Direction(), lset)
newAnd.AddSubIterator(newLto)
n++
}
}
if n == 0 {
return it, false
}
return newAnd.Optimize()
}
开发者ID:dennwc,项目名称:cayley,代码行数:60,代码来源:quadstore_iterator_optimize.go
示例5: 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.")
}
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:27,代码来源:quadstore_test.go
示例6: join
// join puts two iterators together by intersecting their result sets with an AND
// Since we're using an and iterator, it's a good idea to put the smallest result
// set first so that Next() produces fewer values to check Contains().
func join(qs graph.QuadStore, itL, itR graph.Iterator) graph.Iterator {
and := iterator.NewAnd(qs)
and.AddSubIterator(itL)
and.AddSubIterator(itR)
return and
}
开发者ID:dwdm,项目名称:clair,代码行数:10,代码来源:morphism_apply_functions.go
示例7: 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.")
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:31,代码来源:quadstore_test.go
示例8: 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?")
}
开发者ID:dennwc,项目名称:cayley,代码行数:46,代码来源:graphtest.go
示例9: 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?")
}
}
开发者ID:heshizhu,项目名称:cayley,代码行数:44,代码来源:triplestore_test.go
示例10: join
// join puts two iterators together by intersecting their result sets with an AND
// Since we're using an and iterator, it's a good idea to put the smallest result
// set first so that Next() produces fewer values to check Contains().
func join(qs graph.QuadStore, its ...graph.Iterator) graph.Iterator {
and := iterator.NewAnd(qs)
for _, it := range its {
if it == nil {
continue
}
and.AddSubIterator(it)
}
return and
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:13,代码来源:morphism_apply_functions.go
示例11: 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)
}
开发者ID:oliverp19,项目名称:cayley,代码行数:11,代码来源:morphism_apply_functions.go
示例12: iteratorMorphism
func iteratorMorphism(it graph.Iterator) morphism {
return morphism{
Name: "iterator",
Reversal: func() morphism { return iteratorMorphism(it) },
Apply: func(qs graph.QuadStore, subIt graph.Iterator) graph.Iterator {
and := iterator.NewAnd(qs)
and.AddSubIterator(it)
and.AddSubIterator(subIt)
return and
},
}
}
开发者ID:oliverp19,项目名称:cayley,代码行数:12,代码来源:morphism_apply_functions.go
示例13: andMorphism
func andMorphism(p *Path) morphism {
return morphism{
Name: "and",
Reversal: func() morphism { return andMorphism(p) },
Apply: func(qs graph.QuadStore, it graph.Iterator) graph.Iterator {
subIt := p.BuildIteratorOn(qs)
and := iterator.NewAnd(qs)
and.AddSubIterator(it)
and.AddSubIterator(subIt)
return and
},
}
}
开发者ID:oliverp19,项目名称:cayley,代码行数:13,代码来源:morphism_apply_functions.go
示例14: TestAndIterator
func TestAndIterator(t *testing.T) {
all1 := iterator.NewInt64(1, 3)
all2 := iterator.NewInt64(3, 5)
and := iterator.NewAnd()
and.AddSubIterator(all1)
and.AddSubIterator(all2)
result := StringResultTreeEvaluator(and)
expected := "(3 (3) (3))\n"
if expected != result {
t.Errorf("Expected %q got %q", expected, result)
}
}
开发者ID:JesseLivingston,项目名称:cayley,代码行数:13,代码来源:result_tree_evaluator_test.go
示例15: exceptMorphism
func exceptMorphism(p *Path) morphism {
return morphism{
Name: "except",
Reversal: func() morphism { return exceptMorphism(p) },
Apply: func(qs graph.QuadStore, base graph.Iterator) graph.Iterator {
subIt := p.BuildIteratorOn(qs)
notIt := iterator.NewNot(subIt, qs.NodesAllIterator())
and := iterator.NewAnd(qs)
and.AddSubIterator(base)
and.AddSubIterator(notIt)
return and
},
}
}
开发者ID:oliverp19,项目名称:cayley,代码行数:14,代码来源:morphism_apply_functions.go
示例16: buildSave
func buildSave(qs graph.QuadStore, via interface{}, tag string, it graph.Iterator, reverse bool) graph.Iterator {
all := qs.NodesAllIterator()
all.Tagger().Add(tag)
node, allDir := quad.Subject, quad.Object
var viaPath *Path
if via != nil {
viaPath = buildViaPath(qs, via)
} else {
viaPath = buildViaPath(qs)
}
if reverse {
node, allDir = allDir, node
}
lto := iterator.NewLinksTo(qs, all, allDir)
subAnd := iterator.NewAnd(qs)
subAnd.AddSubIterator(iterator.NewLinksTo(qs, viaPath.BuildIterator(), quad.Predicate))
subAnd.AddSubIterator(lto)
hasa := iterator.NewHasA(qs, subAnd, node)
and := iterator.NewAnd(qs)
and.AddSubIterator(hasa)
and.AddSubIterator(it)
return and
}
开发者ID:oliverp19,项目名称:cayley,代码行数:23,代码来源:morphism_apply_functions.go
示例17: 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.")
}
}
开发者ID:heshizhu,项目名称:cayley,代码行数:19,代码来源:triplestore_test.go
示例18: buildInOutIterator
func buildInOutIterator(obj *otto.Object, ts graph.TripleStore, base graph.Iterator, isReverse bool) graph.Iterator {
argList, _ := obj.Get("_gremlin_values")
if argList.Class() != "GoArray" {
glog.Errorln("How is arglist not an array? Return nothing.", argList.Class())
return iterator.NewNull()
}
argArray := argList.Object()
lengthVal, _ := argArray.Get("length")
length, _ := lengthVal.ToInteger()
var predicateNodeIterator graph.Iterator
if length == 0 {
predicateNodeIterator = ts.NodesAllIterator()
} else {
zero, _ := argArray.Get("0")
predicateNodeIterator = buildIteratorFromValue(zero, ts)
}
if length >= 2 {
var tags []string
one, _ := argArray.Get("1")
if one.IsString() {
s, _ := one.ToString()
tags = append(tags, s)
} else if one.Class() == "Array" {
tags = makeListOfStringsFromArrayValue(one.Object())
}
for _, tag := range tags {
predicateNodeIterator.Tagger().Add(tag)
}
}
in, out := quad.Subject, quad.Object
if isReverse {
in, out = out, in
}
lto := iterator.NewLinksTo(ts, base, in)
and := iterator.NewAnd()
and.AddSubIterator(iterator.NewLinksTo(ts, predicateNodeIterator, quad.Predicate))
and.AddSubIterator(lto)
return iterator.NewHasA(ts, and, out)
}
开发者ID:jacqui,项目名称:cayley,代码行数:40,代码来源:build_iterator.go
示例19: optimizeAnd
func (qs *QuadStore) optimizeAnd(it *iterator.And) (graph.Iterator, bool) {
subs := it.SubIterators()
var unusedIts []graph.Iterator
var newit *SQLIterator
newit = nil
changed := false
var err error
for _, it := range subs {
if it.Type() == sqlType {
if newit == nil {
newit = it.(*SQLIterator)
} else {
changed = true
newit, err = intersect(newit.sql, it.(*SQLIterator).sql, qs)
if err != nil {
glog.Error(err)
return it, false
}
}
} else {
unusedIts = append(unusedIts, it)
}
}
if !changed {
return it, false
}
if len(unusedIts) == 0 {
newit.Tagger().CopyFrom(it)
return newit, true
}
newAnd := iterator.NewAnd(qs)
newAnd.Tagger().CopyFrom(it)
newAnd.AddSubIterator(newit)
for _, i := range unusedIts {
newAnd.AddSubIterator(i)
}
return newAnd.Optimize()
}
开发者ID:rlayte,项目名称:cayley,代码行数:40,代码来源:optimizers.go
示例20: isMorphism
func isMorphism(nodes ...string) morphism {
return morphism{
Name: "is",
Reversal: func() morphism { return isMorphism(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
}
and := iterator.NewAnd(qs)
and.AddSubIterator(sub)
and.AddSubIterator(it)
return and
},
}
}
开发者ID:oliverp19,项目名称:cayley,代码行数:22,代码来源:morphism_apply_functions.go
注:本文中的github.com/google/cayley/graph/iterator.NewAnd函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论