Skip to content

Commit 827f4be

Browse files
committed
fix: treat span as doc in Qualifier process method
1 parent 698a8df commit 827f4be

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

edsnlp/pipes/qualifiers/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,13 @@ def get_matches(self, doc: Doc) -> List[Span]:
172172

173173
return list(matches)
174174

175-
def process(self, doc: Doc) -> BaseQualifierResults:
175+
def ensure_doc(self, doc: Union[Doc, Span]) -> Doc:
176+
return doc if not hasattr(doc, "as_doc") else doc.as_doc()
177+
178+
def process(self, doc_like: Union[Doc, Span]) -> BaseQualifierResults:
179+
doc_like = self.ensure_doc(doc_like) # pragma: no cover
176180
raise NotImplementedError
177181

178182
def __call__(self, doc: Doc) -> Doc:
179-
results = self.process(doc)
183+
results = self.process(doc) # pragma: no cover
180184
raise NotImplementedError(f"{type(results)} should be used to tag the document")

edsnlp/pipes/qualifiers/family/family.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def set_extensions(self) -> None:
187187
if not Doc.has_extension("family"):
188188
Doc.set_extension("family", default=[])
189189

190-
def process(self, doc: Doc) -> FamilyResults:
190+
def process(self, doc_like: Union[Doc, Span]) -> FamilyResults:
191+
doc = self.ensure_doc(doc_like)
191192
matches = self.get_matches(doc)
192193

193194
terminations = [m for m in matches if m.label_ == "termination"]

edsnlp/pipes/qualifiers/history/history.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def set_extensions(self) -> None:
326326
getter=deprecated_getter_factory("antecedent_cues", "history_cues"),
327327
)
328328

329-
def process(self, doc: Doc) -> HistoryResults:
329+
def process(self, doc_like: Union[Doc, Span]) -> HistoryResults:
330+
doc = self.ensure_doc(doc_like)
330331
note_datetime = None
331332
if doc._.note_datetime is not None:
332333
try:

edsnlp/pipes/qualifiers/hypothesis/hypothesis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def load_verbs(
262262
list_hypo_verbs_following,
263263
)
264264

265-
def process(self, doc: Doc) -> HypothesisResults:
265+
def process(self, doc_like: Union[Doc, Span]) -> HypothesisResults:
266+
doc = self.ensure_doc(doc_like)
266267
matches = self.get_matches(doc)
267268

268269
terminations = [m for m in matches if m.label_ == "termination"]

edsnlp/pipes/qualifiers/negation/negation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def __call__(self, doc: Doc) -> Doc:
295295
token._.negation = True
296296
return doc
297297

298-
def process(self, doc: Doc) -> NegationResults:
298+
def process(self, doc_like: Union[Doc, Span]) -> NegationResults:
299+
doc = self.ensure_doc(doc_like)
299300
matches = self.get_matches(doc)
300301

301302
terminations = [m for m in matches if m.label_ == "termination"]

edsnlp/pipes/qualifiers/reported_speech/reported_speech.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ def load_verbs(self, verbs: List[str]) -> List[str]:
226226

227227
return list_rep_verbs
228228

229-
def process(self, doc: Doc) -> ReportedSpeechResults:
229+
def process(self, doc_like: Union[Doc, Span]) -> ReportedSpeechResults:
230+
doc = self.ensure_doc(doc_like)
230231
matches = self.get_matches(doc)
231232
matches += list(self.regex_matcher(doc, as_spans=True))
232233

0 commit comments

Comments
 (0)