Skip to content

config_drug_mapping

ConfigDrugMapping

Configuration class for the drug-mapping workflow.

Loads settings from a YAML file and provides structured access via per-component settings dataclasses shared with :class:Config.

Source code in src/ariadne/utils/config_drug_mapping.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class ConfigDrugMapping:
    """
    Configuration class for the drug-mapping workflow.

    Loads settings from a YAML file and provides structured access via
    per-component settings dataclasses shared with :class:`Config`.
    """

    drug_structuring: DrugStructuringSettings
    mapping_per_concept_class: Dict[str, MappingPerConceptClassSettings]

    def __init__(self, filename: str = "config_drug_mapping.yaml"):
        """
        Initializes the ConfigDrugMapping object by loading settings from the specified YAML file.

        Args:
            filename: The path to the YAML configuration file. Defaults to 'config_drug_mapping.yaml' in the current
                        working directory or project root.
        """
        path = Path.cwd() / filename
        if not path.exists():
            path = get_project_root() / filename
            if not path.exists():
                raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
        with path.open("r", encoding="utf-8") as fh:
            raw = yaml.safe_load(fh) or {}

        self.drug_structuring = build_dataclass(DrugStructuringSettings, raw.get("drug_structuring", {}))
        self.mapping_per_concept_class = {
            name: build_dataclass(MappingPerConceptClassSettings, cc_raw)
            for name, cc_raw in (raw.get("mapping_per_concept_class") or {}).items()
        }
        for cc in self.mapping_per_concept_class.values():
            vm_filter = cc.verbatim_mapping.standard_concept_filter
            vm_filter.include_classification_concepts = not vm_filter.standard_concept

    def to_dict(self) -> Dict[str, Any]:
        return {
            "drug_structuring": serialize_dataclass(self.drug_structuring),
            "mapping_per_concept_class": {
                name: serialize_dataclass(cc)
                for name, cc in self.mapping_per_concept_class.items()
            },
        }

__init__(filename='config_drug_mapping.yaml')

Initializes the ConfigDrugMapping object by loading settings from the specified YAML file.

Parameters:

Name Type Description Default
filename str

The path to the YAML configuration file. Defaults to 'config_drug_mapping.yaml' in the current working directory or project root.

'config_drug_mapping.yaml'
Source code in src/ariadne/utils/config_drug_mapping.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def __init__(self, filename: str = "config_drug_mapping.yaml"):
    """
    Initializes the ConfigDrugMapping object by loading settings from the specified YAML file.

    Args:
        filename: The path to the YAML configuration file. Defaults to 'config_drug_mapping.yaml' in the current
                    working directory or project root.
    """
    path = Path.cwd() / filename
    if not path.exists():
        path = get_project_root() / filename
        if not path.exists():
            raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
    with path.open("r", encoding="utf-8") as fh:
        raw = yaml.safe_load(fh) or {}

    self.drug_structuring = build_dataclass(DrugStructuringSettings, raw.get("drug_structuring", {}))
    self.mapping_per_concept_class = {
        name: build_dataclass(MappingPerConceptClassSettings, cc_raw)
        for name, cc_raw in (raw.get("mapping_per_concept_class") or {}).items()
    }
    for cc in self.mapping_per_concept_class.values():
        vm_filter = cc.verbatim_mapping.standard_concept_filter
        vm_filter.include_classification_concepts = not vm_filter.standard_concept