Commit 515420a9 by gradyward

Refactored the feature_extractor file to include just what we want it to, in a logical manner.

parent 4b8ef34b
...@@ -52,7 +52,7 @@ class EssaySet(object): ...@@ -52,7 +52,7 @@ class EssaySet(object):
self._cleaned_spelled_essays = [] self._cleaned_spelled_essays = []
self._tokens = [] self._tokens = []
self._pos_tags = [] self._pos_tags = []
self._cleaned_stem_essays = [] self._cleaned_stemmed_essays = []
self._generated = [] self._generated = []
self._prompt = "" self._prompt = ""
self._spelling_errors = [] self._spelling_errors = []
...@@ -147,7 +147,7 @@ class EssaySet(object): ...@@ -147,7 +147,7 @@ class EssaySet(object):
# from words in English. # from words in English.
porter = nltk.PorterStemmer() porter = nltk.PorterStemmer()
porter_tokens = " ".join([porter.stem(token) for token in tokens]) porter_tokens = " ".join([porter.stem(token) for token in tokens])
self._cleaned_stem_essays.append(porter_tokens) self._cleaned_stemmed_essays.append(porter_tokens)
return "Essay Added. Text: " + cleaned_essay + " Score: " + str(essay_score) return "Essay Added. Text: " + cleaned_essay + " Score: " + str(essay_score)
......
...@@ -66,36 +66,15 @@ def grade(grader_data, submission): ...@@ -66,36 +66,15 @@ def grade(grader_data, submission):
grader_features = None grader_features = None
try: try:
grader_features = extractor.generate_features(grader_set) grader_features = extractor.generate_features(grader_set)
feedback = extractor.generate_feedback(grader_set, grader_features)[0]
results['score'] = int(model.predict(grader_features)[0]) results['score'] = int(model.predict(grader_features)[0])
except: except:
error_message = "Could not extract features and score essay." error_message = "Could not extract features and score essay."
log.exception(error_message) log.exception(error_message)
results['errors'].append(error_message) results['errors'].append(error_message)
# If we have errors above, we do not continue here, but return the dictionary of failure # We have gotten through without an error, so we have been successful
if len(results['errors']) < 0: if len(results['errors']) < 0:
# We have gotten through without an error, so we have been successful
results['success'] = True results['success'] = True
# If the essay is just a copy of the prompt (or too similar), return a 0 as the score
if 'too_similar_to_prompt' in feedback and feedback['too_similar_to_prompt']:
results['score'] = 0
# Generate feedback, identifying a number of explicable problem areas
results['feedback'] = {
'spelling': feedback['spelling'],
'grammar': feedback['grammar'],
'markup-text': feedback['markup_text'],
}
if 'topicality' in feedback and 'prompt_overlap' in feedback:
results['feedback'].update({
'topicality': feedback['topicality'],
'prompt-overlap': feedback['prompt_overlap'],
})
# If we get here, that means there was 1+ error above. Set success to false and return # If we get here, that means there was 1+ error above. Set success to false and return
else: else:
results['success'] = False results['success'] = False
......
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