Module: Pacer::Utils::GraphAnalysis
- Defined in:
- lib/pacer/utils/graph_analysis.rb
Defined Under Namespace
Modules: Edges, Properties, Route, Vertices
Class Method Summary collapse
-
.structure(graph, type_field = :type) ⇒ Object
Returns a TinkerGraph representing the number of each type of node and how many edges (by label) point to each other type of node.
Class Method Details
.structure(graph, type_field = :type) ⇒ Object
Returns a TinkerGraph representing the number of each type of node and how many edges (by label) point to each other type of node.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pacer/utils/graph_analysis.rb', line 8 def structure(graph, type_field = :type) result = Pacer.tg result.vertex_name = proc do |v| case v[:element_type] when 'vertex' "vertex '#{ v[:type] }' (#{ v[:count] })" when 'edge' "edge '#{ v[:label] }' (#{ v[:count] })" when 'property keys' if v[:keys].empty? "has no properties" else "has properties: #{ v[:keys].join ', ' } (#{ v[:count] })" end end end result.edge_name = proc do |e| if e.label == 'properties' "#{ e[:count] }" else "#{ e[:count] } '#{ e.label }' edges to" end end graph.v[type_field].fast_group_count.to_h.each do |type, count| result.create_vertex :element_type => 'vertex', :type_field => type_field, :type => type, :count => count end graph.e.labels.fast_group_count.to_h.each do |label, count| result.create_vertex :element_type => 'edge', :label => label, :count => count end result.v(:element_type => 'vertex').each do |type_node| puts "vertices of type #{ type_node[:type] }: #{ type_node[:count] }" graph.v(self, :type => type_node[:type]).property_variations result, type_node end result.v(:element_type => 'edge').each do |edge_node| puts "edges with label #{ edge_node[:label] }: #{ edge_node[:count] }" edge_route = graph.e(edge_node[:label]).e(self) edge_route.property_variations result, edge_node end result.v.each do |type_node| begin edges = graph.v(type_field => type_node[:type]).out_e edge_types = edges.group_count do |e| [e.label, e.in_vertex[type_field]] end edge_types.each do |(label, type), count| puts "edges labelled #{ label } from #{ type_node[:type] } to #{ type }: #{ count }" type_node.add_edges_to(label, result.v(:type => type), :count => count) end rescue => e puts e. end end result end |