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

1from collections import defaultdict 

2from typing import Iterable, Dict, List, Any 

3 

4from . import heuristics, AMRLinker 

5from ..walkers import JsonDictWalker, JsonNode 

6from ..walkers import PetriNetWalker 

7 

8 

9class PetriNetLinker(AMRLinker): 

10 

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() 

18 

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 

32 

33 return ret 

34 

35 def _build_walker(self, amr_data) -> JsonDictWalker: 

36 return PetriNetWalker(amr_data)