Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prints tree to visualise #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions osm_fudge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def main():
sys.exit("Error: Empty input file")

tree_obj.freeze()
tree_obj.print()
if args.query_strings:
for query_string in args.query_strings.split(','):
gen = tree_obj.nearest(query_string.strip(), max_distance=args.max_distance)
Expand Down
20 changes: 20 additions & 0 deletions osm_fudge/index/bk_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from recordclass import recordclass
from bisect import bisect_left
from bisect import bisect_right
import pydot

Node = recordclass('Node', ['value', 'edges', 'children'])

Expand Down Expand Up @@ -84,3 +85,22 @@ def nearest(self, value, max_distance=None):
for index, edge in enumerate(node.edges):
if edge >= minimum and edge <= maximum:
stack.append(node.children[index])

def print(self):
graph = pydot.Dot(graph_type='digraph')

stack = []
stack.append(self.root)

while stack:
node = stack.pop()
if len(node.children):
parent_node = pydot.Node(node.value)
graph.add_node(parent_node)
for index, child in enumerate(node.children):
child_node = pydot.Node(child.value)
graph.add_node(child_node)
graph.add_edge(pydot.Edge(parent_node, child_node, label=node.edges[index]))
stack.append(child)

graph.write_png('graph.png')