Skip to content

edsnlp.pipelines.ner.scores.tnm.models

TnmEnum

Bases: Enum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
16
17
18
class TnmEnum(Enum):
    def __str__(self) -> str:
        return self.value

__str__()

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
17
18
def __str__(self) -> str:
    return self.value

Prefix

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
21
22
23
24
25
26
27
28
29
30
31
class Prefix(TnmEnum):
    clinical = "c"
    histopathology = "p"
    histopathology2 = "P"
    neoadjuvant_therapy = "y"
    recurrent = "r"
    autopsy = "a"
    ultrasonography = "u"
    multifocal = "m"
    py = "yp"
    mp = "mp"

clinical = 'c' class-attribute

histopathology = 'p' class-attribute

histopathology2 = 'P' class-attribute

neoadjuvant_therapy = 'y' class-attribute

recurrent = 'r' class-attribute

autopsy = 'a' class-attribute

ultrasonography = 'u' class-attribute

multifocal = 'm' class-attribute

py = 'yp' class-attribute

mp = 'mp' class-attribute

Tumour

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
34
35
36
37
38
39
40
41
42
class Tumour(TnmEnum):
    unknown = "x"
    in_situ = "is"
    score_0 = "0"
    score_1 = "1"
    score_2 = "2"
    score_3 = "3"
    score_4 = "4"
    o = "o"

unknown = 'x' class-attribute

in_situ = 'is' class-attribute

score_0 = '0' class-attribute

score_1 = '1' class-attribute

score_2 = '2' class-attribute

score_3 = '3' class-attribute

score_4 = '4' class-attribute

o = 'o' class-attribute

Specification

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
45
46
47
48
49
50
51
class Specification(TnmEnum):
    a = "a"
    b = "b"
    c = "c"
    d = "d"
    mi = "mi"
    x = "x"

a = 'a' class-attribute

b = 'b' class-attribute

c = 'c' class-attribute

d = 'd' class-attribute

mi = 'mi' class-attribute

x = 'x' class-attribute

Node

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
54
55
56
57
58
59
60
class Node(TnmEnum):
    unknown = "x"
    score_0 = "0"
    score_1 = "1"
    score_2 = "2"
    score_3 = "3"
    o = "o"

unknown = 'x' class-attribute

score_0 = '0' class-attribute

score_1 = '1' class-attribute

score_2 = '2' class-attribute

score_3 = '3' class-attribute

o = 'o' class-attribute

Metastasis

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
63
64
65
66
67
68
69
70
class Metastasis(TnmEnum):
    unknown = "x"
    score_0 = "0"
    score_1 = "1"
    o = "o"
    score_1x = "1x"
    score_2x = "2x"
    ox = "ox"

unknown = 'x' class-attribute

score_0 = '0' class-attribute

score_1 = '1' class-attribute

o = 'o' class-attribute

score_1x = '1x' class-attribute

score_2x = '2x' class-attribute

ox = 'ox' class-attribute

TNM

Bases: BaseModel

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
class TNM(BaseModel):

    prefix: Optional[Prefix] = None
    tumour: Optional[Tumour] = None
    tumour_specification: Optional[Specification] = None
    tumour_suffix: Optional[str] = None
    node: Optional[Node] = None
    node_specification: Optional[Specification] = None
    node_suffix: Optional[str] = None
    metastasis: Optional[Metastasis] = None
    resection_completeness: Optional[int] = None
    version: Optional[str] = None
    version_year: Optional[int] = None

    @validator("*", pre=True)
    def coerce_o(cls, v):
        if isinstance(v, str):
            v = v.replace("o", "0")
        return v

    @validator("version_year")
    def validate_year(cls, v):
        if v is None:
            return v

        if v < 40:
            v += 2000
        elif v < 100:
            v += 1900

        return v

    def norm(self) -> str:
        norm = []

        if self.prefix is not None:
            norm.append(str(self.prefix))

        if (
            (self.tumour is not None)
            | (self.tumour_specification is not None)
            | (self.tumour_suffix is not None)
        ):
            norm.append(f"T{str(self.tumour or '')}")
            norm.append(f"{str(self.tumour_specification or '')}")
            norm.append(f"{str(self.tumour_suffix or '')}")

        if (
            (self.node is not None)
            | (self.node_specification is not None)
            | (self.node_suffix is not None)
        ):
            norm.append(f"N{str(self.node or '')}")
            norm.append(f"{str(self.node_specification or '')}")
            norm.append(f"{str(self.node_suffix or '')}")

        if self.metastasis is not None:
            norm.append(f"M{self.metastasis}")

        if self.resection_completeness is not None:
            norm.append(f"R{self.resection_completeness}")

        if self.version is not None and self.version_year is not None:
            norm.append(f" ({self.version.upper()} {self.version_year})")

        return "".join(norm)

    def dict(
        self,
        *,
        include: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
        exclude: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
        by_alias: bool = False,
        skip_defaults: bool = None,
        exclude_unset: bool = False,
        exclude_defaults: bool = False,
        exclude_none: bool = False,
    ) -> "DictStrAny":
        """
        Generate a dictionary representation of the model,
        optionally specifying which fields to include or exclude.

        """
        if skip_defaults is not None:
            warnings.warn(
                f"""{self.__class__.__name__}.dict(): "skip_defaults"
                is deprecated and replaced by "exclude_unset" """,
                DeprecationWarning,
            )
            exclude_unset = skip_defaults

        d = dict(
            self._iter(
                to_dict=True,
                by_alias=by_alias,
                include=include,
                exclude=exclude,
                exclude_unset=exclude_unset,
                exclude_defaults=exclude_defaults,
                exclude_none=exclude_none,
            )
        )
        set_keys = set(d.keys())
        for k in set_keys.intersection(
            {
                "prefix",
                "tumour",
                "node",
                "metastasis",
                "tumour_specification",
                "node_specification",
                "tumour_suffix",
                "node_suffix",
            }
        ):
            v = d[k]
            if isinstance(v, TnmEnum):
                d[k] = v.value

        return d

prefix: Optional[Prefix] = None class-attribute

tumour: Optional[Tumour] = None class-attribute

tumour_specification: Optional[Specification] = None class-attribute

tumour_suffix: Optional[str] = None class-attribute

node: Optional[Node] = None class-attribute

node_specification: Optional[Specification] = None class-attribute

node_suffix: Optional[str] = None class-attribute

metastasis: Optional[Metastasis] = None class-attribute

resection_completeness: Optional[int] = None class-attribute

version: Optional[str] = None class-attribute

version_year: Optional[int] = None class-attribute

coerce_o(v)

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
87
88
89
90
91
@validator("*", pre=True)
def coerce_o(cls, v):
    if isinstance(v, str):
        v = v.replace("o", "0")
    return v

validate_year(v)

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@validator("version_year")
def validate_year(cls, v):
    if v is None:
        return v

    if v < 40:
        v += 2000
    elif v < 100:
        v += 1900

    return v

norm()

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def norm(self) -> str:
    norm = []

    if self.prefix is not None:
        norm.append(str(self.prefix))

    if (
        (self.tumour is not None)
        | (self.tumour_specification is not None)
        | (self.tumour_suffix is not None)
    ):
        norm.append(f"T{str(self.tumour or '')}")
        norm.append(f"{str(self.tumour_specification or '')}")
        norm.append(f"{str(self.tumour_suffix or '')}")

    if (
        (self.node is not None)
        | (self.node_specification is not None)
        | (self.node_suffix is not None)
    ):
        norm.append(f"N{str(self.node or '')}")
        norm.append(f"{str(self.node_specification or '')}")
        norm.append(f"{str(self.node_suffix or '')}")

    if self.metastasis is not None:
        norm.append(f"M{self.metastasis}")

    if self.resection_completeness is not None:
        norm.append(f"R{self.resection_completeness}")

    if self.version is not None and self.version_year is not None:
        norm.append(f" ({self.version.upper()} {self.version_year})")

    return "".join(norm)

dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def dict(
    self,
    *,
    include: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
    exclude: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
    by_alias: bool = False,
    skip_defaults: bool = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
) -> "DictStrAny":
    """
    Generate a dictionary representation of the model,
    optionally specifying which fields to include or exclude.

    """
    if skip_defaults is not None:
        warnings.warn(
            f"""{self.__class__.__name__}.dict(): "skip_defaults"
            is deprecated and replaced by "exclude_unset" """,
            DeprecationWarning,
        )
        exclude_unset = skip_defaults

    d = dict(
        self._iter(
            to_dict=True,
            by_alias=by_alias,
            include=include,
            exclude=exclude,
            exclude_unset=exclude_unset,
            exclude_defaults=exclude_defaults,
            exclude_none=exclude_none,
        )
    )
    set_keys = set(d.keys())
    for k in set_keys.intersection(
        {
            "prefix",
            "tumour",
            "node",
            "metastasis",
            "tumour_specification",
            "node_specification",
            "tumour_suffix",
            "node_suffix",
        }
    ):
        v = d[k]
        if isinstance(v, TnmEnum):
            d[k] = v.value

    return d