Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from chapter import *
- # Frankenstein:
- book_number = "84"
- name = "frank"
- infile_text_filename = "%s.txt" % book_number
- outfile_sentence_csv_filename = "%s-sent.csv" % name
- outfile_chapter_csv_filename = "%s-chap.csv" % name
- with open(outfile_sentence_csv_filename, 'wb') as csv_sentence_file:
- csv_sentence = csv.writer(csv_sentence_file, delimiter=',', lineterminator="\n",
- quotechar='"', quoting=csv.QUOTE_MINIMAL)
- # chapter# (ie, section number)
- # sentence# (ie, within the chapter)
- # slen is sentence length
- hdrs = ['chapter', 'sentence', 'slen', 'note']
- pos = ['noun', 'verb', 'adj', 'adv', 'con',
- 'pron', 'punct', 'dt', 'other' ]
- hdrs = hdrs.extend(pos)
- csv_sentence.writerow(hdrs)
- book = Book(infile_text_filename)
- # chapter
- ch = book.chapter_classes[0]
- chapter_number = 1
- print("Chapter %s" % chapter_number)
- words = list(ch.word_set)
- nsent = ch.sentence_count()
- uwords = len(words)
- verb_d = ch.verb_density()
- adj_d = ch.adj_density()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement