python-clired 6.0.8__py3-none-any.whl → 6.0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- blocks/common_details.py +3 -3
- blocks/mine/bellman.py +60 -0
- blocks/mine/classAction.py +449 -0
- blocks/mine/classCandidates.py +45 -22
- blocks/mine/classCharbon.py +23 -9
- blocks/mine/classCharbonGMiss.py +77 -42
- blocks/mine/classCharbonGStd.py +135 -67
- blocks/mine/classCharbonGreedy.py +168 -70
- blocks/mine/classCharbonTAlt.py +83 -89
- blocks/mine/classCharbonTLayer.py +40 -33
- blocks/mine/classCharbonXFIM.py +113 -185
- blocks/mine/classCol.py +237 -69
- blocks/mine/classConstraints.py +75 -403
- blocks/mine/classContent.py +244 -210
- blocks/mine/classData.py +114 -42
- blocks/mine/classMiner.py +51 -433
- blocks/mine/classMultiprocMiner.py +311 -0
- blocks/mine/classPackage.py +349 -247
- blocks/mine/classPreferencesManager.py +79 -34
- blocks/mine/classProps.py +200 -166
- blocks/mine/classQuery.py +678 -550
- blocks/mine/classRedescription.py +120 -33
- blocks/mine/classSParts.py +50 -12
- blocks/mine/csv_reader.py +20 -9
- blocks/mine/exec_clired.py +74 -21
- blocks/mine/factMiner.py +94 -0
- blocks/mine/fim_mod_eclat.py +130 -0
- blocks/mine/fim_mod_fpgrowth.py +1037 -0
- blocks/mine/fim_org_fpgrowth.py +279 -0
- blocks/mine/inout_confdef.xml +21 -10
- blocks/mine/miner_confdef.xml +162 -14
- blocks/mine/prepare_polygons.py +2 -2
- blocks/mine/redquery_parser.py +25 -6
- blocks/mine/toolLog.py +16 -2
- blocks/mine/toolXML.py +75 -25
- blocks/work/classWorkClient.py +1 -1
- blocks/work/classWorkLocal.py +1 -1
- blocks/work/classWorkServer.py +1 -1
- exec_client.py +2 -3
- {python_clired-6.0.8.dist-info → python_clired-6.0.9.dist-info}/METADATA +18 -10
- python_clired-6.0.9.dist-info/RECORD +78 -0
- {python_clired-6.0.8.dist-info → python_clired-6.0.9.dist-info}/WHEEL +1 -1
- {python_clired-6.0.8.dist-info → python_clired-6.0.9.dist-info}/entry_points.txt +0 -1
- blocks/mine/actions_rdefs_basic.txt +0 -27
- blocks/mine/fields_rdefs_basic.txt +0 -57
- blocks/mine/fields_rdefs_more.txt +0 -3
- blocks/mine/fields_vdefs_basic.txt +0 -16
- blocks/mine/fields_vdefs_more.txt +0 -13
- python_clired-6.0.8.dist-info/RECORD +0 -76
- {python_clired-6.0.8.dist-info → python_clired-6.0.9.dist-info}/LICENSE +0 -0
- {python_clired-6.0.8.dist-info → python_clired-6.0.9.dist-info}/top_level.txt +0 -0
blocks/common_details.py
CHANGED
|
@@ -9,14 +9,14 @@ def getVersion():
|
|
|
9
9
|
ctime = time.strftime("%a, %d %b %Y %T", time.localtime(os.path.getmtime(CHANGELOG_FILE)))
|
|
10
10
|
with open(CHANGELOG_FILE) as fp:
|
|
11
11
|
for line in fp:
|
|
12
|
-
tmp = re.match("^v(?P<version>[0-9\.]*)$", line)
|
|
12
|
+
tmp = re.match(r"^v(?P<version>[0-9\.]*)$", line)
|
|
13
13
|
if tmp is not None:
|
|
14
14
|
if version is None:
|
|
15
15
|
version = tmp.group("version")
|
|
16
16
|
else:
|
|
17
17
|
return version, changes, ctime
|
|
18
|
-
elif version is not None and len(line.strip("
|
|
19
|
-
changes.append(line.strip("
|
|
18
|
+
elif version is not None and len(line.strip("\n*- ")) > 0:
|
|
19
|
+
changes.append(line.strip("\n*- "))
|
|
20
20
|
|
|
21
21
|
return "", [], time.strftime("%a, %d %b %Y %T", time.localtime())
|
|
22
22
|
|
blocks/mine/bellman.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from scipy import stats
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def bin_segments(V_,max_k,criterion):
|
|
8
|
+
V = stats.zscore(V_)
|
|
9
|
+
T,I,J = np.unique(V,return_index=True,return_inverse=True)
|
|
10
|
+
occurrences = np.histogram(J,max(J+1))
|
|
11
|
+
n = len(T)
|
|
12
|
+
cumocc = np.insert(np.cumsum(occurrences[0]),0,0)
|
|
13
|
+
cs = np.insert(np.cumsum(np.multiply(T,occurrences[0])),0,0)
|
|
14
|
+
css = np.insert(np.cumsum(np.multiply(np.power(T,2),occurrences[0])),0,0)
|
|
15
|
+
sigma = np.zeros((n,n))
|
|
16
|
+
for i in range(n):
|
|
17
|
+
for j in range(i+1,n):
|
|
18
|
+
sigma[i,j] = (css[j+1] - css[i]) - (1/(cumocc[j+1]-cumocc[i]))*np.power((cs[j+1]-cs[i]),2)
|
|
19
|
+
E = np.zeros((max_k,n))
|
|
20
|
+
E[0,:] = sigma[0,:]
|
|
21
|
+
B = np.zeros((max_k,n))
|
|
22
|
+
cost = np.inf
|
|
23
|
+
for k in range(1,max_k):
|
|
24
|
+
for cutp in range(k,n):
|
|
25
|
+
E[k,cutp] = np.min(np.add(E[k-1,0:cutp],sigma[1:cutp+1,cutp]))
|
|
26
|
+
B[k,cutp] = int(np.argmin(np.add(E[k-1,0:cutp],sigma[1:cutp+1,cutp])))
|
|
27
|
+
if criterion == "manual":
|
|
28
|
+
c = E[k,n-1]
|
|
29
|
+
elif criterion == "BIC":
|
|
30
|
+
c = E[k,n-1] + k*np.log(len(V))
|
|
31
|
+
elif criterion == "AIC":
|
|
32
|
+
c = E[k,n-1] + 2*k
|
|
33
|
+
if c < cost:
|
|
34
|
+
opt_k = k
|
|
35
|
+
cost = c
|
|
36
|
+
else:
|
|
37
|
+
opt_k = k-1
|
|
38
|
+
break
|
|
39
|
+
B = B.astype(int)
|
|
40
|
+
cuts = [B[opt_k,n-1],n-1]
|
|
41
|
+
for j in range(opt_k-1,0,-1):
|
|
42
|
+
tmp = B[j,cuts[0]]
|
|
43
|
+
cuts = np.insert(cuts,0,tmp)
|
|
44
|
+
cuts = np.insert(np.unique(cuts),0,0)
|
|
45
|
+
buckets = np.zeros(n)
|
|
46
|
+
bounds = []
|
|
47
|
+
U = np.unique(V_)
|
|
48
|
+
for i in range(len(cuts)-1):
|
|
49
|
+
buckets[cuts[i]+1:cuts[i+1]+1] = i
|
|
50
|
+
bounds.append(U[cuts[i]+1])
|
|
51
|
+
bounds = bounds[1:]
|
|
52
|
+
assign = buckets[J]
|
|
53
|
+
|
|
54
|
+
return assign, bounds, cost, opt_k
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import toolXML
|
|
3
|
+
from classSParts import cmp_fun_map
|
|
4
|
+
|
|
5
|
+
except ModuleNotFoundError:
|
|
6
|
+
from . import toolXML
|
|
7
|
+
from .classSParts import cmp_fun_map
|
|
8
|
+
import pdb
|
|
9
|
+
|
|
10
|
+
def flipValue(v):
|
|
11
|
+
nv = v
|
|
12
|
+
if type(v) is bool:
|
|
13
|
+
v = not nv
|
|
14
|
+
elif nv is not None:
|
|
15
|
+
try:
|
|
16
|
+
v = -nv
|
|
17
|
+
except TypeError:
|
|
18
|
+
try:
|
|
19
|
+
v = reversed(nv)
|
|
20
|
+
except TypeError:
|
|
21
|
+
v = nv
|
|
22
|
+
return v
|
|
23
|
+
|
|
24
|
+
def doComparison(vA, cop, vB):
|
|
25
|
+
if cop in cmp_fun_map:
|
|
26
|
+
return cmp_fun_map[cop](vA, vB)
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
def getItemVal(exp, item, other=None, constraints=None, details={}, swap=False):
|
|
30
|
+
if other is not None and swap:
|
|
31
|
+
v = other.getExpProp(exp, details)
|
|
32
|
+
return v, "[%s:%s:]%s" % (other.getShortId(), exp, v)
|
|
33
|
+
if item is not None:
|
|
34
|
+
v = item.getExpProp(exp, details)
|
|
35
|
+
return v, "[%s:%s:]%s" % (item.getShortId(), exp, v)
|
|
36
|
+
|
|
37
|
+
def getPairVal(exp, item, other=None, constraints=None, details={}, swap=False):
|
|
38
|
+
if other is None:
|
|
39
|
+
raise Exception("Pair comparison missing other item")
|
|
40
|
+
if item is not None and other is not None:
|
|
41
|
+
if swap:
|
|
42
|
+
(item, other) = (other, item)
|
|
43
|
+
v = item.getExpPairProp(other, exp, details)
|
|
44
|
+
return v, "[%s:%s:%s]%s" % (item.getShortId(), exp, other.getShortId(), v)
|
|
45
|
+
|
|
46
|
+
class ACstrValue:
|
|
47
|
+
def_atts = {"flip": False, "type": None}
|
|
48
|
+
dynamic_types = {"item": getItemVal,
|
|
49
|
+
"pair": getPairVal}
|
|
50
|
+
def_types_parity = 0
|
|
51
|
+
types_parity = {"item": 1,
|
|
52
|
+
"pair": 2}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def __init__(self, value, cstrs=None, atts=None, is_default=False, value_type=None):
|
|
56
|
+
self.is_default = is_default
|
|
57
|
+
if cstrs is None:
|
|
58
|
+
self.cstrs = {}
|
|
59
|
+
else:
|
|
60
|
+
self.cstrs = cstrs
|
|
61
|
+
if atts is None:
|
|
62
|
+
self.atts = {}
|
|
63
|
+
else:
|
|
64
|
+
self.atts = atts
|
|
65
|
+
if toolXML.isXMLNode(value):
|
|
66
|
+
self.parseNode(value, value_type=value_type)
|
|
67
|
+
else:
|
|
68
|
+
self.value = value
|
|
69
|
+
if value_type is not None and self.atts.get("type") is None:
|
|
70
|
+
self.atts["type"] = value_type
|
|
71
|
+
|
|
72
|
+
def hasConstraints(self):
|
|
73
|
+
return len(self.cstrs) > 0
|
|
74
|
+
def getSimpleCstr(self):
|
|
75
|
+
if not self.isDynamicType() and len(self.cstrs) == 1:
|
|
76
|
+
c = list(self.cstrs.keys())[0]
|
|
77
|
+
if self.value == "{"+c+"}":
|
|
78
|
+
return c
|
|
79
|
+
return None
|
|
80
|
+
def isSimpleCstr(self):
|
|
81
|
+
return self.getSimpleCstr() is not None
|
|
82
|
+
|
|
83
|
+
def hasUnfilledConstraints(self):
|
|
84
|
+
return any([v is None for v in self.cstrs.values()])
|
|
85
|
+
def isDefault(self):
|
|
86
|
+
return self.is_default
|
|
87
|
+
def getType(self):
|
|
88
|
+
return self.atts.get("type")
|
|
89
|
+
def getParity(self):
|
|
90
|
+
return self.types_parity.get(self.getType(), self.def_types_parity)
|
|
91
|
+
def isDynamicType(self):
|
|
92
|
+
return self.getType() in self.dynamic_types
|
|
93
|
+
def getDynamicFunction(self):
|
|
94
|
+
return self.dynamic_types.get(self.getType())
|
|
95
|
+
def getAtt(self, k):
|
|
96
|
+
return self.atts.get(k)
|
|
97
|
+
|
|
98
|
+
def __repr__(self):
|
|
99
|
+
return "%s(%s, %s, %s, %s)" % (self.__class__.__name__, repr(self.value), repr(self.cstrs), repr(self.atts), self.is_default)
|
|
100
|
+
|
|
101
|
+
def parseNode(self, xml_node, value_type=None):
|
|
102
|
+
self.atts = toolXML.getAttsDict(xml_node, self.def_atts)
|
|
103
|
+
if "type" in self.atts and self.atts["type"] not in self.dynamic_types:
|
|
104
|
+
try:
|
|
105
|
+
att_vtype = eval(self.atts["type"])
|
|
106
|
+
except NameError:
|
|
107
|
+
del self.atts["type"]
|
|
108
|
+
else:
|
|
109
|
+
if value_type is None and type(att_vtype) is type:
|
|
110
|
+
self.atts["type"] = att_vtype
|
|
111
|
+
value_type = att_vtype
|
|
112
|
+
|
|
113
|
+
pieces = []
|
|
114
|
+
for child in toolXML.children(xml_node):
|
|
115
|
+
if toolXML.isElementNode(child):
|
|
116
|
+
if toolXML.tagName(child) == "cstr":
|
|
117
|
+
cstr = toolXML.getChildrenText(child)
|
|
118
|
+
pieces.append("{"+cstr+"}")
|
|
119
|
+
self.cstrs[cstr] = None
|
|
120
|
+
else:
|
|
121
|
+
txt = toolXML.getNodeText(child)
|
|
122
|
+
if txt is not None:
|
|
123
|
+
pieces.append(txt)
|
|
124
|
+
self.value = "".join(pieces)
|
|
125
|
+
if len(self.cstrs) == 0 and value_type is not None:
|
|
126
|
+
self.value = toolXML.parseToType(self.value, value_type=value_type)
|
|
127
|
+
|
|
128
|
+
def copy(self, constraints=None, override=True, cstrs=None):
|
|
129
|
+
if cstrs is None:
|
|
130
|
+
cstrs = dict(self.cstrs)
|
|
131
|
+
if constraints is not None:
|
|
132
|
+
self.fillCstrs(constraints=constraints, override=override, cstrs=cstrs)
|
|
133
|
+
return self.__class__(self.value, cstrs, dict(self.atts), self.is_default)
|
|
134
|
+
|
|
135
|
+
def fillCstrs(self, constraints, override=True, cstrs=None):
|
|
136
|
+
if cstrs is None: ## fill in-place
|
|
137
|
+
cstrs = self.cstrs
|
|
138
|
+
for c in self.cstrs.keys():
|
|
139
|
+
v = constraints.getCstr(c)
|
|
140
|
+
if v != cstrs.get(c) and (cstrs.get(c) is None or override):
|
|
141
|
+
cstrs[c] = v
|
|
142
|
+
return cstrs
|
|
143
|
+
def getFilledCstrs(self, constraints, override=True):
|
|
144
|
+
cstrs = dict(self.cstrs)
|
|
145
|
+
return self.fillCstrs(constraints=constraints, override=override, cstrs=cstrs)
|
|
146
|
+
|
|
147
|
+
def getRawValue(self, constraints=None, override=True):
|
|
148
|
+
if not self.isDynamicType() and not self.hasConstraints():
|
|
149
|
+
return self.value
|
|
150
|
+
c = self.getSimpleCstr()
|
|
151
|
+
if c is not None: ## a simple cstr, not a complex expression, return the corresponding value
|
|
152
|
+
if constraints is not None:
|
|
153
|
+
v = constraints.getCstr(c)
|
|
154
|
+
if v != self.cstrs[c] and (self.cstrs[c] is None or override):
|
|
155
|
+
return v
|
|
156
|
+
return self.cstrs[c]
|
|
157
|
+
return self.getExp(constraints=constraints, override=override)
|
|
158
|
+
|
|
159
|
+
def getExp(self, constraints=None, override=True):
|
|
160
|
+
if constraints is None:
|
|
161
|
+
cstrs = self.cstrs
|
|
162
|
+
else:
|
|
163
|
+
cstrs = self.getFilledCstrs(constraints, override=override)
|
|
164
|
+
return self.value.format(**cstrs)
|
|
165
|
+
|
|
166
|
+
def evaluateAndTrack(self, item=None, other=None, constraints=None, swap=False):
|
|
167
|
+
if self.isDynamicType():
|
|
168
|
+
dfun = self.getDynamicFunction()
|
|
169
|
+
exp = self.getExp(constraints)
|
|
170
|
+
v, t = dfun(exp, item, other, constraints, swap=swap)
|
|
171
|
+
if self.getAtt("flip"):
|
|
172
|
+
v = flipValue(v)
|
|
173
|
+
t = "NOT "+t
|
|
174
|
+
return v, t
|
|
175
|
+
else:
|
|
176
|
+
v = self.getRawValue(constraints)
|
|
177
|
+
if self.getAtt("flip"):
|
|
178
|
+
v = flipValue(v)
|
|
179
|
+
if v is not None:
|
|
180
|
+
return v, "%s" % v
|
|
181
|
+
return None, "??"
|
|
182
|
+
|
|
183
|
+
def evaluate(self, item=None, other=None, constraints=None, swap=False):
|
|
184
|
+
return self.evaluateAndTrack(item, other, constraints, swap)[0]
|
|
185
|
+
|
|
186
|
+
class AOperator(ACstrValue):
|
|
187
|
+
def_operator = "="
|
|
188
|
+
|
|
189
|
+
def __init__(self, value=None, cstrs={}, atts={}, is_default=False):
|
|
190
|
+
ACstrValue.__init__(self, value or self.def_operator, cstrs={}, atts={}, is_default=is_default or (value is None))
|
|
191
|
+
|
|
192
|
+
class AValue(ACstrValue):
|
|
193
|
+
pass
|
|
194
|
+
|
|
195
|
+
class AComparison:
|
|
196
|
+
|
|
197
|
+
def __init__(self, valueA, operator=None, valueB=None):
|
|
198
|
+
self.valueA = valueA
|
|
199
|
+
if operator is None:
|
|
200
|
+
self.operator = AOperator()
|
|
201
|
+
else:
|
|
202
|
+
self.operator = operator
|
|
203
|
+
if valueB is None:
|
|
204
|
+
self.valueB = valueA.copy()
|
|
205
|
+
else:
|
|
206
|
+
self.valueB = valueB
|
|
207
|
+
|
|
208
|
+
def hasUnfilledConstraints(self):
|
|
209
|
+
return self.valueA.hasUnfilledConstraints() or self.operator.hasUnfilledConstraints() or self.valueB.hasUnfilledConstraints()
|
|
210
|
+
|
|
211
|
+
def getParity(self):
|
|
212
|
+
return min(2, self.valueA.getParity()+self.valueB.getParity())
|
|
213
|
+
|
|
214
|
+
def __repr__(self):
|
|
215
|
+
return "%s(%s, %s, %s)" % (self.__class__.__name__, repr(self.valueA), repr(self.operator), repr(self.valueB))
|
|
216
|
+
|
|
217
|
+
def copy(self, constraints=None, override=True, cstrs=None):
|
|
218
|
+
return self.__class__(self.valueA.copy(constraints=constraints, override=override, cstrs=cstrs),
|
|
219
|
+
self.operator.copy(constraints=constraints, override=override, cstrs=cstrs),
|
|
220
|
+
self.valueB.copy(constraints=constraints, override=override, cstrs=cstrs))
|
|
221
|
+
|
|
222
|
+
def evaluate(self, item=None, other=None, constraints=None, swap=False):
|
|
223
|
+
vA = self.valueA.evaluate(item, other, constraints, swap=swap)
|
|
224
|
+
vB = self.valueB.evaluate(item, other, constraints, swap=not swap)
|
|
225
|
+
cop = self.operator.evaluate(constraints = constraints)
|
|
226
|
+
return doComparison(vA, cop, vB)
|
|
227
|
+
|
|
228
|
+
def evaluateAndTrack(self, item=None, other=None, constraints=None, swap=False):
|
|
229
|
+
vA, tA = self.valueA.evaluateAndTrack(item, other, constraints, swap=swap)
|
|
230
|
+
vB, tB = self.valueB.evaluateAndTrack(item, other, constraints, swap=not swap)
|
|
231
|
+
cop, tcop = self.operator.evaluateAndTrack(constraints = constraints)
|
|
232
|
+
v = doComparison(vA, cop, vB)
|
|
233
|
+
return v, "%s%s?%s -> %s" % (tA, tcop, tB, v)
|
|
234
|
+
|
|
235
|
+
def parseValueNode(xml_node):
|
|
236
|
+
return AValue(xml_node)
|
|
237
|
+
|
|
238
|
+
def parseComparisonNode(xml_node):
|
|
239
|
+
kwargs = {}
|
|
240
|
+
for child in toolXML.children(xml_node):
|
|
241
|
+
if kwargs is not None and toolXML.isElementNode(child):
|
|
242
|
+
if toolXML.tagName(child) == "value":
|
|
243
|
+
v = AValue(child)
|
|
244
|
+
if v is not None:
|
|
245
|
+
if "valueA" in kwargs:
|
|
246
|
+
if "valueB" in kwargs:
|
|
247
|
+
kwargs = None
|
|
248
|
+
else:
|
|
249
|
+
kwargs["valueB"] = v
|
|
250
|
+
else:
|
|
251
|
+
kwargs["valueA"] = v
|
|
252
|
+
elif toolXML.tagName(child) == "operator":
|
|
253
|
+
v = AOperator(child)
|
|
254
|
+
if v is not None:
|
|
255
|
+
if "operator" in kwargs:
|
|
256
|
+
kwargs = None
|
|
257
|
+
else:
|
|
258
|
+
kwargs["operator"] = v
|
|
259
|
+
if kwargs is not None and "valueA" in kwargs:
|
|
260
|
+
return AComparison(**kwargs)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def all_subclasses(cls):
|
|
264
|
+
return cls.__subclasses__() + [g for s in cls.__subclasses__() for g in all_subclasses(s)]
|
|
265
|
+
|
|
266
|
+
class ActionFactory(object):
|
|
267
|
+
|
|
268
|
+
top_class = None
|
|
269
|
+
substitute_comp_classes = []
|
|
270
|
+
|
|
271
|
+
@classmethod
|
|
272
|
+
def getActionClass(tcl, what, top_class=None):
|
|
273
|
+
if top_class is None:
|
|
274
|
+
top_class = tcl.top_class
|
|
275
|
+
for c in all_subclasses(top_class):
|
|
276
|
+
if c.what == what:
|
|
277
|
+
return c
|
|
278
|
+
return None
|
|
279
|
+
|
|
280
|
+
@classmethod
|
|
281
|
+
def initFromXml(tcl, xml_node=None):
|
|
282
|
+
what = toolXML.getAttData(xml_node, "what")
|
|
283
|
+
c = tcl.getActionClass(what)
|
|
284
|
+
if c is not None:
|
|
285
|
+
return c(xml_node=xml_node)
|
|
286
|
+
return None
|
|
287
|
+
|
|
288
|
+
@classmethod
|
|
289
|
+
def getSubstituteActionClass(tcl, from_ac, to_what):
|
|
290
|
+
for sc in tcl.substitute_comp_classes:
|
|
291
|
+
if isinstance(from_ac, sc):
|
|
292
|
+
return tcl.getActionClass(to_what, top_class=sc)
|
|
293
|
+
return None
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class Action(object):
|
|
297
|
+
|
|
298
|
+
what = "?"
|
|
299
|
+
def_args = {"reverse": False}
|
|
300
|
+
block_types = {"value": parseValueNode,
|
|
301
|
+
"comparison": parseComparisonNode}
|
|
302
|
+
action_parity = None
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def __init__(self, xml_node=None, args=None, blocks=None):
|
|
306
|
+
if args is None:
|
|
307
|
+
self.args = {}
|
|
308
|
+
else:
|
|
309
|
+
self.args = args
|
|
310
|
+
if blocks is None:
|
|
311
|
+
self.blocks = []
|
|
312
|
+
else:
|
|
313
|
+
self.blocks = blocks
|
|
314
|
+
|
|
315
|
+
if xml_node is not None:
|
|
316
|
+
if type(xml_node) is str:
|
|
317
|
+
xxml_node = toolXML.parseStr(xml_node)
|
|
318
|
+
self.parseActionNode(xxml_node)
|
|
319
|
+
else:
|
|
320
|
+
self.parseActionNode(xml_node)
|
|
321
|
+
self.setSrc(xml_node)
|
|
322
|
+
|
|
323
|
+
def getSrc(self):
|
|
324
|
+
return self.src
|
|
325
|
+
def setSrc(self, xml_node):
|
|
326
|
+
self.src = None
|
|
327
|
+
if type(xml_node) is str:
|
|
328
|
+
self.src = xml_node
|
|
329
|
+
elif toolXML.isXMLNode(xml_node):
|
|
330
|
+
self.src = toolXML.getSrc(xml_node)
|
|
331
|
+
|
|
332
|
+
def getWhat(self):
|
|
333
|
+
return self.what
|
|
334
|
+
def isWhat(self, what):
|
|
335
|
+
return self.what == what
|
|
336
|
+
|
|
337
|
+
def getDefArgsItems(self):
|
|
338
|
+
return self.def_args.items()
|
|
339
|
+
|
|
340
|
+
def getNbBlocks(self):
|
|
341
|
+
return len(self.blocks)
|
|
342
|
+
|
|
343
|
+
def parseBlockNode(self, xml_node):
|
|
344
|
+
if toolXML.isXMLNode(xml_node) and toolXML.isElementNode(xml_node) and toolXML.tagName(xml_node) in self.block_types:
|
|
345
|
+
b = self.block_types[toolXML.tagName(xml_node)](xml_node)
|
|
346
|
+
if self.action_parity is not None and b.getParity() > self.action_parity:
|
|
347
|
+
raise Warning("Too high parity for action %s! parity %s (%s)" % (self.getWhat(), b.getParity(), b))
|
|
348
|
+
return b
|
|
349
|
+
return None
|
|
350
|
+
|
|
351
|
+
def parseActionNode(self, xml_node=None):
|
|
352
|
+
if toolXML.isXMLNode(xml_node):
|
|
353
|
+
for k, dv in self.getDefArgsItems():
|
|
354
|
+
attv = toolXML.getAttData(xml_node, k, value_type=type(dv))
|
|
355
|
+
if attv is not None:
|
|
356
|
+
self.args[k] = AValue(attv, value_type=type(dv))
|
|
357
|
+
else:
|
|
358
|
+
tagn = toolXML.getTagNode(xml_node, k)
|
|
359
|
+
if tagn is not None:
|
|
360
|
+
self.args[k] = AValue(tagn, value_type=type(dv))
|
|
361
|
+
elif k not in self.args:
|
|
362
|
+
self.args[k] = AValue(dv, is_default=True, value_type=type(dv))
|
|
363
|
+
for child in toolXML.children(xml_node):
|
|
364
|
+
b = self.parseBlockNode(child)
|
|
365
|
+
if b is not None:
|
|
366
|
+
self.blocks.append(b)
|
|
367
|
+
|
|
368
|
+
def __repr__(self):
|
|
369
|
+
return "%s(%s, %s)" % (self.__class__.__name__, repr(self.args), repr(self.blocks))
|
|
370
|
+
|
|
371
|
+
def copy(self, constraints=None, override=True, to_class=None):
|
|
372
|
+
blocks = [b.copy(constraints=constraints, override=override) for b in self.blocks]
|
|
373
|
+
args = dict([(k, v.copy(constraints=constraints, override=override)) for (k,v) in self.args.items()])
|
|
374
|
+
if to_class is None:
|
|
375
|
+
to_class = self.__class__
|
|
376
|
+
new = to_class(args=args, blocks=blocks)
|
|
377
|
+
new.setSrc(self.getSrc())
|
|
378
|
+
return new
|
|
379
|
+
|
|
380
|
+
def fillCstrs(self, constraints, override=True, cstrs=None):
|
|
381
|
+
for b in self.blocks:
|
|
382
|
+
b.fillCstrs(constraints, override=override)
|
|
383
|
+
for k in self.args.keys():
|
|
384
|
+
self.args[k].fillCstrs(constraints, override=override)
|
|
385
|
+
|
|
386
|
+
def getSubstitutionClass(self, to_what):
|
|
387
|
+
return ActionFactory.getSubstituteActionClass(self, to_what)
|
|
388
|
+
|
|
389
|
+
def getSubstitutionWhat(self, to_what):
|
|
390
|
+
sc = ActionFactory.getSubstituteActionClass(self, to_what)
|
|
391
|
+
if sc is not None:
|
|
392
|
+
return sc.getWhat()
|
|
393
|
+
return None
|
|
394
|
+
def doSubstitution(self, to_what):
|
|
395
|
+
to_class = self.getSubstitutionClass(to_what)
|
|
396
|
+
if to_class is not None:
|
|
397
|
+
return self.copy(to_class=to_class)
|
|
398
|
+
return None
|
|
399
|
+
|
|
400
|
+
def getArg(self, k, constraints=None, override=True):
|
|
401
|
+
if k in self.args:
|
|
402
|
+
return self.args[k].getRawValue(constraints=constraints, override=override)
|
|
403
|
+
elif k in self.def_args:
|
|
404
|
+
return self.def_args[k]
|
|
405
|
+
|
|
406
|
+
### WARNING "reverse" argument must be taken into account in the parent calling function of evaluate (e.g. when sorting)
|
|
407
|
+
### but is already taken into account in computeSatisfy
|
|
408
|
+
def evaluateAndTrack(self, item=None, other=None, constraints=None, swap=False):
|
|
409
|
+
return [b.evaluateAndTrack(item, other=other, constraints=constraints, swap=swap) for b in self.blocks]
|
|
410
|
+
|
|
411
|
+
def evaluate(self, item=None, other=None, constraints=None, swap=False):
|
|
412
|
+
return [b.evaluate(item, other=other, constraints=constraints, swap=swap) for b in self.blocks]
|
|
413
|
+
|
|
414
|
+
def computeSatisfyAndTrack(self, item=None, other=None, constraints=None, swap=False):
|
|
415
|
+
reverse = self.getArg("reverse", constraints)
|
|
416
|
+
ts = []
|
|
417
|
+
for bi, b in enumerate(self.blocks):
|
|
418
|
+
v, t = b.evaluateAndTrack(item, other=other, constraints=constraints, swap=swap)
|
|
419
|
+
if not v:
|
|
420
|
+
return reverse, [(bi, t)]
|
|
421
|
+
ts.append((bi, t))
|
|
422
|
+
return not reverse, ts
|
|
423
|
+
|
|
424
|
+
def computeSatisfy(self, item=None, other=None, constraints=None, swap=False):
|
|
425
|
+
return self.computeSatisfyAndTrack(item, other, constraints, swap)[0]
|
|
426
|
+
|
|
427
|
+
class ActionUnary(Action):
|
|
428
|
+
action_parity = 1
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
class ActionBinary(Action):
|
|
432
|
+
action_parity = 2
|
|
433
|
+
|
|
434
|
+
ActionFactory.top_class = Action
|
|
435
|
+
ActionFactory.substitute_comp_classes = [ActionUnary, ActionBinary]
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
# sed '
|
|
439
|
+
# s:actionlist\t\(.*\)$:</actionlist>\n<actionlist><name>\1</name>:;
|
|
440
|
+
# s:^list\t\(.*\)$:<list><name>\1</name></list>:;
|
|
441
|
+
# s:^\([^\t]*\)\t\(.*\)$:<action what=\"\1\">\2</action>:;
|
|
442
|
+
# s!\([a-zA-Z0-9_][a-zA-Z0-9_]*\)\=\([0-9a-zA-Z_:][0-9a-zA-Z_:]*\)[ \t]!<\1>\2</\1>!g;
|
|
443
|
+
# s!PAIR:\([^ <>=\t]*\)!<value type=\"pair\">\1</value>!g;
|
|
444
|
+
# s!ITEM:\([^ <>=\t]*\)!<value type=\"item\">\1</value>!g;
|
|
445
|
+
# s!\(CSTR:[^: <\t]*\)!<value>\1</value>!g;
|
|
446
|
+
# s%</value>\([<>=][<>=]*\)<value>%</value><operator><![CDATA[\1]]></operator><value>%g;
|
|
447
|
+
# s!><\([a-z]\)!>\n<\1!g;
|
|
448
|
+
# s!CSTR:\([^: <\t]*\)!<cstr>\1</cstr>!g;
|
|
449
|
+
# s!\t!\n!g' actions_rdefs_basic_alt.txt > actions_rdefs_basic_alt.xml
|