diff --git a/app.py b/app.py
index 98df5d2..53e5c91 100644
--- a/app.py
+++ b/app.py
@@ -448,6 +448,44 @@ def login():
return render_template(
'login.html', error=error, totalsents=len(SENTENCES))
+def loadgrammar(username):
+ _, lang = os.path.split(os.path.basename(app.config['GRAMMAR']))
+ app.logger.info('Loading grammar %r', lang)
+ if username in WORKERS and isinstance(WORKERS[username], ProcessPoolExecutor):
+ WORKERS[username].shutdown(wait=False)
+ pool = ProcessPoolExecutor(max_workers=1)
+ future = pool.submit(
+ worker.loadgrammar,
+ app.config['GRAMMAR'], app.config['LIMIT'])
+ future.result()
+ app.logger.info('Grammar %r loaded.', lang)
+ # train on annotated sentences
+ annotations = readannotations()
+ if annotations:
+ app.logger.info('training on %d previously annotated sentences',
+ len(annotations))
+ trees, sents = [], []
+ headrules = pool.submit(worker.getprop, 'headrules').result()
+ for block in annotations.values():
+ # HOTFIX for ROOT error
+ blocklns = block.splitlines()
+ for iln,blockln in enumerate(blocklns):
+ if '\tROOT\t' in blockln and '\t0\t' not in blockln:
+ blocklns[iln] = blocklns[iln].replace('\tROOT\t', '\tXXX-XXX\t')
+ block = '\n'.join(blocklns)
+
+ item = exporttree(block.splitlines())
+ canonicalize(item.tree)
+ if headrules:
+ applyheadrules(item.tree, headrules)
+ trees.append(item.tree)
+ sents.append(item.sent)
+ if False and app.config['DEBUG']:
+ future = NoFuture(worker.augment, trees, sents)
+ else:
+ future = pool.submit(worker.augment, trees, sents)
+ future.result()
+ WORKERS[username] = pool
@app.route('/annotate/dologin')
def dologin():
@@ -457,7 +495,7 @@ def generate(url):
''
'
redirect'
'You were logged in successfully. ')
- if username in WORKERS:
+ if username in WORKERS and isinstance(WORKERS[username], ProcessPoolExecutor):
try:
_ = WORKERS[username].submit(
worker.getprop, 'headrules').result()
@@ -467,50 +505,8 @@ def generate(url):
yield "" % url
return
yield 'Loading grammar; this will take a few seconds ...'
- _, lang = os.path.split(os.path.basename(app.config['GRAMMAR']))
- app.logger.info('Loading grammar %r', lang)
- pool = ProcessPoolExecutor(max_workers=1)
- if False and app.config['DEBUG']:
- from discodop.treesearch import NoFuture
- future = NoFuture(
- worker.loadgrammar,
- app.config['GRAMMAR'], app.config['LIMIT'])
- else:
- future = pool.submit(
- worker.loadgrammar,
- app.config['GRAMMAR'], app.config['LIMIT'])
- future.result()
- app.logger.info('Grammar %r loaded.', lang)
- # train on annotated sentences
- annotations = readannotations()
- if annotations:
- app.logger.info('training on %d previously annotated sentences',
- len(annotations))
- trees, sents = [], []
- headrules = pool.submit(worker.getprop, 'headrules').result()
- for block in annotations.values():
- # HOTFIX for ROOT error
- blocklns = block.splitlines()
- for iln,blockln in enumerate(blocklns):
- if '\tROOT\t' in blockln and '\t0\t' not in blockln:
- blocklns[iln] = blocklns[iln].replace('\tROOT\t', '\tXXX-XXX\t')
- block = '\n'.join(blocklns)
-
- item = exporttree(block.splitlines())
- canonicalize(item.tree)
- if headrules:
- applyheadrules(item.tree, headrules)
- trees.append(item.tree)
- sents.append(item.sent)
- if False and app.config['DEBUG']:
- future = NoFuture(worker.augment, trees, sents)
- else:
- future = pool.submit(worker.augment, trees, sents)
- future.result()
- WORKERS[username] = pool
+ loadgrammar(username)
yield "" % url
- # return "" % url
-
nexturl = request.args.get('next')
if not is_safe_url(nexturl) or 'username' not in session:
return abort(400)
@@ -572,6 +568,8 @@ def undoaccept():
'DELETE FROM entries WHERE username = ? AND id = ?',
(username, sentid))
db.commit()
+ # reload the grammar
+ loadgrammar(username)
return jsonify({"success": True})
@app.route('/retokenize', methods=['POST'])
@@ -741,7 +739,7 @@ def edit():
msg = ''
if request.args.get('annotated') == '1': # there is a saved tree
msg = Markup('You have already annotated '
- 'this sentence.')
+ 'this sentence.')
id = QUEUE[sentno - 1][3]
treestr, n = getannotation(username, id) # get tree from database
treeobj = ActivedopTree.from_str(treestr)
diff --git a/templates/edittree.html b/templates/edittree.html
index cdd3244..70cdab3 100644
--- a/templates/edittree.html
+++ b/templates/edittree.html
@@ -42,6 +42,8 @@
window.location.href = '/annotate/annotate/' + sentno;
}
function undoAccept() {
+ // Change text of button to "Reverting..." to indicate that the action is being processed
+ $('#undo').text('Reverting...');
var sentid = $('#sentid').val();
var sentno = $('#sentno').val();
$.ajax({