diff --git a/ontology/update.py b/ontology/update.py index 3105a4e..911e713 100755 --- a/ontology/update.py +++ b/ontology/update.py @@ -39,11 +39,22 @@ def get_node(name, children, parent=None): return node +def render_children(root, indent=0): + txt = ('\t' * indent) + root['name'] + if 'children' in root: + parts = '' + for child in root['children']: + parts += '\n' + render_children(child, indent+1) + txt += '\n'.join([('\t' * indent) + p for p in parts.split('\n')]) + return '\n'.join([l.rstrip() for l in txt.split('\n')]) + if __name__ == '__main__': os.chdir(base) tree = defaultdict(dict) + ontology_txt = '' + for keyword in keywords: if ': ' not in keyword: parent = 'other' @@ -75,5 +86,10 @@ if __name__ == '__main__': child = get_node(name, tree[name], name) sized_ontology['children'].append(child) + + ontology_txt = render_children(sized_ontology) + with open('../static/ontology/sized_ontology.json', 'w') as fd: json.dump(sized_ontology, fd, indent=4, sort_keys=True) + with open('../static/ontology/ontology.txt', 'w') as fd: + fd.write(ontology_txt)