Предположим, у меня есть такой файл docx:
Когда я был маленьким мальчиком, мой отец взял меня в город, чтобы посмотреть марширующий оркестр. Он сказал: «Сынок, когда ты вырастешь, ты будешь спасителем сломленных?». Отец сел рядом со мной, обняв меня за плечи обеими руками. Я сказал: «Я бы». Мой отец ответил: «Это мой мальчик!»
И я хочу сегментировать базу docx по прямому предложению. Нравится :
sent1 : Он сказал: «Сын, когда ты вырастешь, ты будешь спасителем сломленных?»
sent2 : Я сказал "Я бы."
sent3 : Мой отец ответил: "Это мой мальчик!"
Я пытался использовать регулярное выражение. результат таков
When I was a young boy my father took me into the city to see a marching band.
He said, "Son when you grow up would you be the savior of the broken?
".
My father sat beside me, hugging my shoulders with both of his arms.
I said "I Would.
".
My father replied "That is my boy!
код регулярного выражения:
import re
SENTENCE_REGEX = re.compile('[^!?\.]+[!?\.]')
text = open ('text.docx','r')
def parse_sentences(text):
return [x.lstrip() for x in SENTENCE_REGEX.findall(text)]
def print_sentences(sentences):
print ("\n\n".join(sentences))
if __name__ == "__main__":
print_sentences(parse_sentences(text))
I tried using regex.
С каким кодом? - person CertainPerformance   schedule 02.09.2018