
| Current Path : /proc/thread-self/root/usr/local/lib/python3.8/dist-packages/txt/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //proc/thread-self/root/usr/local/lib/python3.8/dist-packages/txt/count_sentences.py |
ENDINGS = ['.', '!', '?', ';']
def count_sentences(text):
text = text.strip()
if len(text) == 0:
return 0
split_result = None
for ending in ENDINGS:
separator = f'{ending} '
if split_result is None:
split_result = text.split(separator)
else:
split_result = [y for x in split_result for y in x.split(separator)]
last_is_sentence = text[-1] in ENDINGS
return len(split_result) - 1 + last_is_sentence