import ebooklibfrom ebooklib import epubimport osimport nltkfrom bs4 import BeautifulSoup# EPUB-formatted ebook you want to importbook = epub.read_epub('lovecraft.epub')# For each document in the EPUB,# get the raw text in the document without HTML using the BeautifulSoup library,# get each token in the document - i.e. a sequence of characters we want to treat as a group, quite often words using the NLTK library,# get the vocabulary in the document by collapsing all duplicate tokens into a single set,# get the title of the document# print the title of the document and its sorted vocabularyfor doc in book.get_items_of_type(ebooklib.ITEM_DOCUMENT): raw = BeautifulSoup(doc.content).get_text() tokens = nltk.word_tokenize(raw) vocabulary = set(tokens) title = doc.get_name() print(title, sorted(vocabulary))
In relating the circumstances which have led to my confinement within this refuge for the demented, I am aware that my present position will create a natural doubt of the authenticity of my narrative. It is an unfortunate fact that the bulk of humanity is too limited in its mental vision to weigh with patience and intelligence those isolated phenomena, seen and felt only by a psychologically sensitive few, which lie outside its common experience. Men of broader intellect know that there is no sharp distinction betwixt the real and the unreal; that all things appear as they do only by virtue of the delicate individual physical and mental media through which we are made conscious of them; but the prosaic materialism of the majority condemns as madness the flashes of super-sight which penetrate the common veil of obvious empiricism.
Life is a hideous thing, and from the background behind what we know of it peer daemoniacal hints of truth which make it sometimes a thousandfold more hideous. Science, already oppressive with its shocking revelations, will perhaps be the ultimate exterminator of our human species—if separate species we be—for its reserve of unguessed horrors could never be borne by mortal brains if loosed upon the world. If we knew what we are, we should do as Sir Arthur Jermyn did; and Arthur Jermyn soaked himself in oil and set fire to his clothing one night. No one placed the charred fragments in an urn or set a memorial to him who had been; for certain papers and a certain boxed object were found, which made men wish to forget. Some who knew him do not admit that he ever existed.