code: def _mangle_sentences_from_file(input_file):
      
      try:
          with open(input_file, 'r') as f:
              # final sentence may not be a complete sentence, save and prepend to next chunk
              leftovers = ''
              sentence_no = 0
              for chunk in read_in_chunks(f): # lazy way of reading our file in case it's large
                  # prepend leftovers to chunk
                  chunk = chunk.decode('utf8')
                  chunk = leftovers + chunk
                  chunk = chunk.replace(';', '.') # replace semi colons with periods 
                  doc = nlp(chunk)
  
                  # last sentence may not be sentence, move to next chunk
                  sents = [sent.string.strip() for sent in doc.sents]
                  if len(sents) > 1:
                      leftovers = sents[-1] + chunk.rpartition(sents[-1])[-1]
                      sents = sents[:-1]
  
                  for sent in sents:
                      sent = sent.replace('\n', ' ')
                      sent = sent.replace('\r', ' ')
                      sent = re.sub( '\s+', ' ', sent ).strip()
                      if len(sent) < 5:
                          continue # skip tiny sentences
                      # add original sentence to database
                      cursor.execute('''insert into orignal_sentences (sentence,
                      flesch_reading_ease, flesch_kincaid_grade_level) values (?,
                      ?, ?)''', (sent, textstat.flesch_reading_ease(sent),
                          textstat.flesch_kincaid_grade(sent)))
                      og_sent_id = cursor.lastrowid
                      for mangled_sentence in mangle_agreement(sent):
                          # add mangled sentence to database
                          cursor.execute('''insert into mangled_sentences
                          (original_sentence_id, sentence) values (?, ?)''',
                          (og_sent_id, mangled_sentence))
                  conn.commit() # commit all sentences in this chunk
  
      except Exception as e:
          print('error on {}'.format(input_file))
          print(e)
docs: Write participle phrase file