本文整理汇总了Golang中github.com/lytics/cayley/graph.Iterator.SubIterators方法的典型用法代码示例。如果您正苦于以下问题:Golang Iterator.SubIterators方法的具体用法?Golang Iterator.SubIterators怎么用?Golang Iterator.SubIterators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lytics/cayley/graph.Iterator
的用法示例。
在下文中一共展示了Iterator.SubIterators方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MakeNode
func (s *queryShape) MakeNode(it graph.Iterator) *Node {
n := Node{ID: s.nodeID}
for _, tag := range it.Tagger().Tags() {
n.Tags = append(n.Tags, tag)
}
for k := range it.Tagger().Fixed() {
n.Tags = append(n.Tags, k)
}
switch it.Type() {
case graph.And:
for _, sub := range it.SubIterators() {
s.nodeID++
newNode := s.MakeNode(sub)
if sub.Type() != graph.Or {
s.StealNode(&n, newNode)
} else {
s.AddNode(newNode)
s.AddLink(&Link{n.ID, newNode.ID, 0, 0})
}
}
case graph.Fixed:
n.IsFixed = true
for graph.Next(it) {
n.Values = append(n.Values, s.qs.NameOf(it.Result()))
}
case graph.HasA:
hasa := it.(*HasA)
s.PushHasa(n.ID, hasa.dir)
s.nodeID++
newNode := s.MakeNode(hasa.primaryIt)
s.AddNode(newNode)
s.RemoveHasa()
case graph.Or:
for _, sub := range it.SubIterators() {
s.nodeID++
newNode := s.MakeNode(sub)
if sub.Type() == graph.Or {
s.StealNode(&n, newNode)
} else {
s.AddNode(newNode)
s.AddLink(&Link{n.ID, newNode.ID, 0, 0})
}
}
case graph.LinksTo:
n.IsLinkNode = true
lto := it.(*LinksTo)
s.nodeID++
newNode := s.MakeNode(lto.primaryIt)
hasaID, hasaDir := s.LastHasa()
if (hasaDir == quad.Subject && lto.dir == quad.Object) ||
(hasaDir == quad.Object && lto.dir == quad.Subject) {
s.AddNode(newNode)
if hasaDir == quad.Subject {
s.AddLink(&Link{hasaID, newNode.ID, 0, n.ID})
} else {
s.AddLink(&Link{newNode.ID, hasaID, 0, n.ID})
}
} else if lto.primaryIt.Type() == graph.Fixed {
s.StealNode(&n, newNode)
} else {
s.AddNode(newNode)
}
case graph.Optional:
// Unsupported, for the moment
fallthrough
case graph.All:
}
return &n
}