Wrote merge nodes test and neo4j testing infrastructure.
Added entity formatting functionality. Renamed the EventSubgraph to Subgraph because it is generic.
This commit is contained in:
+16
-16
@@ -6,35 +6,35 @@ import (
|
||||
|
||||
// Types
|
||||
|
||||
type EventSubgraph struct {
|
||||
type Subgraph struct {
|
||||
nodes []*Node
|
||||
rels []*Relationship
|
||||
}
|
||||
|
||||
func NewEventSubgraph() *EventSubgraph {
|
||||
return &EventSubgraph{
|
||||
func NewSubgraph() *Subgraph {
|
||||
return &Subgraph{
|
||||
nodes: []*Node{},
|
||||
rels: []*Relationship{},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) AddNode(node *Node) {
|
||||
func (s *Subgraph) AddNode(node *Node) {
|
||||
s.nodes = append(s.nodes, node)
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) AddRel(rel *Relationship) {
|
||||
func (s *Subgraph) AddRel(rel *Relationship) {
|
||||
s.rels = append(s.rels, rel)
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) Nodes() []*Node {
|
||||
func (s *Subgraph) Nodes() []*Node {
|
||||
return s.nodes
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) Rels() []*Relationship {
|
||||
func (s *Subgraph) Rels() []*Relationship {
|
||||
return s.rels
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) NodesByLabel(label string) []*Node {
|
||||
func (s *Subgraph) NodesByLabel(label string) []*Node {
|
||||
var nodes []*Node
|
||||
for _, node := range s.nodes {
|
||||
if node.Labels.Contains(label) {
|
||||
@@ -44,7 +44,7 @@ func (s *EventSubgraph) NodesByLabel(label string) []*Node {
|
||||
return nodes
|
||||
}
|
||||
|
||||
func (s *EventSubgraph) FirstNodeByLabel(label string) *Node {
|
||||
func (s *Subgraph) FirstNodeByLabel(label string) *Node {
|
||||
for _, node := range s.nodes {
|
||||
if node.Labels.Contains(label) {
|
||||
return node
|
||||
@@ -65,8 +65,8 @@ func IsValidTag(t roots.Tag) bool {
|
||||
|
||||
// Event to subgraph pipeline
|
||||
|
||||
func EventToSubgraph(e roots.ValidatedEvent, p ExpanderPipeline) *EventSubgraph {
|
||||
s := NewEventSubgraph()
|
||||
func EventToSubgraph(e roots.ValidatedEvent, p ExpanderPipeline) *Subgraph {
|
||||
s := NewSubgraph()
|
||||
|
||||
// Create core entities
|
||||
eventNode := newEventNode(e.ID(), e.CreatedAt(), e.Kind(), e.Content())
|
||||
@@ -133,7 +133,7 @@ func newTagRels(event *Node, tags []*Node) []*Relationship {
|
||||
|
||||
// Expander Pipeline
|
||||
|
||||
type Expander func(e roots.ValidatedEvent, s *EventSubgraph)
|
||||
type Expander func(e roots.ValidatedEvent, s *Subgraph)
|
||||
type ExpanderPipeline []Expander
|
||||
|
||||
func NewExpanderPipeline(expanders ...Expander) ExpanderPipeline {
|
||||
@@ -148,7 +148,7 @@ func DefaultExpanders() []Expander {
|
||||
}
|
||||
}
|
||||
|
||||
func ExpandTaggedEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
func ExpandTaggedEvents(e roots.ValidatedEvent, s *Subgraph) {
|
||||
for _, tag := range s.NodesByLabel("Tag") {
|
||||
if tag.Props["name"] != "e" {
|
||||
continue
|
||||
@@ -166,7 +166,7 @@ func ExpandTaggedEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
}
|
||||
}
|
||||
|
||||
func ExpandTaggedUsers(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
func ExpandTaggedUsers(e roots.ValidatedEvent, s *Subgraph) {
|
||||
for _, tag := range s.NodesByLabel("Tag") {
|
||||
if tag.Props["name"] != "p" {
|
||||
continue
|
||||
@@ -184,7 +184,7 @@ func ExpandTaggedUsers(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
}
|
||||
}
|
||||
|
||||
func ExpandReplaceableEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
func ExpandReplaceableEvents(e roots.ValidatedEvent, s *Subgraph) {
|
||||
if e.Kind() != 0 && e.Kind() != 3 && !(e.Kind() >= 10000 && e.Kind() < 20000) {
|
||||
return
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func ExpandReplaceableEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
s.AddRel(NewForUserRel(rk, authorNode, nil))
|
||||
}
|
||||
|
||||
func ExpandAddressableEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||
func ExpandAddressableEvents(e roots.ValidatedEvent, s *Subgraph) {
|
||||
if !(e.Kind() >= 30000 && e.Kind() < 40000) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user