-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtom.py
executable file
·60 lines (51 loc) · 1.49 KB
/
tom.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
#!/usr/bin/env python
import read_questions
import re
import operator
import itertools
def colocation_ngram(q_id,n,direction='after'):
pass
#Is the answer one of the two numeric types?
def is_numeric(answer):
return(re.match('.*[0-9].*',answer))
#Is the answer a raw number?
def is_number(answer):
if is_numeric(answer):
return max(measurement_unit(answer))==''
else:
return False
#Is the answer a quantity?
def is_quantity(answer):
if is_numeric(answer):
return max(measurement_unit(answer))!=''
else:
return False
def measurement_unit(answer):
''' Take the full answer string and
return preceeding and proceeding potential units.
'''
if is_numeric(answer):
#If it's a number question, return potential units
return re.split('[0-9., ]*',answer)
else:
#If not, return nothing
return []
def find_units(q_id):
pass
def interactions(predictors,rmax=None):
''' Given a list of main effects, return a list of the interactions
of order up to rmax. If rmax is not given, all orders of
interactions are returned. The main effects are also returned.
'''
if rmax==None:
rmax=len(predictors)
beta=[]
for r in range(1,int(rmax)+1):
for combination in list(itertools.combinations(predictors,r=r)):
beta.append(reduce(operator.mul, combination))
return beta
def main():
# return map(measurement_unit,['about 570','saguaro,','Guglielmo Marconi','Africa','$1.5883'])
print interactions(range(2,5))
if __name__=='__main__':
main()