From da6fa3b69722ed583a0ac1dbd016947ee70b461b Mon Sep 17 00:00:00 2001 From: j Date: Sun, 24 Mar 2019 11:43:51 +0800 Subject: [PATCH] add tab ontology --- ontology/update.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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)