本文整理汇总了Golang中github.com/google/cayley/graph/iterator.NewNull函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNull函数的具体用法?Golang NewNull怎么用?Golang NewNull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNull函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: buildIteratorTree
func buildIteratorTree(obj *otto.Object, qs graph.QuadStore) graph.Iterator {
if !isVertexChain(obj) {
return iterator.NewNull()
}
path := buildPathFromObject(obj)
if path == nil {
return iterator.NewNull()
}
return path.BuildIteratorOn(qs)
}
开发者ID:e4x,项目名称:cayley,代码行数:10,代码来源:build_iterator.go
示例2: buildIteratorFromValue
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
if val.IsNull() || val.IsUndefined() {
return ts.NodesAllIterator()
}
if val.IsPrimitive() {
thing, _ := val.Export()
switch v := thing.(type) {
case string:
it := ts.FixedIterator()
it.Add(ts.ValueOf(v))
return it
default:
glog.Errorln("Trying to build unknown primitive value.")
}
}
switch val.Class() {
case "Object":
return buildIteratorTree(val.Object(), ts)
case "Array":
// Had better be an array of strings
strings := makeListOfStringsFromArrayValue(val.Object())
it := ts.FixedIterator()
for _, x := range strings {
it.Add(ts.ValueOf(x))
}
return it
case "Number":
fallthrough
case "Boolean":
fallthrough
case "Date":
fallthrough
case "String":
it := ts.FixedIterator()
str, _ := val.ToString()
it.Add(ts.ValueOf(str))
return it
default:
glog.Errorln("Trying to handle unsupported Javascript value.")
return iterator.NewNull()
}
}
开发者ID:jacqui,项目名称:cayley,代码行数:42,代码来源:build_iterator.go
示例3: 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
示例4: optimizeLinksTo
func (qs *QuadStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
subs := it.SubIterators()
if len(subs) != 1 {
return it, false
}
primary := subs[0]
switch primary.Type() {
case graph.Fixed:
size, _ := primary.Size()
if size == 0 {
return iterator.NewNull(), true
}
if size == 1 {
if !graph.Next(primary) {
panic("sql: unexpected size during optimize")
}
val := primary.Result()
newIt := qs.QuadIterator(it.Direction(), val)
nt := newIt.Tagger()
nt.CopyFrom(it)
for _, tag := range primary.Tagger().Tags() {
nt.AddFixed(tag, val)
}
it.Close()
return newIt, true
} else if size > 1 {
var vals []string
for graph.Next(primary) {
vals = append(vals, qs.NameOf(primary.Result()))
}
lsql := &SQLLinkIterator{
constraints: []constraint{
constraint{
dir: it.Direction(),
vals: vals,
},
},
tableName: newTableName(),
size: 0,
}
l := &SQLIterator{
uid: iterator.NextUID(),
qs: qs,
sql: lsql,
}
nt := l.Tagger()
nt.CopyFrom(it)
for _, t := range primary.Tagger().Tags() {
lsql.tagdirs = append(lsql.tagdirs, tagDir{
dir: it.Direction(),
tag: t,
})
}
it.Close()
return l, true
}
case sqlType:
p := primary.(*SQLIterator)
newit, err := linksto(p.sql, it.Direction(), qs)
if err != nil {
glog.Errorln(err)
return it, false
}
newit.Tagger().CopyFrom(it)
return newit, true
case graph.All:
linkit := &SQLLinkIterator{
tableName: newTableName(),
size: qs.Size(),
}
for _, t := range primary.Tagger().Tags() {
linkit.tagdirs = append(linkit.tagdirs, tagDir{
dir: it.Direction(),
tag: t,
})
}
for k, v := range primary.Tagger().Fixed() {
linkit.tagger.AddFixed(k, v)
}
linkit.tagger.CopyFrom(it)
newit := NewSQLIterator(qs, linkit)
return newit, true
}
return it, false
}
开发者ID:e4x,项目名称:cayley,代码行数:85,代码来源:optimizers.go
示例5: buildIteratorTree
func buildIteratorTree(obj *otto.Object, ts graph.TripleStore) graph.Iterator {
if !isVertexChain(obj) {
return iterator.NewNull()
}
return buildIteratorTreeHelper(obj, ts, iterator.NewNull())
}
开发者ID:jacqui,项目名称:cayley,代码行数:6,代码来源:build_iterator.go
示例6: buildIteratorTreeHelper
func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.Iterator) graph.Iterator {
var it graph.Iterator
it = base
// TODO: Better error handling
kindVal, _ := obj.Get("_gremlin_type")
stringArgs := getStringArgs(obj)
var subIt graph.Iterator
prevVal, _ := obj.Get("_gremlin_prev")
if !prevVal.IsObject() {
subIt = base
} else {
subIt = buildIteratorTreeHelper(prevVal.Object(), ts, base)
}
kind, _ := kindVal.ToString()
switch kind {
case "vertex":
if len(stringArgs) == 0 {
it = ts.NodesAllIterator()
} else {
fixed := ts.FixedIterator()
for _, name := range stringArgs {
fixed.Add(ts.ValueOf(name))
}
it = fixed
}
case "tag":
it = subIt
for _, tag := range stringArgs {
it.Tagger().Add(tag)
}
case "save":
all := ts.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
if len(stringArgs) == 2 {
all.Tagger().Add(stringArgs[1])
} else {
all.Tagger().Add(stringArgs[0])
}
predFixed := ts.FixedIterator()
predFixed.Add(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, quad.Object))
hasa := iterator.NewHasA(ts, subAnd, quad.Subject)
and := iterator.NewAnd()
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "saver":
all := ts.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
if len(stringArgs) == 2 {
all.Tagger().Add(stringArgs[1])
} else {
all.Tagger().Add(stringArgs[0])
}
predFixed := ts.FixedIterator()
predFixed.Add(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, quad.Subject))
hasa := iterator.NewHasA(ts, subAnd, quad.Object)
and := iterator.NewAnd()
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "has":
fixed := ts.FixedIterator()
if len(stringArgs) < 2 {
return iterator.NewNull()
}
for _, name := range stringArgs[1:] {
fixed.Add(ts.ValueOf(name))
}
predFixed := ts.FixedIterator()
predFixed.Add(ts.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd()
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed, quad.Object))
hasa := iterator.NewHasA(ts, subAnd, quad.Subject)
and := iterator.NewAnd()
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "morphism":
it = base
case "and":
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")
if !isVertexChain(firstArg.Object()) {
return iterator.NewNull()
}
argIt := buildIteratorTree(firstArg.Object(), ts)
and := iterator.NewAnd()
//.........这里部分代码省略.........
开发者ID:jacqui,项目名称:cayley,代码行数:101,代码来源:build_iterator.go
示例7: buildIteratorTreeHelper
func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator {
// TODO: Better error handling
var (
it graph.Iterator
subIt graph.Iterator
)
if prev, _ := obj.Get("_gremlin_prev"); !prev.IsObject() {
subIt = base
} else {
subIt = buildIteratorTreeHelper(prev.Object(), qs, base)
}
stringArgs := propertiesOf(obj, "string_args")
val, _ := obj.Get("_gremlin_type")
switch val.String() {
case "vertex":
if len(stringArgs) == 0 {
it = qs.NodesAllIterator()
} else {
fixed := qs.FixedIterator()
for _, name := range stringArgs {
fixed.Add(qs.ValueOf(name))
}
it = fixed
}
case "tag":
it = subIt
for _, tag := range stringArgs {
it.Tagger().Add(tag)
}
case "save":
all := qs.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
if len(stringArgs) == 2 {
all.Tagger().Add(stringArgs[1])
} else {
all.Tagger().Add(stringArgs[0])
}
predFixed := qs.FixedIterator()
predFixed.Add(qs.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd(qs)
subAnd.AddSubIterator(iterator.NewLinksTo(qs, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Object))
hasa := iterator.NewHasA(qs, subAnd, quad.Subject)
and := iterator.NewAnd(qs)
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "saver":
all := qs.NodesAllIterator()
if len(stringArgs) > 2 || len(stringArgs) == 0 {
return iterator.NewNull()
}
if len(stringArgs) == 2 {
all.Tagger().Add(stringArgs[1])
} else {
all.Tagger().Add(stringArgs[0])
}
predFixed := qs.FixedIterator()
predFixed.Add(qs.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd(qs)
subAnd.AddSubIterator(iterator.NewLinksTo(qs, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Subject))
hasa := iterator.NewHasA(qs, subAnd, quad.Object)
and := iterator.NewAnd(qs)
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "has":
fixed := qs.FixedIterator()
if len(stringArgs) < 2 {
return iterator.NewNull()
}
for _, name := range stringArgs[1:] {
fixed.Add(qs.ValueOf(name))
}
predFixed := qs.FixedIterator()
predFixed.Add(qs.ValueOf(stringArgs[0]))
subAnd := iterator.NewAnd(qs)
subAnd.AddSubIterator(iterator.NewLinksTo(qs, predFixed, quad.Predicate))
subAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed, quad.Object))
hasa := iterator.NewHasA(qs, subAnd, quad.Subject)
and := iterator.NewAnd(qs)
and.AddSubIterator(hasa)
and.AddSubIterator(subIt)
it = and
case "morphism":
it = base
case "and":
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")
if !isVertexChain(firstArg.Object()) {
return iterator.NewNull()
}
argIt := buildIteratorTree(firstArg.Object(), qs)
and := iterator.NewAnd(qs)
//.........这里部分代码省略.........
开发者ID:oliverp19,项目名称:cayley,代码行数:101,代码来源:build_iterator.go
示例8: buildIteratorTree
func (p *pathObject) buildIteratorTree() graph.Iterator {
if p.path == nil {
return iterator.NewNull()
}
return p.path.BuildIteratorOn(p.wk.qs)
}
开发者ID:dennwc,项目名称:cayley,代码行数:6,代码来源:traversals.go
注:本文中的github.com/google/cayley/graph/iterator.NewNull函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论