add tab ontology

This commit is contained in:
j 2019-03-24 11:43:51 +08:00
parent 5000f4a1ad
commit da6fa3b697
1 changed files with 16 additions and 0 deletions

View File

@ -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)