Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import csv
  2. from chapter import *
  3.  
  4. # Frankenstein:
  5. book_number = "84"
  6. name = "frank"
  7.  
  8. infile_text_filename = "%s.txt" % book_number
  9. outfile_sentence_csv_filename = "%s-sent.csv" % name
  10. outfile_chapter_csv_filename = "%s-chap.csv" % name
  11.  
  12. with open(outfile_sentence_csv_filename, 'wb') as csv_sentence_file:
  13.  
  14. csv_sentence = csv.writer(csv_sentence_file, delimiter=',', lineterminator="\n",
  15. quotechar='"', quoting=csv.QUOTE_MINIMAL)
  16.  
  17. # chapter# (ie, section number)
  18. # sentence# (ie, within the chapter)
  19. # slen is sentence length
  20. hdrs = ['chapter', 'sentence', 'slen', 'note']
  21. pos = ['noun', 'verb', 'adj', 'adv', 'con',
  22. 'pron', 'punct', 'dt', 'other' ]
  23. hdrs = hdrs.extend(pos)
  24. csv_sentence.writerow(hdrs)
  25.  
  26. book = Book(infile_text_filename)
  27.  
  28. # chapter
  29. ch = book.chapter_classes[0]
  30. chapter_number = 1
  31. print("Chapter %s" % chapter_number)
  32.  
  33. words = list(ch.word_set)
  34. nsent = ch.sentence_count()
  35. uwords = len(words)
  36. verb_d = ch.verb_density()
  37. adj_d = ch.adj_density()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement