本文整理匯總了Golang中github.com/google/cayley/graph.QuadStore類的典型用法代碼示例。如果您正苦於以下問題:Golang QuadStore類的具體用法?Golang QuadStore怎麽用?Golang QuadStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QuadStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: NewSingleReplication
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
var (
ignoreMissing bool
ignoreDuplicate bool
err error
)
if *graph.IgnoreMissing {
ignoreMissing = true
} else {
ignoreMissing, _, err = opts.BoolKey("ignore_missing")
if err != nil {
return nil, err
}
}
if *graph.IgnoreDup {
ignoreDuplicate = true
} else {
ignoreDuplicate, _, err = opts.BoolKey("ignore_duplicate")
if err != nil {
return nil, err
}
}
return &Single{
currentID: qs.Horizon(),
qs: qs,
ignoreOpts: graph.IgnoreOpts{
IgnoreDup: ignoreDuplicate,
IgnoreMissing: ignoreMissing,
},
}, nil
}
示例3: buildViaPath
func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
if len(via) == 0 {
return PathFromIterator(qs, qs.NodesAllIterator())
} else if len(via) == 1 {
v := via[0]
switch p := v.(type) {
case nil:
return PathFromIterator(qs, qs.NodesAllIterator())
case *Path:
if p.qs != qs {
newp := &Path{
qs: qs,
baseContext: p.baseContext,
stack: p.stack[:],
}
return newp
}
return p
case string:
return StartPath(qs, p)
default:
panic(fmt.Sprintln("Invalid type passed to buildViaPath.", reflect.TypeOf(v), p))
}
}
var strings []string
for _, s := range via {
if str, ok := s.(string); ok {
strings = append(strings, str)
} else {
panic("Non-string type passed to long Via path")
}
}
return StartPath(qs, strings...)
}
示例4: iteratedQuads
func iteratedQuads(qs graph.QuadStore, it graph.Iterator) []quad.Quad {
var res ordered
for graph.Next(it) {
res = append(res, qs.Quad(it.Result()))
}
sort.Sort(res)
return res
}
示例5: iteratedNames
func iteratedNames(qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for graph.Next(it) {
res = append(res, qs.NameOf(it.Result()))
}
sort.Strings(res)
return res
}
示例6: NewSingleReplication
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
horizon := qs.Horizon()
rep := &Single{nextID: horizon + 1, qs: qs}
if horizon <= 0 {
rep.nextID = 1
}
return rep, nil
}
示例7: IteratedQuads
func IteratedQuads(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Quad {
var res quad.ByQuadString
for graph.Next(it) {
res = append(res, qs.Quad(it.Result()))
}
require.Nil(t, it.Err())
sort.Sort(res)
return res
}
示例8: IteratedValues
func IteratedValues(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Value {
var res []quad.Value
for graph.Next(it) {
res = append(res, qs.NameOf(it.Result()))
}
require.Nil(t, it.Err())
sort.Sort(quad.ByValueString(res))
return res
}
示例9: IteratedRawStrings
func IteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for graph.Next(it) {
res = append(res, qs.NameOf(it.Result()).String())
}
require.Nil(t, it.Err())
sort.Strings(res)
return res
}
示例10: iterateResults
func iterateResults(qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for graph.Next(it) {
v := it.Result()
if t, ok := v.(*Token); ok && t.Kind == nodeKind {
res = append(res, qs.NameOf(it.Result()))
} else {
res = append(res, qs.Quad(it.Result()).String())
}
}
sort.Strings(res)
it.Reset()
return res
}
示例11: hasaWithTag
func hasaWithTag(qs graph.QuadStore, tag string, target string) *HasA {
and := NewAnd(qs)
obj := qs.FixedIterator()
obj.Add(qs.ValueOf(target))
obj.Tagger().Add(tag)
and.AddSubIterator(NewLinksTo(qs, obj, quad.Object))
pred := qs.FixedIterator()
pred.Add(qs.ValueOf("status"))
and.AddSubIterator(NewLinksTo(qs, pred, quad.Predicate))
return NewHasA(qs, and, quad.Subject)
}
示例12: buildViaPath
func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
if len(via) == 0 {
return PathFromIterator(qs, qs.NodesAllIterator())
} else if len(via) == 1 {
v := via[0]
switch p := v.(type) {
case nil:
return PathFromIterator(qs, qs.NodesAllIterator())
case *Path:
if p.qs != qs {
newp := &Path{
qs: qs,
baseContext: p.baseContext,
stack: p.stack[:],
}
return newp
}
return p
case quad.Value:
return StartPath(qs, p)
case string:
return StartPath(qs, quad.Raw(p))
default:
panic(fmt.Sprintln("Invalid type passed to buildViaPath.", reflect.TypeOf(v), p))
}
}
var nodes []quad.Value
for _, s := range via {
switch v := s.(type) {
case quad.Value:
nodes = append(nodes, v)
case string:
nodes = append(nodes, quad.Raw(v))
default:
panic("Non-value type passed to long Via path")
}
}
return StartPath(qs, nodes...)
}
示例13: buildInOutIterator
func buildInOutIterator(obj *otto.Object, qs graph.QuadStore, 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 = qs.NodesAllIterator()
} else {
zero, _ := argArray.Get("0")
predicateNodeIterator = buildIteratorFromValue(zero, qs)
}
if length >= 2 {
var tags []string
one, _ := argArray.Get("1")
if one.IsString() {
tags = append(tags, one.String())
} else if one.Class() == "Array" {
tags = stringsFrom(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(qs, base, in)
and := iterator.NewAnd()
and.AddSubIterator(iterator.NewLinksTo(qs, predicateNodeIterator, quad.Predicate))
and.AddSubIterator(lto)
return iterator.NewHasA(qs, and, out)
}
示例14: 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
}
示例15: buildViaPath
func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
if len(via) == 0 {
return PathFromIterator(qs, qs.NodesAllIterator())
} else if len(via) == 1 {
v := via[0]
switch p := v.(type) {
case *Path:
return p
case string:
return StartPath(qs, p)
default:
panic("Invalid type passed to buildViaPath.")
}
}
var strings []string
for _, s := range via {
if str, ok := s.(string); ok {
strings = append(strings, str)
} else {
panic("Non-string type passed to long Via path")
}
}
return StartPath(qs, strings...)
}