Get mapping list from src to dst. Args: src (str): source data type from keypoints_factory. dst (str): destination data type from keypoints_factory. approximate (bool): control whether approximate mapping is allowed. keypoints_factory (dict, optional): A class to
(src: str,
dst: str,
approximate: bool = False,
keypoints_factory: dict = KEYPOINTS_FACTORY)
| 234 | |
| 235 | |
| 236 | def get_mapping(src: str, |
| 237 | dst: str, |
| 238 | approximate: bool = False, |
| 239 | keypoints_factory: dict = KEYPOINTS_FACTORY): |
| 240 | """Get mapping list from src to dst. |
| 241 | |
| 242 | Args: |
| 243 | src (str): source data type from keypoints_factory. |
| 244 | dst (str): destination data type from keypoints_factory. |
| 245 | approximate (bool): control whether approximate mapping is allowed. |
| 246 | keypoints_factory (dict, optional): A class to store the attributes. |
| 247 | Defaults to keypoints_factory. |
| 248 | |
| 249 | Returns: |
| 250 | list: |
| 251 | [src_to_intersection_idx, dst_to_intersection_index, |
| 252 | intersection_names] |
| 253 | """ |
| 254 | if src in __KEYPOINTS_MAPPING_CACHE__ and \ |
| 255 | dst in __KEYPOINTS_MAPPING_CACHE__[src] and \ |
| 256 | __KEYPOINTS_MAPPING_CACHE__[src][dst][3] == approximate: |
| 257 | return __KEYPOINTS_MAPPING_CACHE__[src][dst][:3] |
| 258 | else: |
| 259 | src_names = keypoints_factory[src.lower()] |
| 260 | dst_names = keypoints_factory[dst.lower()] |
| 261 | |
| 262 | dst_idxs, src_idxs, intersection = [], [], [] |
| 263 | unmapped_names, approximate_names = [], [] |
| 264 | for dst_idx, dst_name in enumerate(dst_names): |
| 265 | matched = False |
| 266 | try: |
| 267 | src_idx = src_names.index(dst_name) |
| 268 | except ValueError: |
| 269 | src_idx = -1 |
| 270 | if src_idx >= 0: |
| 271 | matched = True |
| 272 | dst_idxs.append(dst_idx) |
| 273 | src_idxs.append(src_idx) |
| 274 | intersection.append(dst_name) |
| 275 | # approximate mapping |
| 276 | if approximate and not matched: |
| 277 | |
| 278 | try: |
| 279 | part_list = human_data.APPROXIMATE_MAP[dst_name] |
| 280 | except KeyError: |
| 281 | continue |
| 282 | for approximate_name in part_list: |
| 283 | try: |
| 284 | src_idx = src_names.index(approximate_name) |
| 285 | except ValueError: |
| 286 | src_idx = -1 |
| 287 | if src_idx >= 0: |
| 288 | dst_idxs.append(dst_idx) |
| 289 | src_idxs.append(src_idx) |
| 290 | intersection.append(dst_name) |
| 291 | unmapped_names.append(src_names[src_idx]) |
| 292 | approximate_names.append(dst_name) |
| 293 | break |
no outgoing calls
no test coverage detected