Coverage for skema/metal/model_linker/skema_model_linker/linkers/generalizer_amr_linker.py: 36%

22 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 GeneralizedAMRWalker 

7 

8 

9class GeneralizedAMRLinker(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 (name == "states") or (name == "parameters" and 'name' in val): 

15 key = val['name'].strip() 

16 lower_case_key = key.lower() 

17 

18 if "description" in val: 

19 ret[f"{key}: {val['description']}"] = val 

20 else: 

21 if lower_case_key in heuristics: 

22 descriptions = heuristics[lower_case_key] 

23 for desc in descriptions: 

24 ret[f"{key}: {desc}"] = val 

25 ret[key] = val 

26 

27 return ret 

28 

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

30 return GeneralizedAMRWalker(amr_data)