Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions medcat/medcat/stats/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PredictedAnnotation(TypedDict):
end: int
cui: str
text: str
detected_name: str
confidence: float
raw: MutableEntity
no_tokens: int
Expand Down
4 changes: 3 additions & 1 deletion medcat/medcat/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def _extract_predictions(
'start': ent.base.start_char_index,
'end': ent.base.end_char_index,
'cui': ent.cui,
'text': ent.base.text,
'text': doc['text'][max(0, ent.base.start_char_index):
ent.base.end_char_index],
'detected_name': ent.detected_name,
'context': doc['text'][max(0, ent.base.start_char_index - 60):
ent.base.end_char_index + 60],
'document_id': doc['id'],
Expand Down
4 changes: 2 additions & 2 deletions medcat/medcat/tokenizing/spacy_impl/tokens.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Iterator, Union, Optional, overload, cast, Any
from bisect import bisect_left, bisect_right
from bisect import bisect_left
import logging

from spacy.tokens import Token as SpacyToken
Expand Down Expand Up @@ -236,7 +236,7 @@ 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)
hi = bisect_left(char_indices, end_index)
return [Token(self._delegate[i]) for i in range(lo, hi)]

def set_addon_data(self, path: str, val: Any) -> None:
Expand Down
1 change: 1 addition & 0 deletions medcat/tests/stats/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DummyEntity:
base: SimpleNamespace = field(init=False)

def __post_init__(self):
self.detected_name = self.text
self.base = SimpleNamespace(
text=self.text,
start_char_index=self.start_char_index,
Expand Down
1 change: 1 addition & 0 deletions medcat/tests/utils/test_training_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _FakeEntity:
def __init__(self, start: int, end: int, text: str, cui: str):
self.base = _FakeEntityBase(start, end, text)
self.cui = cui
self.detected_name = text
self.context_similarity = 1.0
self.id = 0

Expand Down
Loading