add tab ontology
This commit is contained in:
parent
5000f4a1ad
commit
da6fa3b697
1 changed files with 16 additions and 0 deletions
|
@ -39,11 +39,22 @@ def get_node(name, children, parent=None):
|
||||||
return node
|
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__':
|
if __name__ == '__main__':
|
||||||
os.chdir(base)
|
os.chdir(base)
|
||||||
|
|
||||||
tree = defaultdict(dict)
|
tree = defaultdict(dict)
|
||||||
|
|
||||||
|
ontology_txt = ''
|
||||||
|
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
if ': ' not in keyword:
|
if ': ' not in keyword:
|
||||||
parent = 'other'
|
parent = 'other'
|
||||||
|
@ -75,5 +86,10 @@ if __name__ == '__main__':
|
||||||
child = get_node(name, tree[name], name)
|
child = get_node(name, tree[name], name)
|
||||||
sized_ontology['children'].append(child)
|
sized_ontology['children'].append(child)
|
||||||
|
|
||||||
|
|
||||||
|
ontology_txt = render_children(sized_ontology)
|
||||||
|
|
||||||
with open('../static/ontology/sized_ontology.json', 'w') as fd:
|
with open('../static/ontology/sized_ontology.json', 'w') as fd:
|
||||||
json.dump(sized_ontology, fd, indent=4, sort_keys=True)
|
json.dump(sized_ontology, fd, indent=4, sort_keys=True)
|
||||||
|
with open('../static/ontology/ontology.txt', 'w') as fd:
|
||||||
|
fd.write(ontology_txt)
|
||||||
|
|
Loading…
Reference in a new issue