From 441e3d24daaa948c90135fb97f57316bcb168b6a Mon Sep 17 00:00:00 2001 From: William Boag Date: Tue, 17 Jul 2018 10:20:33 -0400 Subject: [PATCH] changed tmp dir to data/tmp instead of assuming /tmp (which is now compatible for windows) --- code/evaluate.py | 4 +++- code/feature_extraction/genia_dir/interface_genia.py | 3 ++- code/format.py | 3 ++- code/machine_learning/crf.py | 7 +++++-- code/model.py | 6 ++++-- data/tmp/.gitignore | 2 ++ 6 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 data/tmp/.gitignore diff --git a/code/evaluate.py b/code/evaluate.py index 0c02267..1045341 100644 --- a/code/evaluate.py +++ b/code/evaluate.py @@ -88,7 +88,9 @@ def main(): # create temporary directory for these files - tempdir_name = '/tmp/cliner_eval_%d' % random.randint(0,256) + cliner_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + tmp_dir = os.path.join(cliner_dir, 'data', 'tmp') + tempdir_name = os.path.join(tmp_dir, 'cliner_eval_%d' % random.randint(0,256)) #print tempdir_name #text_dir = os.path.join(tempdir_name, 'text/') diff --git a/code/feature_extraction/genia_dir/interface_genia.py b/code/feature_extraction/genia_dir/interface_genia.py index 241e8c9..4d29907 100644 --- a/code/feature_extraction/genia_dir/interface_genia.py +++ b/code/feature_extraction/genia_dir/interface_genia.py @@ -22,7 +22,8 @@ from subprocess import Popen, PIPE from .genia_cache import GeniaCache -tmp_dir = '/tmp' +cliner_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +tmp_dir = os.path.join(cliner_dir, 'data', 'tmp') def genia(geniatagger, data): diff --git a/code/format.py b/code/format.py index 12b2385..22e2ce5 100644 --- a/code/format.py +++ b/code/format.py @@ -16,7 +16,8 @@ import tempfile -tmp_dir = '/tmp' +cliner_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +tmp_dir = os.path.join(cliner_dir, 'data', 'tmp') def create_filename(odir, bfile, extension): fname = os.path.basename(bfile) + extension diff --git a/code/machine_learning/crf.py b/code/machine_learning/crf.py index cfa019a..0b81333 100755 --- a/code/machine_learning/crf.py +++ b/code/machine_learning/crf.py @@ -16,6 +16,9 @@ from tools import compute_performance_stats from feature_extraction.read_config import enabled_modules +cliner_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +tmp_dir = os.path.join(cliner_dir, 'data', 'tmp') + def format_features(rows, labels=None): retVal = [] @@ -125,7 +128,7 @@ def train(X, Y, val_X=None, val_Y=None, test_X=None, test_Y=None): trainer.append(xseq, yseq) # Train the model - os_handle,tmp_file = tempfile.mkstemp(dir='/tmp', suffix="crf_temp") + os_handle,tmp_file = tempfile.mkstemp(dir=tmp_dir, suffix="crf_temp") trainer.train(tmp_file) # Read the trained model into a string (so it can be pickled) @@ -173,7 +176,7 @@ def predict(clf, X): feats = format_features(X) # Dump the model into a temp file - os_handle,tmp_file = tempfile.mkstemp(dir='/tmp', suffix="crf_temp") + os_handle,tmp_file = tempfile.mkstemp(dir=tmp_dir, suffix="crf_temp") with open(tmp_file, 'wb') as f: f.write(clf) diff --git a/code/model.py b/code/model.py index e777444..8c41689 100644 --- a/code/model.py +++ b/code/model.py @@ -21,7 +21,8 @@ from tools import print_str, print_vec, print_files, write - +cliner_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +tmp_dir = os.path.join(cliner_dir, 'data', 'tmp') class ClinerModel: @@ -431,7 +432,8 @@ def generic_train(p_or_n, train_sents, train_labels, use_lstm, val_sents=None, v print ("START TRAINING") - parameters['conll_like_result_folder']='/tmp/cliner_eval_%d' % random.randint(0,256)+os.sep + eval_dir = os.path.join(tmo_dir, 'cliner_eval_%d' % random.randint(0,256)+os.sep) + parameters['conll_like_result_folder']=eval_dir) test_temp = os.path.join(parameters['conll_like_result_folder'], 'test/') diff --git a/data/tmp/.gitignore b/data/tmp/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/tmp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore