Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def sentence_splitter(text):
  2.     '''получает на вход целый текст, записывает по предложениям в отдельный файл, ничего не возвращает'''
  3.     text = text.read()
  4.     sentences = codecs.open('sentences.txt', 'w', 'utf-8-sig')
  5.     reg = re.compile(u'(\\S\\S[.?!])[\n\s]')
  6.     text = re.sub(u'\[.+?\]', '', text)
  7.     text = reg.split(text)
  8.     for i in text:
  9.         if len(i) != 3:
  10.             i=i.rstrip()
  11.             sentences.write(i)
  12.         else:
  13.             i=i.rstrip()
  14.             i+=u'\0'.lstrip()
  15.             i+=u'\n'
  16.             sentences.write(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement