Commit 19010224 by Vik Paruchuri

Add in ability to check if model file exists.

parent ab6de5d9
......@@ -8,10 +8,10 @@ one_up_path = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append(one_up_path)
import model_creator
import util_functions
def create(text,scores,prompt,model_path):
if not model_path.endswith(".p"):
model_path+=".p"
model_path=util_functions.create_model_path(model_path)
results = {'errors': [],'created' : False}
try:
......@@ -30,4 +30,14 @@ def create(text,scores,prompt,model_path):
return results
def check(model_path):
model_path=util_functions.create_model_path(model_path)
try:
with open(model_path) as f: pass
except IOError as e:
return False
return True
......@@ -15,6 +15,7 @@ base_path = os.path.dirname(__file__)
sys.path.append(base_path)
from essay_set import EssaySet
import util_functions
#Imports needed to unpickle grader data
import feature_extractor
......@@ -73,8 +74,7 @@ error_template = u"""
def grade(grader_path,grader_config,submission,sandbox=None):
if not grader_path.endswith(".p"):
grader_path+=".p"
grader_path=util_functions.create_model_path(grader_path)
log.debug("Grader path: {0}\n Submission: {1}".format(grader_path,submission))
results = {'errors': [],'tests': [],'correct': False,'score': 0, 'feedback' : ""}
......
......@@ -13,6 +13,17 @@ import nltk
import random
import pickle
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"):
model_path = "models" + model_path
if not model_path.endswith(".p"):
model_path+=".p"
return model_path
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