Commit 2b1bb375 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[cmd] models: fix typos

parent 36d2e96c
......@@ -40,8 +40,7 @@ import itertools as it
from logging import DEBUG
# Library imports
from cadbiom.models.guard_transitions.translators.chart_xml \
import MakeModelFromXmlFile
from cadbiom.models.guard_transitions.translators.chart_xml import MakeModelFromXmlFile
from cadbiom.models.biosignal.translators.gt_visitors import compile_event, compile_cond
from cadbiom.models.biosignal.sig_expr import *
from cadbiom.models.guard_transitions.analyser.ana_visitors import TableVisitor
......@@ -129,7 +128,7 @@ def get_transitions(parser):
# Some event have many clocks (like _h_2755) for the same
# ori/ext entities, so we have to extract them and their respective
# conditions
if trans.event == '':
if trans.event == "":
# null event without clock => StartNodes
# These nodes are used to resolve the problem of
# Strongly Connected Components (inactivated cycles in the graph)
......@@ -137,9 +136,9 @@ def get_transitions(parser):
# Avoids having SigConstExpr as event type in parse_event()
# I create a transition (SCC-__start__?),
# and a node (__start__?) for this case.
trans.event = 'SCC-' + trans.ori.name
trans.event = "SCC-" + trans.ori.name
events = {trans.event: trans.condition}
elif re.match('_h[\w]+', trans.event):
elif re.match("_h[\w]+", trans.event):
# 1 event (with 1 clock)
events = {trans.event: trans.condition}
else:
......@@ -154,18 +153,20 @@ def get_transitions(parser):
(
trans.ori.name, trans.ext.name,
{
'label': event, #+ '[' + trans.condition + ']',
'condition': condition,
}
"label": event, # + '[' + trans.condition + ']',
"condition": condition,
},
)
)
LOGGER.info("%s transitions loaded", len(transitions))
# Return a dict instead of defaultdict to avoid later confusions
#(masked errors) by searching a transition that was not in the model...
# (masked errors) by searching a transition that was not in the model...
assert transitions, "No transitions found in the model ! " \
assert transitions, (
"No transitions found in the model ! "
"Please check the names of events (_h_xxx)"
)
# Forge return value
return dict(transitions)
......@@ -230,14 +231,13 @@ def get_places_from_condition(condition):
# Replace parentheses first to make spaces in the string
# As operators are followed or preceded by parentheses, we can detect them
# without false positives (operator string inside an entity name)
replacement = ['(', ')', ' and ', ' or ', ' not ']
replacement = ["(", ")", " and ", " or ", " not "]
for operator in replacement:
condition = condition.replace(operator, ' ')
condition = condition.replace(operator, " ")
# Must be exempt of unauthorized chars
return {elem for elem in condition.split(' ')
if elem != ''}
return {elem for elem in condition.split(" ") if elem != ""}
def parse_event(event):
......@@ -273,16 +273,17 @@ def parse_event(event):
# sometimes SigConstExpr (just a True boolean) when clock is empty
# Ex: "when ()"
# So, we replace this boolean with an empty condition
right = '' if isinstance(expr.right_h, SigConstExpr) \
else str(expr.right_h)
right = "" if isinstance(expr.right_h, SigConstExpr) else str(expr.right_h)
return expr.left_h.name, right
if isinstance(expr, SigIdentExpr):
return expr.name, ''
return expr.name, ""
raise AssertionError("You should never have been there ! "
"Your expression type is not yet supported...")
raise AssertionError(
"You should never have been there ! "
"Your expression type is not yet supported..."
)
# def filterSigExpression(listOfExpr):
# return [filterSigExpression(expr) for expr in listOfExpr]
......@@ -296,11 +297,8 @@ def parse_event(event):
event_sexpr = compile_event(event, symb_tab, True, err)[0]
# Filter when events
g = (filterSigExpression(expr) \
for expr in treeToExprDefaultsList(event_sexpr))
eventToCondStr = \
{event_name: event_cond for event_name, event_cond in g}
g = (filterSigExpression(expr) for expr in treeToExprDefaultsList(event_sexpr))
eventToCondStr = {event_name: event_cond for event_name, event_cond in g}
LOGGER.debug("Clocks from event parsing: %s", eventToCondStr)
......@@ -330,9 +328,9 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
# Link the lexer to the model allows to avoid error in Reporter
# like: "-> dec -> Undeclared event or state"
# In practice this is time consuming and useless for what we want to do
#parser = MakeModelFromXmlFile(BIO_MOLDELS_DIR +
# parser = MakeModelFromXmlFile(BIO_MOLDELS_DIR +
# "Whole NCI-PID database translated into CADBIOM formalism(and).bcx")
#parser.model.accept(tvi)
# parser.model.accept(tvi)
symb_tab = tvi.tab_symb
# Get tree object from condition string
cond_sexpr = compile_cond(condition, symb_tab, err)
......@@ -347,8 +345,11 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
# - All frontier places, that are known entities that can be in conditions
# (not only in ori/ext) of transitions.
# So: authorized nodes = frontier_places + transition_nodes - inhibitor nodes
valid_paths = {tuple(path) for path in possible_paths
if (set(path) - inhibitors_nodes).issubset(all_nodes)}
valid_paths = {
tuple(path)
for path in possible_paths
if (set(path) - inhibitors_nodes).issubset(all_nodes)
}
# Debugging only
if LOGGER.getEffectiveLevel() == DEBUG:
......@@ -358,7 +359,9 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
LOGGER.debug("VALID PATHS: %s", valid_paths)
if len(valid_paths) > 1:
LOGGER.debug("Multiple valid paths in the model for: %s:\n%s", condition, valid_paths)
LOGGER.debug(
"Multiple valid paths in the model for: %s:\n%s", condition, valid_paths
)
for path in possible_paths:
pruned_places = set(path) - inhibitors_nodes
......@@ -444,7 +447,7 @@ def rec(tree, inhibitors_nodes):
lch = tree.left_h
op = tree.operator
op = tree.operator
rch = tree.right_h
# print('OZCJSH:', lch, op, rch, sep='\t\t')
lpaths = rec(lch, inhibitors_nodes)
......@@ -512,14 +515,14 @@ def get_places_data(places, model):
:rtype: <list <dict>>
"""
if model.xml_namespace == 'http://cadbiom.genouest.org/v2/':
if model.xml_namespace == "http://cadbiom.genouest.org/v2/":
# Fixed fields and default types
json_note_fieldnames = {
"uri": '',
"entityType": '',
"entityRef": '',
"location": '',
"names": list(), # Default type is 'list' for names (not '')
"uri": "",
"entityType": "",
"entityRef": "",
"location": "",
"names": list(), # Default type is 'list' for names (not '')
"xrefs": dict(),
}
# Init final dictionary
......@@ -532,24 +535,24 @@ def get_places_data(places, model):
json_data = json.loads(model.node_dict[place_name].note)
except ValueError as exc:
# Handle start nodes (name: __start__x)
if exc.message == 'No JSON object could be decoded':
if exc.message == "No JSON object could be decoded":
json_data = dict()
temp = \
{fieldname: json_data.get(fieldname, default_data)
for fieldname, default_data in json_note_fieldnames.items()}
temp = {
fieldname: json_data.get(fieldname, default_data)
for fieldname, default_data in json_note_fieldnames.items()
}
# Patch: Handle null values that should be avoided in cadbiom_writer.build_json_data()
temp["names"] = [name for name in temp["names"] if name]
# Add the cadbiom name (name attribute of xml element
temp['cadbiomName'] = place_name
temp["cadbiomName"] = place_name
data.append(temp)
return data
# v1 model: return only the name of the place
return [{'cadbiomName': place_name} for place_name in places]
return [{"cadbiomName": place_name} for place_name in places]
def get_identifiers_mapping(model_file, external_identifiers):
......@@ -576,8 +579,10 @@ def get_identifiers_mapping(model_file, external_identifiers):
places_data = get_places_data(parser.handler.node_dict.iterkeys(), model)
# {'xrefs': {'bdd': [values],}, 'cadbiomName': '',}
g = {place['cadbiomName']: frozenset(it.chain(*place['xrefs'].itervalues()))
for place in places_data}
g = {
place["cadbiomName"]: frozenset(it.chain(*place["xrefs"].itervalues()))
for place in places_data
}
# Mapping: external_identifiers as keys and Cadbiom names as values
mapping = defaultdict(set)
......@@ -589,10 +594,11 @@ def get_identifiers_mapping(model_file, external_identifiers):
not_found_identifiers = external_identifiers - set(mapping.keys())
if not_found_identifiers:
LOGGER.info("Some identifiers were not found (%s/%s): %s",
len(not_found_identifiers),
len(external_identifiers),
not_found_identifiers
LOGGER.info(
"Some identifiers were not found (%s/%s): %s",
len(not_found_identifiers),
len(external_identifiers),
not_found_identifiers,
)
return mapping
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment