From 3f81414660d8b0290485bad18eb8d8ad4b71a702 Mon Sep 17 00:00:00 2001 From: Lance Lafontaine Date: Tue, 14 Nov 2017 09:15:52 -0500 Subject: [PATCH 1/2] [#65] Fixes all lints, and removes unused util functions --- src/backend_service/app.py | 3 --- src/backend_service/controllers/conversationController.py | 4 ---- src/backend_service/util.py | 8 -------- src/ml_service/feature_extraction/main.py | 2 +- src/ml_service/outputs/output.py | 2 +- src/ml_service/word_vectors/related_word_fetcher.py | 4 ++-- src/nlp_service/app.py | 4 +--- src/nlp_service/controllers/nlpController.py | 3 --- src/nlp_service/rasa/rasa_classifier.py | 4 ++-- src/nlp_service/util.py | 8 -------- 10 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 src/backend_service/util.py delete mode 100644 src/nlp_service/util.py diff --git a/src/backend_service/app.py b/src/backend_service/app.py index fed9bbb9..d1da07b9 100644 --- a/src/backend_service/app.py +++ b/src/backend_service/app.py @@ -3,9 +3,6 @@ from flask import Flask, request, abort, make_response, jsonify from flask_cors import CORS -import util -util.load_src_dir_to_sys_path() - from controllers import conversationController, legalController from postgresql_db import database diff --git a/src/backend_service/controllers/conversationController.py b/src/backend_service/controllers/conversationController.py index 94d0ff67..30976723 100644 --- a/src/backend_service/controllers/conversationController.py +++ b/src/backend_service/controllers/conversationController.py @@ -1,10 +1,6 @@ import json from flask import jsonify, abort, make_response - -import util - -util.load_src_dir_to_sys_path() from postgresql_db.models import * from services import nlpService, fileService from services.staticStrings import * diff --git a/src/backend_service/util.py b/src/backend_service/util.py deleted file mode 100644 index efe742a1..00000000 --- a/src/backend_service/util.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import sys - - -def load_src_dir_to_sys_path(): - parent_dir = os.getcwd() + "/.." - if parent_dir not in sys.path: - sys.path.insert(0, parent_dir) diff --git a/src/ml_service/feature_extraction/main.py b/src/ml_service/feature_extraction/main.py index 003a8d5f..765e16a7 100644 --- a/src/ml_service/feature_extraction/main.py +++ b/src/ml_service/feature_extraction/main.py @@ -8,7 +8,7 @@ from outputs.output import Log ''' -Improvement: +Improvement: 1 - Commands can be imporoved for this class. Now a little basic 2 - Perhaps clear previous output directories of the models etc. ''' diff --git a/src/ml_service/outputs/output.py b/src/ml_service/outputs/output.py index 243a3cb7..6cb36ccd 100644 --- a/src/ml_service/outputs/output.py +++ b/src/ml_service/outputs/output.py @@ -66,7 +66,7 @@ def save_text_file(self, filename, text, protocol='a'): __rel_path = filename file_path = os.path.join(self.__output_dir, __rel_path) file = open(file_path, protocol) - if not type(text) == list: + if not isinstance(text, list): text = [text] for lines in text: file.writelines(lines) diff --git a/src/ml_service/word_vectors/related_word_fetcher.py b/src/ml_service/word_vectors/related_word_fetcher.py index 3347ddf7..e3ee3b8d 100644 --- a/src/ml_service/word_vectors/related_word_fetcher.py +++ b/src/ml_service/word_vectors/related_word_fetcher.py @@ -7,7 +7,7 @@ from outputs.output import Log """ -This python module is used to fill in missing keys from the +This python module is used to fill in missing keys from the word vector model. This script attempts to find the closest similar word to the one given. The end goal will enable every word to be vectorized. @@ -18,7 +18,7 @@ """ Cache is a dictionary which stores keys -and maps them to values +and maps them to values """ cache = {} diff --git a/src/nlp_service/app.py b/src/nlp_service/app.py index 7b5b6c68..9c70af55 100644 --- a/src/nlp_service/app.py +++ b/src/nlp_service/app.py @@ -3,10 +3,8 @@ from flask import Flask from flask import request -import util from controllers import nlpController -util.load_src_dir_to_sys_path() from postgresql_db import database # Flask Setup @@ -18,7 +16,7 @@ """ These functions establishes HTTP routes for the core functionality of the src/nlp_service/controllers/nlpController.py The core functionality of classify_claim_category and classify_fact_value are explained further in the file mentioned above - + """ diff --git a/src/nlp_service/controllers/nlpController.py b/src/nlp_service/controllers/nlpController.py index 7dc15d9e..07ec1d7a 100644 --- a/src/nlp_service/controllers/nlpController.py +++ b/src/nlp_service/controllers/nlpController.py @@ -1,8 +1,5 @@ from flask import jsonify, abort, make_response -import util - -util.load_src_dir_to_sys_path() from postgresql_db.models import * from rasa.rasa_classifier import RasaClassifier from services import mlService diff --git a/src/nlp_service/rasa/rasa_classifier.py b/src/nlp_service/rasa/rasa_classifier.py index bc175bc4..5bd55238 100644 --- a/src/nlp_service/rasa/rasa_classifier.py +++ b/src/nlp_service/rasa/rasa_classifier.py @@ -26,7 +26,7 @@ def __init__(self): """ Training method that trains the data sets from facts and problem categories separately force_train=False will ensure the saved models are used - initialize_interpreters=True so the interpreters get initialized due to the models already being present + initialize_interpreters=True so the interpreters get initialized due to the models already being present result: creates models on trained data """ @@ -63,7 +63,7 @@ def classify_fact(self, fact_name, message): Training the interpreters one by one training_data_dir: Directory where data is held on our project interpreter_dict: dictionary of interpreters that will hold the interpreters - force_train: set ti either true or false so it knows if it should train new models (if empty dir) or use the old ones already present + force_train: set ti either true or false so it knows if it should train new models (if empty dir) or use the old ones already present initialized_interpreters: won't attempt to initialize interpreters if there are no models :returns dict of the fact with intent and entities """ diff --git a/src/nlp_service/util.py b/src/nlp_service/util.py deleted file mode 100644 index efe742a1..00000000 --- a/src/nlp_service/util.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import sys - - -def load_src_dir_to_sys_path(): - parent_dir = os.getcwd() + "/.." - if parent_dir not in sys.path: - sys.path.insert(0, parent_dir) From 5689ebb24337d3a877d4edc7b23faaf6c4181bf4 Mon Sep 17 00:00:00 2001 From: Lance Lafontaine Date: Tue, 14 Nov 2017 10:17:34 -0500 Subject: [PATCH 2/2] [#65] Removes reference to previously-removed util module --- src/backend_service/app_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/backend_service/app_test.py b/src/backend_service/app_test.py index cff95c33..562dc8be 100644 --- a/src/backend_service/app_test.py +++ b/src/backend_service/app_test.py @@ -4,9 +4,6 @@ from werkzeug.datastructures import FileStorage -import util - -util.load_src_dir_to_sys_path() from services import fileService from services.staticStrings import StaticStrings