From fe832e949b6b8105a7cbd5eba30951df93c2d7fc Mon Sep 17 00:00:00 2001 From: wboag Date: Fri, 23 Feb 2018 14:14:06 -0500 Subject: [PATCH] tweaked a few python 2/3 syntaxes --- code/feature_extraction/word_features.py | 2 +- code/model.py | 12 +----------- code/tools.py | 12 ++++++++++++ requirements.txt | 2 -- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/code/feature_extraction/word_features.py b/code/feature_extraction/word_features.py index 6d3fbb9..993ea6f 100644 --- a/code/feature_extraction/word_features.py +++ b/code/feature_extraction/word_features.py @@ -39,7 +39,7 @@ def feature_length(word): def feature_stem_porter(word): try: return {('stem_porter', porter_st.stem(word)): 1} - except Exception, e: + except Exception as e: return {} def feature_mitre(word): diff --git a/code/model.py b/code/model.py index 39ca69e..e777444 100644 --- a/code/model.py +++ b/code/model.py @@ -18,20 +18,10 @@ from notes.documents import labels as tag2id, id2tag from tools import flatten, save_list_structure, reconstruct_list -from tools import print_str, print_vec, print_files +from tools import print_str, print_vec, print_files, write -# python2 needs to convert to unicdode, but thats default for python3 -if sys.version_info.major == 2: - tostr = unicode -else: - tostr = str - -def write(f, s): - f.write(tostr(s)) - - class ClinerModel: diff --git a/code/tools.py b/code/tools.py index 8a3a094..8e93f60 100644 --- a/code/tools.py +++ b/code/tools.py @@ -8,6 +8,7 @@ import os +import sys import errno import string import math @@ -232,6 +233,17 @@ def print_files(f, file_names): +# python2 needs to convert to unicdode, but thats default for python3 +if sys.version_info.major == 2: + tostr = unicode +else: + tostr = str + +def write(f, s): + f.write(tostr(s)) + + + def print_vec(f, label, vec): ''' print_vec() diff --git a/requirements.txt b/requirements.txt index 9b83111..e39980e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,3 @@ python-crfsuite numpy scipy scikit-learn -marisa-trie -repoze.lru