-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.py
88 lines (80 loc) · 2.9 KB
/
args.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
import argparse
def process_args():
def percent_value(string):
val = float(string)
if 0.0 <= val <=1.0:
return val
else:
raise argparse.ArgumentTypeError(u"{0} is not from the range of 0..1".format(string))
def algorithm_name(string):
if string.lower() not in ('apriori', 'dic'):
raise argparse.ArgumentTypeError(u"No algorithm named {0} is known.".format(string))
else:
return string.lower()
def dic_granularity(string):
val = int(string)
#if val < 0:
#raise argparse.ArgumentTypeError(u"DIC's granularity must be positive or 0 for automatic M calculation.")
#else:
#return val
return val
def boolean(string):
if string == "False":
val = False
elif string == "True":
val = True
else:
int_val = int(string)
if int_val in (0, 1):
val = bool(int_val)
else:
raise argparse.ArgumentTypeError(u"{0} should be from \"True\" \\ \"False\" or \"0\" \\ \"1\" ".format(string))
return bool(val)
parser = argparse.ArgumentParser(
description=u"Induction of associative rules from datasets.",
epilog=u"For current version check 'https://github.com/PowerLlamas/associative_rules'."
)
parser.add_argument('infile',
help=u"input file")
parser.add_argument('outfile',
nargs='?',
help=u"output file"
)
parser.add_argument('-a, --algorithm',
dest='algorithm',
type=algorithm_name,
default='dic',
help=u"name of preferred algorithm - apriori or dic"
)
parser.add_argument('-r, --randomize',
dest='randomize',
type=boolean,
default='False',
help=u"Randomize transactions order or not"
)
parser.add_argument('-c, --confidence',
dest='minconf',
type=percent_value,
default=0.7,
help=u"minimum confidence (0..1)"
)
parser.add_argument('-s, --support',
dest="minsup",
type=percent_value,
default=0.4,
help=u"minimum support (0..1)"
)
parser.add_argument('-m',
dest="m",
type=dic_granularity,
default=100,
help=u"DIC's granularity or 0 for automatic (M = transactions number * min support"
)
parser.add_argument('-p, --partial',
dest="partial",
type=boolean,
default=False,
help=u"Switches DIC partial aproach: support is calculated using transactions counted till moment of support calculation."
)
return parser.parse_args()