Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ease
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ease
Commits
0a4d39d7
Commit
0a4d39d7
authored
Jun 13, 2014
by
gradyward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exception Handling for the Essay Set module
Other small changes.
parent
6c1aa5f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
13 deletions
+26
-13
ease/create.py
+1
-1
ease/errors.py
+3
-1
ease/essay_set.py
+16
-8
ease/util_functions.py
+6
-3
No files found.
ease/create.py
View file @
0a4d39d7
...
...
@@ -69,7 +69,7 @@ def create(examples, scores, prompt_string, dump_data=False):
# Create an essay set object that encapsulates all the essays and alternate representations (tokens, etc)
try
:
essay_set
=
_create_essay_set
(
examples
,
scores
,
prompt_string
)
except
(
E
xampleCreation
RequestError
,
ExampleCreationInternalError
)
as
ex
:
except
(
E
ssaySet
RequestError
,
ExampleCreationInternalError
)
as
ex
:
msg
=
"Essay Set Creation failed (likely due to an error in essay cleaning/parsing) {}"
.
format
(
ex
)
results
[
'errors'
]
.
append
(
msg
)
log
.
exception
(
msg
)
...
...
ease/errors.py
View file @
0a4d39d7
...
...
@@ -2,7 +2,7 @@
Errors for the EASE repository
"""
class
E
xampleCreation
RequestError
(
Exception
):
class
E
ssaySet
RequestError
(
Exception
):
pass
class
ExampleCreationInternalError
(
Exception
):
...
...
@@ -18,3 +18,4 @@ class ClassifierTrainingInternalError(Exception):
pass
class
CreateRequestError
(
Exception
):
pass
\ No newline at end of file
ease/essay_set.py
View file @
0a4d39d7
...
...
@@ -8,6 +8,7 @@ import sys
import
random
import
os
import
logging
from
errors
import
*
base_path
=
os
.
path
.
dirname
(
__file__
)
sys
.
path
.
append
(
base_path
)
...
...
@@ -76,6 +77,9 @@ class EssaySet(object):
Returns:
A string confirmation that essay was added.
Raises
EssaySetRequestError
"""
# Get maximum current essay id (the newest essay), or set to 0 if this is the first essay added
...
...
@@ -91,9 +95,10 @@ class EssaySet(object):
except
UnicodeError
:
try
:
essay_text
=
(
essay_text
.
decode
(
'utf-8'
,
'replace'
))
.
encode
(
'ascii'
,
'ignore'
)
except
UnicodeError
:
log
.
exception
(
"Could not parse essay into ascii."
)
raise
except
UnicodeError
as
ex
:
str
=
"Could not parse essay text into ascii: {}"
.
format
(
ex
)
log
.
exception
(
str
)
raise
EssaySetRequestError
(
ex
)
# Validates that score is an integer and essay_text is a string.
try
:
...
...
@@ -101,15 +106,15 @@ class EssaySet(object):
essay_text
=
str
(
essay_text
)
essay_generated
=
int
(
essay_generated
)
except
TypeError
:
log
.
exception
(
"Invalid type for essay score : {0} or essay text : {1}"
.
format
(
type
(
essay_score
),
type
(
essay_text
))
)
raise
str
=
"Invalid type for essay score : {0} or essay text : {1}"
.
format
(
type
(
essay_score
),
type
(
essay_text
))
log
.
exception
(
str
)
raise
EssaySetRequestError
(
str
)
# Validates that essay generated is 0 or 1
if
essay_generated
!=
0
and
essay_generated
!=
1
:
ex
=
"Invalid value for essay_generated ({}). Value must be 0 or 1."
.
format
(
essay_generated
)
log
.
exception
(
ex
)
raise
util_functions
.
Inpu
tError
(
ex
)
raise
EssaySetReques
tError
(
ex
)
# Validates to make sure that the essay is at least five characters long.
if
len
(
essay_text
)
<
5
:
...
...
@@ -159,8 +164,11 @@ class EssaySet(object):
Returns:
(str): The prompt, if it was stored successfully.
Raises:
InputError
"""
if
(
isinstance
(
prompt_text
,
basestring
)
):
if
isinstance
(
prompt_text
,
basestring
):
self
.
_prompt
=
util_functions
.
sub_chars
(
prompt_text
)
else
:
raise
util_functions
.
InputError
(
prompt_text
,
"Invalid prompt. Need to enter a string value."
)
...
...
ease/util_functions.py
View file @
0a4d39d7
...
...
@@ -89,9 +89,9 @@ def spell_correct(string):
incorrect
=
p
.
readlines
()
p
.
close
()
except
Exception
:
log
.
exception
(
"aspell
process failed; could not spell check"
)
# Return original string if aspell fails
except
Exception
as
ex
:
log
.
exception
(
"aspell
spell checking was not run, because it failed with the exception: {}"
.
format
(
ex
)
)
#
DESIGN CHOICE:
Return original string if aspell fails
return
string
,
0
,
string
finally
:
...
...
@@ -201,6 +201,9 @@ def get_vocab(essays, scores, max_features_pass_1=750, max_features_pass_2=200):
class
InputError
(
Exception
):
"""
A class to report to the user that one of their inputs was incorrect.
"""
def
__init__
(
self
,
expr
,
msg
):
self
.
expr
=
expr
self
.
msg
=
msg
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment