Skip to content

medcat.tokenizing.spacy_impl.tokens

Classes:

Attributes:

logger module-attribute

logger = getLogger(__name__)

Document

Document(delegate: Doc)

Methods:

Attributes:

Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
198
199
200
201
202
def __init__(self, delegate: SpacyDoc) -> None:
    self._delegate = delegate
    self._char_indices: Optional[list[int]] = None
    self.ner_ents: list[MutableEntity] = []
    self.linked_ents: list[MutableEntity] = []

base property

linked_ents instance-attribute

linked_ents: list[MutableEntity] = []

ner_ents instance-attribute

ner_ents: list[MutableEntity] = []

text property

text: str

get_addon_data

get_addon_data(path: str) -> Any
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
250
251
252
253
def get_addon_data(self, path: str) -> Any:
    if not self._delegate.has_extension(path):
        raise UnregisteredDataPathException(self.__class__, path)
    return getattr(self._delegate._, path)

get_available_addon_paths

get_available_addon_paths() -> list[str]
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
255
256
257
def get_available_addon_paths(self) -> list[str]:
    return [path for path in self._addon_extension_paths
            if self.has_addon_data(path)]

get_tokens

get_tokens(start_index: int, end_index: int) -> list[MutableToken]
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
235
236
237
238
239
240
def get_tokens(self, start_index: int, end_index: int
               ) -> list[MutableToken]:
    char_indices = self._ensure_char_indices()
    lo = bisect_left(char_indices, start_index)
    hi = bisect_right(char_indices, end_index)
    return [Token(self._delegate[i]) for i in range(lo, hi)]

has_addon_data

has_addon_data(path: str) -> bool
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
247
248
def has_addon_data(self, path: str) -> bool:
    return bool(self.get_addon_data(path))

isupper

isupper() -> bool
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
269
270
def isupper(self) -> bool:
    return self._delegate.text.isupper()

register_addon_path classmethod

register_addon_path(path: str, def_val: Any = None, force: bool = True) -> None
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
259
260
261
262
263
@classmethod
def register_addon_path(cls, path: str, def_val: Any = None,
                        force: bool = True) -> None:
    SpacyDoc.set_extension(path, default=def_val, force=force)
    cls._addon_extension_paths.add(path)

set_addon_data

set_addon_data(path: str, val: Any) -> None
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
242
243
244
245
def set_addon_data(self, path: str, val: Any) -> None:
    if not self._delegate.has_extension(path):
        raise UnregisteredDataPathException(self.__class__, path)
    setattr(self._delegate._, path, val)

Entity

Entity(delegate: Span)

Methods:

Attributes:

Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
119
120
121
122
123
124
125
126
127
def __init__(self, delegate: SpacySpan) -> None:
    self._delegate = delegate
    # defaults
    self.link_candidates: list[str] = []
    self.context_similarity: float = 0.0
    self.confidence: float = 0.0
    self.cui = ''
    self.id = -1  # TODO - what's the default?
    self.detected_name = ''

base property

base: BaseEntity

confidence instance-attribute

confidence: float = 0.0

context_similarity instance-attribute

context_similarity: float = 0.0

cui instance-attribute

cui = ''

detected_name instance-attribute

detected_name = ''

end_char_index property

end_char_index: int

end_index property

end_index: int

id instance-attribute

id = -1

label property

label: int
link_candidates: list[str] = []

start_char_index property

start_char_index: int

start_index property

start_index: int

text property

text: str

get_addon_data

get_addon_data(path: str) -> Any
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
141
142
143
144
def get_addon_data(self, path: str) -> Any:
    if not self._delegate.has_extension(path):
        raise UnregisteredDataPathException(self.__class__, path)
    return getattr(self._delegate._, path)

get_available_addon_paths

get_available_addon_paths() -> list[str]
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
146
147
148
def get_available_addon_paths(self) -> list[str]:
    return [path for path in self._addon_extension_paths
            if self.has_addon_data(path)]

has_addon_data

has_addon_data(path: str) -> bool
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
138
139
def has_addon_data(self, path: str) -> bool:
    return bool(self.get_addon_data(path))

register_addon_path classmethod

register_addon_path(path: str, def_val: Any = None, force: bool = True) -> None
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
150
151
152
153
154
@classmethod
def register_addon_path(cls, path: str, def_val: Any = None,
                        force: bool = True) -> None:
    SpacySpan.set_extension(path, default=def_val, force=force)
    cls._addon_extension_paths.add(path)

set_addon_data

set_addon_data(path: str, val: Any) -> None
Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
133
134
135
136
def set_addon_data(self, path: str, val: Any) -> None:
    if not self._delegate.has_extension(path):
        raise UnregisteredDataPathException(self.__class__, path)
    return setattr(self._delegate._, path, val)

Token

Token(delegate: Token)

Attributes:

Source code in medcat-v2/medcat/tokenizing/spacy_impl/tokens.py
26
27
def __init__(self, delegate: SpacyToken) -> None:
    self._delegate = delegate

base property

base: BaseToken

char_index property

char_index: int

index property

index: int

is_digit property

is_digit: bool

is_punctuation property writable

is_punctuation: bool

is_stop property

is_stop: bool

is_upper property

is_upper: bool

lemma property

lemma: str

lower property

lower: str

norm property writable

norm: str

tag property

tag: Optional[str]

text property

text: str

text_versions property

text_versions: list[str]

text_with_ws property

text_with_ws: str

to_skip property writable

to_skip: bool