Skip to content

Commit

Permalink
bunch of nit picks on tokenized_word_processor.py
Browse files Browse the repository at this point in the history
Co-authored-by: Szymon Palucha <[email protected]>
  • Loading branch information
RichJackson and Szymon Palucha committed Sep 18, 2024
1 parent 69e3eae commit 07f265a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions kazu/steps/ner/tokenized_word_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TokWordSpan:


class SpanFinder(ABC):
def __init__(self, text: str, id2label: dict[int, str]):
def __init__(self, text: str, id2label: dict[int, str]) -> None:
"""
:param text: the raw text to be processed
Expand Down Expand Up @@ -163,8 +163,7 @@ def span_continue_condition(
classes_set = set(x[1] for x in bio_and_class_labels)
if None in classes_set or self.text[word.word_char_start - 1] in self.span_breaking_chars:
return False
else:
return True
return True

def get_bio_and_class_labels(self, word: TokenizedWord) -> set[tuple[str, Optional[str]]]:
"""Return a set of tuple[<BIO label>,Optional[<class label>]] for a
Expand Down Expand Up @@ -294,8 +293,7 @@ def span_continue_condition(self, word: TokenizedWord, class_labels: set[str]) -
"""
if not class_labels or self.text[word.word_char_start - 1] in self.span_breaking_chars:
return False
else:
return True
return True

def process_next_word(self, word: TokenizedWord) -> None:
"""Process the next word in the sequence, updating span information accordingly.
Expand Down Expand Up @@ -362,8 +360,7 @@ def _make_multilabel_span_finder(self, text: str) -> MultilabelSpanFinder:
def make_span_finder(self, text: str) -> SpanFinder:
if self.use_multilabel:
return self._make_multilabel_span_finder(text)
else:
return self._make_simple_span_finder(text)
return self._make_simple_span_finder(text)

def __call__(self, words: list[TokenizedWord], text: str, namespace: str) -> list[Entity]:
span_finder: SpanFinder = self.make_span_finder(text)
Expand Down

0 comments on commit 07f265a

Please sign in to comment.