-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaccard_configuration_parser.py
38 lines (31 loc) · 1.95 KB
/
jaccard_configuration_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import abstract_configuration_parser
from utils import constants as const
from utils import fuzzysetevaluator
from utils import paramethers as param
class JaccardConfigParser(abstract_configuration_parser.AbstractConfigurationParser):
requiredParameters = [param.ALPHA, param.BETA, param.GAMMA, param.EVALUATOR]
def parse(self, rawConfigMap):
print "Parsing config for jaccard_index"
for parameter in self.requiredParameters:
if parameter not in rawConfigMap.keys():
raise AttributeError(
"Missing '{}' parameter for jaccards method. Required params: {}".format(parameter,
self.requiredParameters))
alpha = self.parseToIntOrRaiseAttributeError(rawConfigMap[param.ALPHA],
"Can parse alpha paramether {}".format(rawConfigMap[param.ALPHA]))
beta = self.parseToIntOrRaiseAttributeError(rawConfigMap[param.BETA],
"Can parse beta paramether {}".format(rawConfigMap[param.BETA]))
gamma = self.parseToIntOrRaiseAttributeError(rawConfigMap[param.GAMMA],
"Can parse gamma paramether {}".format(rawConfigMap[param.GAMMA]))
evaluator = rawConfigMap[param.EVALUATOR]
if evaluator not in fuzzysetevaluator.SUPPORTED_EVALUATORS:
raise AttributeError(
"Not supported evaluator found: '{}'. Supported evaluators: {}".format(evaluator,
fuzzysetevaluator.SUPPORTED_EVALUATORS))
return {
const.METHOD_PARAM_NAME: const.JACCARD_INDEX,
param.ALPHA: alpha,
param.BETA: beta,
param.GAMMA: gamma,
param.EVALUATOR: evaluator
}