annotating_by_label : automatically make label groups.
parent
4584993106
commit
b0d814af4b
|
|
@ -102,16 +102,34 @@ def main():
|
|||
|
||||
root_dir = args.input_path
|
||||
results = annotating.make_dictionary(root_dir)
|
||||
labels_file = os.path.join(root_dir, "label_groups")
|
||||
label_groups = os.path.join(root_dir, "label_groups")
|
||||
all_labels = os.path.join(root_dir, "labels")
|
||||
|
||||
if not os.path.exists(labels_file):
|
||||
print(f"Error: Labels file '{labels_file}' not found.")
|
||||
sys.exit(1)
|
||||
if not os.path.exists(label_groups):
|
||||
print(f"Warning: Labels file '{label_groups}' not found, making it out of '{all_labels}' (do check it…)")
|
||||
if not os.path.exists(all_labels):
|
||||
print(f"Error: {all_labels} not found.")
|
||||
sys.exit(1)
|
||||
|
||||
with open(labels_file, "r") as f:
|
||||
with open(all_labels, 'r') as f:
|
||||
lines = [l.strip() for l in f if l.strip()]
|
||||
|
||||
groups = {}
|
||||
for line in lines:
|
||||
# Key is the part before the colon, or the whole line if no colon
|
||||
key = line.split(' : ')[0] if ' : ' in line else line
|
||||
groups.setdefault(key, []).append(line)
|
||||
|
||||
with open(label_groups, 'w') as f:
|
||||
for items in groups.values():
|
||||
f.write(",".join(items) + "\n")
|
||||
|
||||
with open(label_groups, "r") as f:
|
||||
lines = [line.strip() for line in f if line.strip()]
|
||||
|
||||
bgnot_dir = os.path.join(root_dir, "BGnot")
|
||||
if args.overwrite and os.path.exists(bgnot_dir):
|
||||
shutil.rmtree(bgnot_dir)
|
||||
os.makedirs(bgnot_dir, exist_ok=True)
|
||||
|
||||
for line in lines:
|
||||
|
|
|
|||
Loading…
Reference in New Issue