AddNavigation adds a navigation to the graph
(n types.PageState)
| 45 | |
| 46 | // AddNavigation adds a navigation to the graph |
| 47 | func (g *CrawlGraph) AddPageState(n types.PageState) error { |
| 48 | vertexAttrs := map[string]string{ |
| 49 | "label": n.URL, |
| 50 | } |
| 51 | if n.IsRoot { |
| 52 | vertexAttrs["is_root"] = "true" |
| 53 | } |
| 54 | |
| 55 | err := g.graph.AddVertex(n, func(vp *graph.VertexProperties) { |
| 56 | vp.Weight = n.Depth |
| 57 | vp.Attributes = vertexAttrs |
| 58 | }) |
| 59 | if err != nil { |
| 60 | if errors.Is(err, graph.ErrVertexAlreadyExists) { |
| 61 | return nil |
| 62 | } |
| 63 | return errors.Wrap(err, "could not add vertex to graph") |
| 64 | } |
| 65 | |
| 66 | if n.NavigationAction != nil { |
| 67 | edgeAttrs := map[string]string{ |
| 68 | "label": n.NavigationAction.String(), |
| 69 | } |
| 70 | |
| 71 | err = g.graph.AddEdge(n.OriginID, n.UniqueID, func(ep *graph.EdgeProperties) { |
| 72 | ep.Weight = n.Depth |
| 73 | ep.Attributes = edgeAttrs |
| 74 | }) |
| 75 | if err != nil { |
| 76 | if errors.Is(err, graph.ErrEdgeAlreadyExists) { |
| 77 | return nil |
| 78 | } |
| 79 | return errors.Wrapf(err, "could not add edge to graph: source vertex %s", n.OriginID) |
| 80 | } |
| 81 | } |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | func (g *CrawlGraph) AddEdge(sourceState, targetState string, action *types.Action) error { |
| 86 | if action == nil { |