Skip to content

edsnlp.pipelines.ner.scores.tnm.models

TnmEnum

Bases: Enum

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

__str__()

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

Unknown

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
12
13
class Unknown(TnmEnum):
    unknown = "x"

unknown = 'x' class-attribute

Modifier

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
16
17
18
19
20
21
22
23
class Modifier(TnmEnum):
    clinical = "c"
    histopathology = "p"
    neoadjuvant_therapy = "y"
    recurrent = "r"
    autopsy = "a"
    ultrasonography = "u"
    multifocal = "m"

clinical = 'c' class-attribute

histopathology = 'p' class-attribute

neoadjuvant_therapy = 'y' class-attribute

recurrent = 'r' class-attribute

autopsy = 'a' class-attribute

ultrasonography = 'u' class-attribute

multifocal = 'm' class-attribute

Tumour

Bases: TnmEnum

Source code in edsnlp/pipelines/ner/scores/tnm/models.py
26
27
28
class Tumour(TnmEnum):
    unknown = "x"
    in_situ = "is"

unknown = 'x' class-attribute

in_situ = 'is' class-attribute

TNM

Bases: BaseModel

Source code in edsnlp/pipelines/ner/scores/tnm/models.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
75
76
77
class TNM(BaseModel):

    modifier: Optional[Union[int, Modifier]] = None
    tumour: Optional[Union[int, Tumour]] = None
    node: Optional[Union[int, Unknown]] = None
    metastasis: Optional[Union[int, Unknown]] = 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.modifier is not None:
            norm.append(str(self.modifier))

        if self.tumour is not None:
            norm.append(f"T{self.tumour}")

        if self.node is not None:
            norm.append(f"N{self.node}")

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

        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)

modifier: Optional[Union[int, Modifier]] = None class-attribute

tumour: Optional[Union[int, Tumour]] = None class-attribute

node: Optional[Union[int, Unknown]] = None class-attribute

metastasis: Optional[Union[int, Unknown]] = 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
41
42
43
44
45
@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
47
48
49
50
51
52
53
54
55
56
57
@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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def norm(self) -> str:
    norm = []

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

    if self.tumour is not None:
        norm.append(f"T{self.tumour}")

    if self.node is not None:
        norm.append(f"N{self.node}")

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

    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)