You are viewing a single comment's thread. Return to all comments →
import sys import re
text=sys.stdin.read()
text=re.sub(r"([.?!])(?=[A-Z])",r'\1',text)
abbreviations=["Mr.", "Mrs.", "Ms.", "Dr.", "Jr.", "Sr.", "vs.", "Prof.", "St.", "Mt.", "W.", "Gen.", "Rep.", "Sen.", "Lt.", "Maj.", "Capt.", "Sgt."] for abbr in abbreviations: text=text.replace(abbr,abbr.replace('.',''))
sentences = re.split(r'(?<=[.?!])\s+', text)
sentences = [s.replace('', '.') for s in sentences]
for sentence in sentences: if sentence.strip(): print(sentence.strip())
Seems like cookies are disabled on this browser, please enable them to open this website
From Paragraphs to Sentences
You are viewing a single comment's thread. Return to all comments →
import sys import re
text=sys.stdin.read()
text=re.sub(r"([.?!])(?=[A-Z])",r'\1',text)
abbreviations=["Mr.", "Mrs.", "Ms.", "Dr.", "Jr.", "Sr.", "vs.", "Prof.", "St.", "Mt.", "W.", "Gen.", "Rep.", "Sen.", "Lt.", "Maj.", "Capt.", "Sgt."] for abbr in abbreviations: text=text.replace(abbr,abbr.replace('.',''))
sentences = re.split(r'(?<=[.?!])\s+', text)
sentences = [s.replace('', '.') for s in sentences]
for sentence in sentences: if sentence.strip():
print(sentence.strip())