(
values: Iterable[Any],
*,
lexicon: Optional[Dict[str, Any]] = None,
include_paper_terms: bool = True,
keep_unknown: bool = True,
)
| 609 | |
| 610 | |
| 611 | def canonicalize_direction_terms( |
| 612 | values: Iterable[Any], |
| 613 | *, |
| 614 | lexicon: Optional[Dict[str, Any]] = None, |
| 615 | include_paper_terms: bool = True, |
| 616 | keep_unknown: bool = True, |
| 617 | ) -> List[str]: |
| 618 | current_lexicon = lexicon or load_lexicon() |
| 619 | canonical_terms: List[str] = [] |
| 620 | seen = set() |
| 621 | |
| 622 | for value in values: |
| 623 | cleaned = str(value or "").strip() |
| 624 | if not cleaned: |
| 625 | continue |
| 626 | resolved = resolve_canonical_direction( |
| 627 | cleaned, |
| 628 | lexicon=current_lexicon, |
| 629 | include_paper_terms=include_paper_terms, |
| 630 | ) |
| 631 | normalized = resolved["canonical_name"] if resolved else normalize_direction_key(cleaned) |
| 632 | if not normalized: |
| 633 | continue |
| 634 | if resolved is None and not keep_unknown: |
| 635 | continue |
| 636 | if normalized in seen: |
| 637 | continue |
| 638 | seen.add(normalized) |
| 639 | canonical_terms.append(normalized) |
| 640 | |
| 641 | return canonical_terms |
| 642 | |
| 643 | |
| 644 | def canonicalize_weight_mapping( |
no test coverage detected