From f169614c533db59a92edf4407246b8512ba9d176 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Thu, 1 Feb 2024 12:36:41 +0100 Subject: [PATCH] Use type alias. --- spacy/kb/kb.pxd | 1 - spacy/kb/kb.pyx | 4 +++- spacy/kb/typedefs.pxd | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 spacy/kb/typedefs.pxd diff --git a/spacy/kb/kb.pxd b/spacy/kb/kb.pxd index 263469546..1b0a03838 100644 --- a/spacy/kb/kb.pxd +++ b/spacy/kb/kb.pxd @@ -5,7 +5,6 @@ from libc.stdint cimport int64_t from ..vocab cimport Vocab - cdef class KnowledgeBase: cdef Pool mem cdef readonly Vocab vocab diff --git a/spacy/kb/kb.pyx b/spacy/kb/kb.pyx index af3a5c6c6..a33e105fb 100644 --- a/spacy/kb/kb.pyx +++ b/spacy/kb/kb.pyx @@ -9,6 +9,8 @@ from ..errors import Errors from ..tokens import SpanGroup from ..util import SimpleFrozenList from .candidate import Candidate +from .typedefs import CandidatesForMention + cdef class KnowledgeBase: @@ -32,7 +34,7 @@ cdef class KnowledgeBase: self.entity_vector_length = entity_vector_length self.mem = Pool() - def get_candidates(self, mentions: Iterator[SpanGroup]) -> Iterator[Iterable[Iterable[Candidate]]]: + def get_candidates(self, mentions: Iterator[SpanGroup]) -> Iterator[Iterable[CandidatesForMention]]: """ Return candidate entities for a specified Span mention. Each candidate defines at least the entity and the entity's embedding vector. Depending on the KB implementation, further properties - such as the prior diff --git a/spacy/kb/typedefs.pxd b/spacy/kb/typedefs.pxd new file mode 100644 index 000000000..4f7e887ad --- /dev/null +++ b/spacy/kb/typedefs.pxd @@ -0,0 +1,4 @@ +from .candidate import Candidate +from typing import Iterable + +ctypedef Iterable[Candidate] CandidatesForMention \ No newline at end of file