Commit e1e52e8f by Vik Paruchuri

Add directory creation for model file if it isn't found

parent 19010224
......@@ -10,7 +10,7 @@ sys.path.append(one_up_path)
import model_creator
import util_functions
def create(text,scores,prompt,model_path):
def create(text,score,prompt_string,model_path):
model_path=util_functions.create_model_path(model_path)
results = {'errors': [],'created' : False}
......@@ -23,6 +23,7 @@ def create(text,scores,prompt,model_path):
except:
results['errors'].append("feature extraction and model creation failed.")
try:
util_functions.create_directory(model_path)
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, args.model_path)
results['created']=True
except:
......
......@@ -12,18 +12,25 @@ import math
import nltk
import random
import pickle
from path import path
def create_model_path(model_path):
if not model_path.startswith("/") and not model_path.startswith("models/"):
model_path="/" + model_path
if not model.path.startswith("models"):
if not model_path.startswith("models"):
model_path = "models" + model_path
if not model_path.endswith(".p"):
model_path+=".p"
return model_path
def create_directory(model_path):
directory=path(model_path).dirname()
if not os.path.exists(directory):
os.makedirs(directory)
return True
def sub_chars(string):
"""
Strips illegal characters from a string. Used to sanitize input essays.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment