From 6d8ee74212aec93a5393e22742ee2b00028d0ed1 Mon Sep 17 00:00:00 2001 From: Ned Letcher Date: Fri, 20 Oct 2017 15:30:50 +1100 Subject: [PATCH] it's workinggit status --- .gitignore | 2 +- run-web | 1 - .../settings_example.py | 43 --------------- .../config_hum.py => settings/settings_hum.py | 46 +--------------- typediff/__init__.py | 27 ---------- typediff/config.py | 52 +++++++++++++++++++ typediff/grammar_utils.py | 3 +- typediff/server.py | 3 +- www/static/typediff.js | 3 +- 9 files changed, 58 insertions(+), 122 deletions(-) rename configs/config_example.py => settings/settings_example.py (70%) rename configs/config_hum.py => settings/settings_hum.py (79%) create mode 100644 typediff/config.py diff --git a/.gitignore b/.gitignore index 48ee6ca..0198c25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .python-version -typediff/config.py +typediff/settings.py # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/run-web b/run-web index cde7865..4da5de2 100755 --- a/run-web +++ b/run-web @@ -7,7 +7,6 @@ export PYTHONPATH=${SCRIPTPATH}:${PYTHONPATH} mod_wsgi-express start-server \ --debug-mode \ --reload-on-changes \ - --url-alias /static www/static \ --document-root www \ --directory-index index.html \ --entry-point wsgi.py diff --git a/configs/config_example.py b/settings/settings_example.py similarity index 70% rename from configs/config_example.py rename to settings/settings_example.py index 81f53ab..e7ee297 100644 --- a/configs/config_example.py +++ b/settings/settings_example.py @@ -1,6 +1,3 @@ -import os - - """ This file contains configuration information that typediff needs to run, as well as options which can be customized. @@ -26,17 +23,6 @@ ACESRC = None -# The path to the directory of the typediff program. Needed for other -# defaults. You should not need to change this. -TYPEDIFF_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') - - -# Path where ACE output will be logged to. This is useful to change if -# your web server does not have write access to the typediff -# directory. -LOGPATH = os.path.join(TYPEDIFF_PATH, 'ace.log') - - # Grammars configured for use with typediff. The string '${LOGONROOT}' # Will be replaced with the value of the LOGONROOT environment # variable. @@ -124,32 +110,3 @@ 'json' : 'tanaka.json', } ) - - -# The order types are to be displayed in the output list and their -# color value for terminal output and web interface output -# repectively. -# -# format = (super_type_name, terminal_color, web_color) -# -# terminal_color must be one of {white, cyan, purple, blue, -# yellow, green, red} -# -# web_color can be any valid CSS color string -TYPES = ( - ('sign', 'red', 'rgba(255, 0, 0, 0.65)'), - ('head', 'purple', 'rgba(128, 0, 128, 0.65)'), - ('synsem', 'green', 'rgba(0, 128, 0, 0.65)'), - ('cat', 'blue', 'rgba(0, 0, 255, 0.65)'), - ('relation', 'cyan', 'rgba(0, 255, 255, 0.65)'), - ('predsort', 'yellow', 'rgba(255, 255, 0, 0.65)'), - ('other', 'white', 'rgba(255, 255, 255, 1.00)'), -) - - -# These should only need to be changed if you needed to compile -# thebinaries for your own environment. -TYPIFIERBIN = os.path.join(TYPEDIFF_PATH, 'bin', 'typifier') -DUMPHIERARCHYBIN = os.path.join(TYPEDIFF_PATH, 'bin', 'dumphierarchy') -ACEBIN = os.path.join(TYPEDIFF_PATH, 'bin', 'ace') -JSONPATH = 'www/json' diff --git a/configs/config_hum.py b/settings/settings_hum.py similarity index 79% rename from configs/config_hum.py rename to settings/settings_hum.py index 04c35a0..75e9645 100644 --- a/configs/config_hum.py +++ b/settings/settings_hum.py @@ -1,20 +1,12 @@ -import os - - """ This file contains configuration information that typediff needs to run, as well as options which can be customized. """ -# The path to the src directory in the typediff program. Needed for -# other defaults. You no not need to change this. -_SRC_PATH = os.path.dirname(os.path.realpath(__file__)) - - # Directory where dat, xml and pickle files are kept. # You'll want to change this if you don't want to store # large amounts of data in the installation directory. -DATAPATH = os.path.join(_SRC_PATH, '..', 'grammar-data') +DATAPATH = '/home/nejl/data/grammar-data' # Path to the directory where ace was compiled. Optionally used to @@ -27,17 +19,12 @@ LTDBPATH = '/ltdb/cgi-bin' -# Path where ACE output will be logged to. This is useful to change if -# your web server does not have write access to the typediff -# directory. -LOGPATH = os.path.join(_SRC_PATH, '..', 'ace.log') - - # For setting the LOGONROOT with apache, specify it here. Note that # this is not actually required for running the typediff interface and # can be left blank. LOGONROOT = '' + # Grammars configured for use with typediff. The string '${LOGONROOT}' # Will be replaced with the value of the LOGONROOT environment # variable. @@ -182,32 +169,3 @@ 'json' : 'tanaka.json', } ) - - -# The order types are to be displayed in the output list and their -# color value for terminal output and web interface output -# repectively. -# -# format = (super_type_name, terminal_color, web_color) -# -# terminal_color must be one of {white, cyan, purple, blue, -# yellow, green, red} -# -# web_color can be any valid CSS color string -TYPES = ( - ('sign', 'red', 'rgba(255, 0, 0, 0.65)'), - ('head', 'purple', 'rgba(128, 0, 128, 0.65)'), - ('synsem', 'green', 'rgba(0, 128, 0, 0.65)'), - ('cat', 'blue', 'rgba(0, 0, 255, 0.65)'), - ('relation', 'cyan', 'rgba(0, 255, 255, 0.65)'), - ('predsort', 'yellow', 'rgba(255, 255, 0, 0.65)'), - ('other', 'white', 'rgba(255, 255, 255, 1.00)'), -) - - -# These should only need to be changed if you needed to compile -# thebinaries for your own environment. -TYPIFIERBIN = os.path.join(_SRC_PATH, '..', 'bin', 'typifier') -DUMPHIERARCHYBIN = os.path.join(_SRC_PATH, '..', 'bin', 'dumphierarchy') -ACEBIN = os.path.join(_SRC_PATH, '..', 'bin', 'ace') -JSONPATH = 'www/json' diff --git a/typediff/__init__.py b/typediff/__init__.py index 635cb04..e69de29 100644 --- a/typediff/__init__.py +++ b/typediff/__init__.py @@ -1,27 +0,0 @@ -import os -import sys - -from . import config - -root_dir = os.path.dirname(os.path.abspath(__file__)) - -# default params -ACEBIN = os.path.join(root_dir, 'bin', 'ace') -TYPIFIERBIN = os.path.join(root_dir, 'bin', 'typifier') -DUMPHIERARCHYBIN = os.path.join(root_dir, 'bin', 'dumphierarchy') -JSONPATH = os.path.join(root_dir, 'www', 'json') -LOGPATH = os.path.join('ace.log') - - -# update any values from user config if set - -params = [ - 'ACEBIN', - 'JSONPATH', - 'LOGPATH', -] - -for param in params: - if hasattr(config, param): - value = getattr(config, param) - setattr(sys.modules[__name__], param, value) diff --git a/typediff/config.py b/typediff/config.py new file mode 100644 index 0000000..70d3294 --- /dev/null +++ b/typediff/config.py @@ -0,0 +1,52 @@ +import os +import sys + +from . import settings + +ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) + +# default params +ACEBIN = os.path.join(ROOT_PATH, 'bin', 'ace') +TYPIFIERBIN = os.path.join(ROOT_PATH, 'bin', 'typifier') +DUMPHIERARCHYBIN = os.path.join(ROOT_PATH, 'bin', 'dumphierarchy') +LOGPATH = os.path.join('ace.log') + +# The order types are to be displayed in the output list and their +# color value for terminal output and web interface output +# repectively. +# +# format = (super_type_name, terminal_color, web_color) +# +# terminal_color must be one of {white, cyan, purple, blue, +# yellow, green, red} +# +# web_color can be any valid CSS color string +TYPES = ( + ('sign', 'rgba(255, 0, 0, 0.65)', 'red'), + ('synsem', 'rgba(0, 128, 0, 0.65)', 'green'), + ('head', 'rgba(128, 0, 128, 0.65)', 'blue'), + ('cat', 'rgba(0, 0, 255, 0.65)', 'purple'), + ('relation', 'rgba(0, 255, 255, 0.65)', 'cyan'), + ('predsort', 'rgba(255, 255, 0, 0.65)', 'yellow'), + ('other', 'rgba(255, 255, 255, 1.00)', 'white'), +) + + +# get other values from settings any already defined above will be overridden + +PARAMS = [ + 'DATAPATH', + 'LOGONROOT', + 'FANGORNPATH', + 'LTDBPATH', + 'ACESRC', + 'GRAMMARLIST', + 'TREEBANKLIST', + 'ACEBIN', + 'JSONPATH', + 'LOGPATH', +] + +for param in PARAMS: + if hasattr(settings, param): + setattr(sys.modules[__name__], param, getattr(settings, param)) diff --git a/typediff/grammar_utils.py b/typediff/grammar_utils.py index 86d6d3d..ce595ba 100755 --- a/typediff/grammar_utils.py +++ b/typediff/grammar_utils.py @@ -5,9 +5,8 @@ import pickle from subprocess import Popen, PIPE -from typediff import ACEBIN, DUMPHIERARCHYBIN from .delphin import TypeHierarchy -from .config import ACESRC, DATAPATH +from .config import ACESRC, DATAPATH, ACEBIN, DUMPHIERARCHYBIN from .gram import get_grammar, get_grammars diff --git a/typediff/server.py b/typediff/server.py index bae7f73..26b2ee0 100644 --- a/typediff/server.py +++ b/typediff/server.py @@ -4,7 +4,7 @@ from flask import Flask, request, jsonify -from .config import LOGONROOT, TREEBANKLIST, FANGORNPATH, JSONPATH +from .config import LOGONROOT, TREEBANKLIST, FANGORNPATH from .gram import get_grammar, get_grammars from .delphin import init_paths, JSONEncoder, load_hierarchy, Treebank @@ -74,5 +74,4 @@ def load_data(): 'grammars' : get_grammars(), 'treebanks' : [Treebank(t) for t in TREEBANKLIST] , 'fangornpath' : FANGORNPATH, - 'jsonpath' : JSONPATH, }) diff --git a/www/static/typediff.js b/www/static/typediff.js index 0cbecef..aacda4a 100644 --- a/www/static/typediff.js +++ b/www/static/typediff.js @@ -526,7 +526,7 @@ function doDiff() { // check to see if the treebank has already been loaded // before making a request to fetch it if (treebank.data == undefined) - requests.push($.getJSON(JSONPATH + '/' + treebank.json)); + requests.push($.getJSON('/json/' + treebank.json)); } // process the array of requests @@ -1118,7 +1118,6 @@ function loadData(callback) { var posting = $.post('/load-data'); posting.done(function(data) { FANGORNPATH = data.fangornpath; - JSONPATH = data.jsonpath; GRAMMARS = {}; var $grammarInput = $('#grammar-input'); var $treebankInput = $('#treebank-input');