Skip to content

Commit

Permalink
fixed parsing errors not flowing back into interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ned2 committed Feb 20, 2018
1 parent 2cab26c commit bb8a094
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
7 changes: 3 additions & 4 deletions bin/run-web
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ This script runs the typediff webapp. Options are:
--port PORT Runs the app on port PORT.
--debug Runs mod_wsgi-express with --debug-mode and --enable-debugger
flags enabled.
--debug Runs mod_wsgi-express with --debug-mode, --enable-debugger
and --log-to-terminal flags enabled.
--echo Don't run the app, just echo the underlying mod_wsgi-express
command that would have been run with the configuration
Expand All @@ -30,7 +30,7 @@ while [[ ${1} == --* ]]; do
shift 2
;;
--debug)
DEBUGFLAGS="--debug-mode --enable-debugger"
DEBUGFLAGS="--log-to-terminal --debug-mode --enable-debugger"
shift 1
;;
--echo)
Expand Down Expand Up @@ -64,6 +64,5 @@ ${ECHO} mod_wsgi-express start-server \
--directory-index index.html \
--include-file httpd.conf \
--request-timeout 180 \
--log-to-terminal \
--application-type module \
--entry-point typediff.wsgi
19 changes: 11 additions & 8 deletions typediff/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
from .config import LOGONROOT, TREEBANKLIST, FANGORNPATH, PROFILELIST
from .gram import get_grammar, get_grammars
from .delphin import (init_paths, JSONEncoder, load_hierarchy, Treebank,
dotdict, Profile)
dotdict, Profile, AceError)

# set LOGONROOT environment variable in case it's not set
init_paths(logonroot=LOGONROOT)

from .typediff import typediff_web, process_sentences, process_profiles

# TODO:
# create a setup.py file with executable entry points for the main functions of:
# -- typediff.py, grammar-utils.py, type-stats.py, parseit.py, queryex.py, eval.py


app = Flask(__name__)
app.json_encoder = JSONEncoder
Expand All @@ -39,9 +35,16 @@ def parse_types():

pos_inputs = request.form.get('pos-items', '').strip().splitlines()
neg_inputs = request.form.get('neg-items', '').strip().splitlines()
pos_items = process_sentences(pos_inputs, opts)
neg_items = process_sentences(neg_inputs, opts)
return jsonify(typediff_web(pos_items, neg_items, opts))
try:
pos_items = process_sentences(pos_inputs, opts)
neg_items = process_sentences(neg_inputs, opts)
except AceError as e:
return jsonify({'success':False, 'error': e.msg})

data = typediff_web(pos_items, neg_items, opts)
data['success'] = True

return jsonify(data)


@app.route('/process-profiles', methods=['POST'])
Expand Down
1 change: 0 additions & 1 deletion typediff/typediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def type_data():

def typediff_web(pos_items, neg_items, opts):
data = {
'success': True,
'pos-items' : pos_items,
'neg-items' : neg_items,
'descendants' : load_descendants(opts.grammar) if opts.desc else False,
Expand Down
3 changes: 2 additions & 1 deletion www/static/typediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ function processPostData(data) {
// applyFilters calls doDiff even when there are no filters();
applyFilters();
} else {
showStatusBox('#fail-box').html(data.error.replace(/\n/g, '<br/>'));
$('#fail-box').html(data.error.replace(/\n/g, '<br/>'));
showStatusBox('#fail-box');
updateButtons();
}
}
Expand Down

0 comments on commit bb8a094

Please sign in to comment.