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 ...@@ -5,6 +5,7 @@ import os.path
import stanza import stanza
from stanza.utils.conll import CoNLL from stanza.utils.conll import CoNLL
import sys import sys
from tqdm import tqdm
def oneLine(sentence): def oneLine(sentence):
return sentence.text.replace('\n', ' ').replace('\t', ' ') return sentence.text.replace('\n', ' ').replace('\t', ' ')
...@@ -27,7 +28,7 @@ class Annotator: ...@@ -27,7 +28,7 @@ class Annotator:
def annotate_dir(self, directory): def annotate_dir(self, directory):
source_path = f'{self.source}/{directory}' source_path = f'{self.source}/{directory}'
os.makedirs(f'{self.target}/{directory}', exist_ok=True) 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}' path = f'{source_path}/{name}'
relpath = f'{directory}/{name}' relpath = f'{directory}/{name}'
if os.path.isdir(path): if os.path.isdir(path):
...@@ -40,13 +41,13 @@ class Annotator: ...@@ -40,13 +41,13 @@ class Annotator:
if not os.path.isfile(outputFile): if not os.path.isfile(outputFile):
with open(f'{self.source}/{file}', 'r') as source: with open(f'{self.source}/{file}', 'r') as source:
document = source.read() document = source.read()
print("trying " + outputFile)
try: try:
with open(outputFile, 'w') as target: with open(outputFile, 'w') as target:
for paragraph in document.split('\n\n'): for paragraph in document.split('\n\n'):
# print(f'# newpar id = {self.newpar()}', file=target) # print(f'# newpar id = {self.newpar()}', file=target)
self.annotate_paragraph(paragraph, target) self.annotate_paragraph(paragraph, target)
except Exception: except Exception:
print("Failed trying " + outputFile)
os.unlink(outputFile) os.unlink(outputFile)
sys.exit(1) 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