Graph implementation in newgraph
Implemented working version of Graph. Issues to solve remain, such as ordering of nodes in a block.
This commit is contained in:
parent
1db41615aa
commit
cff261519f
14
README.md
14
README.md
@ -10,7 +10,19 @@ First created in new_graph.py, but will replace graph.py.
|
||||
|
||||
Based on current cluster architecture.
|
||||
|
||||
### RecordGraph
|
||||
algorithm:
|
||||
~~~
|
||||
for block in blocks
|
||||
create node
|
||||
if block has link, set link as id
|
||||
else create id
|
||||
add texts to node
|
||||
for text in block save links
|
||||
|
||||
create edges from links
|
||||
~~~
|
||||
|
||||
### RecordGraph (experimental)
|
||||
|
||||
New architecture for creating dot. No clusters; one node (record) contains one row table with each column for a person.
|
||||
~~~
|
||||
|
||||
@ -1,10 +1,48 @@
|
||||
import graphviz
|
||||
import uuid
|
||||
|
||||
def get_id():
|
||||
return "id" + str(uuid.uuid4().hex)
|
||||
|
||||
# One cluster of nodes per block
|
||||
class Graph():
|
||||
def __init__(self):
|
||||
self.dot = None
|
||||
self.links = {}
|
||||
|
||||
def create_graph(self, config, data):
|
||||
self.dot = graphviz.Graph('testgraph', graph_attr={'center': 'true', 'compound': 'true', 'nodesep': '0.2', 'ranksep': '0.5 equally'}, node_attr={'shape': 'plaintext'})
|
||||
self.dot.format = 'svg'
|
||||
|
||||
blocks = data.get('blocks', [])
|
||||
for block in blocks:
|
||||
texts = block.get('texts', [])
|
||||
center_node = int(len(texts) / 2)
|
||||
cluster_id = 'cluster_' + get_id()
|
||||
|
||||
with self.dot.subgraph(name=cluster_id) as cluster:
|
||||
prev_node_id = ""
|
||||
for text in texts:
|
||||
node_id = get_id()
|
||||
cluster.node(node_id, label=text.get('text', ''))
|
||||
if prev_node_id:
|
||||
cluster.edge(prev_node_id, node_id, style='invis', rank='same')
|
||||
prev_node_id = node_id
|
||||
for link in text.get('links', []):
|
||||
self.links[link] = node_id
|
||||
|
||||
if center_node == 0:
|
||||
for link in block.get('links', []):
|
||||
if link in self.links:
|
||||
self.dot.edge(self.links[link], node_id, lhead=cluster_id)
|
||||
del self.links[link]
|
||||
center_node -= 1
|
||||
|
||||
def export_graph(self, out_dir):
|
||||
self.dot.render(directory=out_dir)
|
||||
|
||||
def __str__(self):
|
||||
return self.dot.source
|
||||
|
||||
|
||||
# One node per block
|
||||
|
||||
@ -22,7 +22,7 @@ def main():
|
||||
graph.build_dot()
|
||||
|
||||
# Test new dot generation
|
||||
new_graph = ng.RecordGraph()
|
||||
new_graph = ng.Graph()
|
||||
new_graph.create_graph(config, data)
|
||||
#print(new_graph)
|
||||
new_graph.export_graph(DATA_DIR)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 272 KiB After Width: | Height: | Size: 272 KiB |
2437
data/testgraph.gv
Normal file
2437
data/testgraph.gv
Normal file
File diff suppressed because it is too large
Load Diff
3845
data/testgraph.gv.svg
Normal file
3845
data/testgraph.gv.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 289 KiB |
Loading…
x
Reference in New Issue
Block a user