Skip to content
Snippets Groups Projects
Commit 210311e5 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add a progress bar to stanza annotator

parent dddd3e0d
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import os.path
import stanza
from stanza.utils.conll import CoNLL
import sys
from tqdm import tqdm
def oneLine(sentence):
return sentence.text.replace('\n', ' ').replace('\t', ' ')
......@@ -27,7 +28,7 @@ class Annotator:
def annotate_dir(self, directory):
source_path = f'{self.source}/{directory}'
os.makedirs(f'{self.target}/{directory}', exist_ok=True)
for name in os.listdir(source_path):
for name in tqdm(os.listdir(source_path)):
path = f'{source_path}/{name}'
relpath = f'{directory}/{name}'
if os.path.isdir(path):
......@@ -40,13 +41,13 @@ class Annotator:
if not os.path.isfile(outputFile):
with open(f'{self.source}/{file}', 'r') as source:
document = source.read()
print("trying " + outputFile)
try:
with open(outputFile, 'w') as target:
for paragraph in document.split('\n\n'):
# print(f'# newpar id = {self.newpar()}', file=target)
self.annotate_paragraph(paragraph, target)
except Exception:
print("Failed trying " + outputFile)
os.unlink(outputFile)
sys.exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment