add Is, Follow, and All to the path API
This commit is contained in:
parent
3dc74329c0
commit
4128133675
2 changed files with 98 additions and 5 deletions
|
|
@ -32,6 +32,9 @@ type Path struct {
|
|||
}
|
||||
|
||||
func StartPath(qs graph.QuadStore, nodes ...string) *Path {
|
||||
if len(nodes) == 0 {
|
||||
return PathFromIterator(qs, qs.NodesAllIterator())
|
||||
}
|
||||
return &Path{
|
||||
stack: []morphism{
|
||||
isMorphism(qs, nodes...),
|
||||
|
|
@ -43,7 +46,7 @@ func StartPath(qs graph.QuadStore, nodes ...string) *Path {
|
|||
func PathFromIterator(qs graph.QuadStore, it graph.Iterator) *Path {
|
||||
return &Path{
|
||||
stack: []morphism{
|
||||
intersectIteratorMorphism(it),
|
||||
iteratorMorphism(it),
|
||||
},
|
||||
qs: qs,
|
||||
}
|
||||
|
|
@ -63,6 +66,11 @@ func (p *Path) Reverse() *Path {
|
|||
return newPath
|
||||
}
|
||||
|
||||
func (p *Path) Is(nodes ...string) *Path {
|
||||
p.stack = append(p.stack, isMorphism(p.qs, nodes...))
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Path) Tag(tags ...string) *Path {
|
||||
p.stack = append(p.stack, tagMorphism(tags...))
|
||||
return p
|
||||
|
|
@ -87,6 +95,16 @@ func (p *Path) Or(path *Path) *Path {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p *Path) Follow(path *Path) *Path {
|
||||
p.stack = append(p.stack, followMorphism(path))
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Path) FollowReverse(path *Path) *Path {
|
||||
p.stack = append(p.stack, followMorphism(path.Reverse()))
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Path) BuildIterator() graph.Iterator {
|
||||
f := p.MorphismFunc()
|
||||
return f(p.qs.NodesAllIterator())
|
||||
|
|
@ -149,10 +167,10 @@ func inMorphism(qs graph.QuadStore, via ...interface{}) morphism {
|
|||
}
|
||||
}
|
||||
|
||||
func intersectIteratorMorphism(it graph.Iterator) morphism {
|
||||
func iteratorMorphism(it graph.Iterator) morphism {
|
||||
return morphism{
|
||||
"iterator",
|
||||
func() morphism { return intersectIteratorMorphism(it) },
|
||||
func() morphism { return iteratorMorphism(it) },
|
||||
func(subIt graph.Iterator) graph.Iterator {
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(it)
|
||||
|
|
@ -190,6 +208,17 @@ func orMorphism(path *Path) morphism {
|
|||
}
|
||||
}
|
||||
|
||||
func followMorphism(path *Path) morphism {
|
||||
return morphism{
|
||||
"follow",
|
||||
func() morphism { return followMorphism(path.Reverse()) },
|
||||
func(base graph.Iterator) graph.Iterator {
|
||||
p := path.MorphismFunc()
|
||||
return p(base)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func inOutIterator(viaPath *Path, reverse bool) graph.MorphismFunc {
|
||||
return func(base graph.Iterator) graph.Iterator {
|
||||
in, out := quad.Subject, quad.Object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue