fix bug in matcher
This commit is contained in:
parent
abbc854a50
commit
bede501752
1 changed files with 11 additions and 5 deletions
|
|
@ -208,7 +208,8 @@ def model_to_graph(state: State, model: UUID, metamodel: UUID,
|
||||||
|
|
||||||
return names, graph
|
return names, graph
|
||||||
|
|
||||||
|
# This function returns a Generator of matches.
|
||||||
|
# The idea is that the user can iterate over the match set, lazily generating it: if only interested in the first match, the entire match set doesn't have to be generated.
|
||||||
def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
||||||
bottom = Bottom(state)
|
bottom = Bottom(state)
|
||||||
|
|
||||||
|
|
@ -228,7 +229,7 @@ def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
||||||
self.scd_model = UUID(bottom.state.read_value(type_model_id))
|
self.scd_model = UUID(bottom.state.read_value(type_model_id))
|
||||||
|
|
||||||
# constraints need to be checked at the very end, after a complete match is established, because constraint code may refer to matched elements by their name
|
# constraints need to be checked at the very end, after a complete match is established, because constraint code may refer to matched elements by their name
|
||||||
self.conditions_to_check = []
|
self.conditions_to_check = {}
|
||||||
|
|
||||||
def match_types(self, g_vtx_type, h_vtx_type):
|
def match_types(self, g_vtx_type, h_vtx_type):
|
||||||
# types only match with their supertypes
|
# types only match with their supertypes
|
||||||
|
|
@ -266,7 +267,8 @@ def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
||||||
|
|
||||||
python_code = services_od.read_primitive_value(self.bottom, g_vtx.node_id, pattern_mm)[0]
|
python_code = services_od.read_primitive_value(self.bottom, g_vtx.node_id, pattern_mm)[0]
|
||||||
|
|
||||||
self.conditions_to_check.append((python_code, h_vtx.node_id))
|
self.conditions_to_check[g_vtx.name] = python_code
|
||||||
|
# self.conditions_to_check.append((python_code, h_vtx.name, g_vtx.name))
|
||||||
|
|
||||||
return True # do be determined later, if it's actually a match
|
return True # do be determined later, if it's actually a match
|
||||||
|
|
||||||
|
|
@ -333,7 +335,12 @@ def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
||||||
_locals=loc)
|
_locals=loc)
|
||||||
|
|
||||||
# Attribute conditions
|
# Attribute conditions
|
||||||
for python_code, host_node in compare.conditions_to_check:
|
for pattern_name, host_name in name_mapping.items():
|
||||||
|
try:
|
||||||
|
python_code = compare.conditions_to_check[pattern_name]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
host_node = odapi.get(host_name)
|
||||||
if not check(python_code, {'this': host_node}):
|
if not check(python_code, {'this': host_node}):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -354,7 +361,6 @@ def match_od(state, host_m, host_mm, pattern_m, pattern_mm, pivot={}):
|
||||||
compare = RAMCompare(bottom, services_od.OD(host_mm, host_m, state))
|
compare = RAMCompare(bottom, services_od.OD(host_mm, host_m, state))
|
||||||
matcher = MatcherVF2(host, guest, compare)
|
matcher = MatcherVF2(host, guest, compare)
|
||||||
for m in matcher.match(graph_pivot):
|
for m in matcher.match(graph_pivot):
|
||||||
# print("\nMATCH:\n", m)
|
|
||||||
# Convert mapping
|
# Convert mapping
|
||||||
name_mapping = {}
|
name_mapping = {}
|
||||||
for guest_vtx, host_vtx in m.mapping_vtxs.items():
|
for guest_vtx, host_vtx in m.mapping_vtxs.items():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue