Coverage for skema/metal/model_linker/skema_model_linker/linkers/regnet.py: 22%

36 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 RegNetWalker 

7 

8 

9class RegNetLinker(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 id_ = val['id'].strip() 

15 key = id_.lower() 

16 if name == "vertices": 

17 rate_constant = val['rate_constant'].strip() 

18 if "rate_constant" in val: 

19 if id_ != rate_constant: 

20 ret[f"{id_}: {rate_constant}"] = val 

21 else: 

22 if key in heuristics: 

23 descs = heuristics[key] 

24 for desc in descs: 

25 ret[f"{id_}: {desc}"] = val 

26 ret[id_] = val 

27 else: 

28 ret[id_] = val 

29 elif name == "edges": 

30 if "properties" in val and "rate_constant" in val["properties"]: 

31 rate_constant = val['properties']['rate_constant'].strip() 

32 if id_ != rate_constant: 

33 ret[f"{id_}: {rate_constant}"] = val 

34 else: 

35 if key in heuristics: 

36 descs = heuristics[key] 

37 for desc in descs: 

38 ret[f"{id_}: {desc}"] = val 

39 ret[id_] = val 

40 else: 

41 ret[id_] = val 

42 

43 return ret 

44 

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

46 return RegNetWalker(amr_data) 

47 

48