From 7682f3036c784d6eabeda0407eab4f2a475a1b09 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 25 Jun 2022 11:05:21 +0200 Subject: [PATCH] Add truecasing --- great_ai/src/great_ai/utilities/get_sentences.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/great_ai/src/great_ai/utilities/get_sentences.py b/great_ai/src/great_ai/utilities/get_sentences.py index 87bb172..de0ad25 100644 --- a/great_ai/src/great_ai/utilities/get_sentences.py +++ b/great_ai/src/great_ai/utilities/get_sentences.py @@ -1,15 +1,19 @@ -from typing import List +from typing import List, cast from segtok.segmenter import split_multi from .data import sentence_ending_punctuations -def get_sentences(text: str, ignore_partial: bool = False) -> List[str]: +def get_sentences( + text: str, ignore_partial: bool = False, true_case: bool = False +) -> List[str]: if text.strip() == "": return [] - possible_sentences = [s for s in split_multi(text) if s] + possible_sentences = [ + cast(str, s).strip() for s in split_multi(text) if cast(str, s).strip() + ] if ignore_partial: possible_sentences = [ @@ -18,4 +22,9 @@ def get_sentences(text: str, ignore_partial: bool = False) -> List[str]: if s[0].isupper() and s[-1] in sentence_ending_punctuations ] + if true_case: + possible_sentences = [ + s[0].lower() + s[1:] for s in possible_sentences # very crude method + ] + return possible_sentences