-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAnalyzePattern.py
107 lines (102 loc) · 3.38 KB
/
AnalyzePattern.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 26 Apr 2016
@author: mbaxkhm4
Created at the University of Manchester, School of Computer Science
Licence GNU/GPL 3.0
'''
import re
def GetMean(value,res):
#Mean can be mean +- sd or mean (min,max)
#regex = (\d+\.\d+) [(](\d+\.*\d*)[ \-,]{1,}[ ]{0,}(\d+)[)]
if res == None:
res = {}
m = re.search(ur'(\d+\.*\d*)[? ]*[\-—–−––,]+(\d+\.*\d*)[ (]*(\d+\.*\d*)[? ]*[±][? ]*(\d+\.*\d*)[)]*',value)
if(m!=None):
range_min = m.group(1)
range_max = m.group(2)
mean = m.group(3)
sd = m.group(4)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
res["sd"] = sd
return res
m = re.search(ur'(\d+\.*\d*)[? ]*[±][? ]*(\d+\.*\d*)[ (]*(\d+\.*\d*)[? ]{0,}[\-—–−––,]+[ ]*(\d+\.*\d*)[)]*',value)
if(m!=None):
range_min = m.group(3)
range_max = m.group(4)
mean = m.group(1)
sd = m.group(2)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
res["sd"] = sd
return res
m = re.search(ur'(\d+\.*\d*)[? ]*[\(](\d+\.*\d*)[? ]{0,}[\-—–−––,]+(\d+\.*\d*)[\)]',value)
if(m!=None):
mean = m.group(1)
range_min = m.group(2)
range_max = m.group(3)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
return res
m = re.search(ur"[(](\d+\.*\d*)[? ]{0,}[\-—–−,]{1,}[? ]{0,}(\d+\.*\d*)[)][? ]*(\d+\.*\d*)",value)
if(m!=None):
range_min = m.group(1)
range_max = m.group(2)
mean = m.group(3)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
return res
m = re.search(ur"(\d+\.*\d*)[? ]{0,}[±]{1,}[? ]{0,}(\d+\.*\d*)",value)
if(m!=None):
mean = m.group(1)
sd = m.group(2)
res["mean"] = mean
res["sd"] = sd
return res
m = re.search(ur"(\d+\.*\d*)[? ]{0,}[(]{1,}[? ]{0,}(\d+\.*\d*)[)]{1,}",value)
if(m!=None):
mean = m.group(1)
sd = m.group(2)
res["mean"] = mean
res["sd"] = sd
return res
m = re.search("(\d+\.*\d*)",value)
if(m!=None):
mean = m.group(1)
res["mean"] = mean
return res
def GetRange(value,res):
if res == None:
res = {}
m = re.search(ur"(\d+\.*\d*)[? ]*[(](\d+\.*\d*)[? ]{0,}[\-—–−,]{1,}[? ]{0,}(\d+\.*\d*)[)]",value)
if(m!=None):
mean = m.group(1)
range_min = m.group(2)
range_max = m.group(3)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
return res
m = re.search(ur"[(](\d+\.*\d*)[? ]{0,}[\-—–−,;]{1,}[? ]{0,}(\d+)[)][? ]*(\d+\.*\d*)",value)
if(m!=None):
range_min = m.group(1)
range_max = m.group(2)
mean = m.group(3)
res["mean"] = mean
res["min"] = range_min
res["max"] = range_max
return res
m = re.search(ur"(\d+\.*\d*)[? ]{0,1}[\-—–−,;]{1,}[? ]{0,}(\d+\.*\d*)",value)
if(m!=None):
range_min = m.group(1)
range_max = m.group(2)
res["min"] = range_min
res["max"] = range_max
return res
return res