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