Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
giritheja committed Mar 20, 2017
1 parent 3e63728 commit 1e83b66
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 82 deletions.
4 changes: 2 additions & 2 deletions core/domain/classifier_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ def validate(self):
raise utils.ValidationError(
'Expected cached_classifier_data to be a dict, received %s' %(
self.cached_classifier_data))
sc = classifier_registry.Registry.get_classifier_by_id(
classifier_class = classifier_registry.Registry.get_classifier_by_id(
self.algorithm_id)
sc.validate(self.cached_classifier_data)
classifier_class.validate(self.cached_classifier_data)
2 changes: 1 addition & 1 deletion core/domain/classifier_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ def test_update_of_classifiers(self):
classifier = classifier_services.get_classifier_by_id(
classifier_id)
self.assertEqual(classifier.exp_id, exp_id)
self.assertEqual(classifier.state_name, test_state)
self.assertEqual(classifier.state_name, test_state_name)
143 changes: 64 additions & 79 deletions extensions/classifiers/LDAStringClassifier/LDAStringClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,82 +607,67 @@ def validate(self, classifier_data):
classifier.
"""

if not isinstance(classifier_data['_alpha'], float):
raise utils.ValidationError(
('Expected alpha to be a float, received %f' %
classifier_data['_alpha']))

if not isinstance(classifier_data['_beta'], float):
raise utils.ValidationError(
('Expected beta to be a float, received %f' %
classifier_data['_beta']))

if not isinstance(classifier_data['_prediction_threshold'], float):
raise utils.ValidationError(
('Expected prediction_threshold to be a float, received %f' %
classifier_data['_prediction_threshold']))

if not isinstance(classifier_data['_training_iterations'], int):
raise utils.ValidationError(
('Expected training_iterations to be a int, received %d' %
classifier_data['_training_iterations']))

if not isinstance(classifier_data['_prediction_iterations'], int):
raise utils.ValidationError(
('Expected prediction_iterations to be a int, received %d' %
classifier_data['_prediction_iterations']))

if not isinstance(classifier_data['_num_labels'], int):
raise utils.ValidationError(
('Expected num_labels to be a int, received %d' %
classifier_data['_num_labels']))

if not isinstance(classifier_data['_num_docs'], int):
raise utils.ValidationError(
('Expected num_docs to be a int, received %d' %
classifier_data['_num_docs']))

if not isinstance(classifier_data['_num_words'], int):
raise utils.ValidationError(
('Expected num_words to be a int, received %d' %
classifier_data['_num_words']))

if not isinstance(classifier_data['_label_to_id'], dict):
raise utils.ValidationError(
('Expected label_to_id to be a dict, received %s' %
classifier_data['_label_to_id']))

if not isinstance(classifier_data['_word_to_id'], dict):
raise utils.ValidationError(
('Expected word_to_id to be a dict, received %s' %
classifier_data['_word_to_id']))

if not isinstance(classifier_data['_w_dp'], list):
raise utils.ValidationError(
('Expected w_dp to be a list, received %s' %
classifier_data['_w_dp']))

if not isinstance(classifier_data['_b_dl'], list):
raise utils.ValidationError(
('Expected b_dl to be a list, received %s' %
classifier_data['_b_dl']))

if not isinstance(classifier_data['_l_dp'], list):
raise utils.ValidationError(
('Expected l_dp to be a list, received %s' %
classifier_data['_l_dp']))

if not isinstance(classifier_data['_c_dl'], list):
raise utils.ValidationError(
('Expected c_dl to be a list, received %s' %
classifier_data['_c_dl']))

if not isinstance(classifier_data['_c_lw'], list):
raise utils.ValidationError(
('Expected c_lw to be a list, received %s' %
classifier_data['_c_lw']))

if not isinstance(classifier_data['_c_l'], list):
raise utils.ValidationError(
('Expected c_l to be a list, received %s' %
classifier_data['_c_l']))
float_properties = [
"_alpha",
"_beta",
"_prediction_threshold"
]
int_properties = [
"_training_iterations",
"_prediction_iterations",
"_num_labels",
"_num_docs",
"_num_words"
]
dict_properties = [
"_label_to_id",
"_word_to_id"
]
list_properties = [
"_w_dp",
"_b_dl",
"_l_dp",
"_c_dl",
"_c_lw",
"_c_l"
]

for float_property in float_properties:
if not float_property in classifier_data.keys():
raise utils.ValidationError(
'Expected %s to be a key in classifier_data' %
float_property)
if not isinstance(classifier_data[float_property], float):
raise utils.ValidationError(
('Expected %s to be a float, received %f' %
float_property, classifier_data[float_property]))

for int_property in int_properties:
if not int_property in classifier_data.keys():
raise utils.ValidationError(
'Expected %s to be a key in classifier_data' %
int_property)
if not isinstance(classifier_data[int_property], int):
raise utils.ValidationError(
('Expected %s to be a int, received %d' %
int_property, classifier_data[int_property]))

for dict_property in dict_properties:
if not dict_property in classifier_data.keys():
raise utils.ValidationError(
'Expected %s to be a key in classifier_data' %
dict_property)
if not isinstance(classifier_data[dict_property], dict):
raise utils.ValidationError(
('Expected %s to be a dict, received %s' %
dict_property, classifier_data[dict_property]))

for list_property in list_properties:
if not list_property in classifier_data.keys():
raise utils.ValidationError(
'Expected %s to be a key in classifier_data' %
float_property)
if not isinstance(classifier_data[list_property], list):
raise utils.ValidationError(
('Expected %s to be a list, received %s' %
list_property, classifier_data[list_property]))

0 comments on commit 1e83b66

Please sign in to comment.