forked from leonard-thong/SciAnnotate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
newEntity.py
31 lines (24 loc) · 895 Bytes
/
newEntity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import shutil
import re
from document import real_directory
from os.path import join as path_join
from projectconfig import __parse_configs, __default_configuration, __read_or_default, SECTION_ALIAS, SEPARATOR_STR
def create_new_entity(**kwargs):
res = dict()
entity = kwargs['entity_name']
collection = kwargs['collection']
real_dir = real_directory(collection)
config_dir = real_dir + "annotation.conf"
configstr = __read_or_default(config_dir, __default_configuration)
configstr = configstr.split("\n")
# section = "general"
# section_lines = {section: []}
# section_labels = {}
for ln, l in enumerate(configstr):
if l == "[relations]":
configstr.insert(ln-2, entity)
with open(config_dir, 'w') as configFile:
configFile.write("\n".join(configstr))
res['status'] = 200
return res