Coverage for skema/metal/model_linker/skema_model_linker/linkers/petrinet.py: 35%
23 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1from collections import defaultdict
2from typing import Iterable, Dict, List, Any
4from . import heuristics, AMRLinker
5from ..walkers import JsonDictWalker, JsonNode
6from ..walkers import PetriNetWalker
9class PetriNetLinker(AMRLinker):
11 def _generate_linking_sources(self, elements: Iterable[JsonNode]) -> Dict[str, List[Any]]:
12 ret = defaultdict(list)
13 for name, val, ix in elements:
14 if val is not None:
15 if (name == "states") or (name == "parameters" and 'name' in val):
16 key = val['name'].strip()
17 lower_case_key = key.lower()
19 if "description" in val:
20 ret[f"{key}: {val['description']}"] = val
21 else:
22 if lower_case_key in heuristics:
23 descs = heuristics[lower_case_key]
24 for desc in descs:
25 ret[f"{key}: {desc}"] = val
26 ret[key] = val
27 # elif name == "transitions":
28 # if "description" in val:
29 # ret[f"{val['id'].strip()}: {val['description']}"] = val
30 # else:
31 # ret[val['id'].strip()] = val
33 return ret
35 def _build_walker(self, amr_data) -> JsonDictWalker:
36 return PetriNetWalker(amr_data)