Question: Python Question Help Question: Write a function called load_book. This function should be able to: split a book into paragraphs and loop over them, but
Python Question Help
Question:
Write a function called load_book. This function should be able to:
- split a book into paragraphs and loop over them, but
- process each paragraph with spacy;
- store the document as a triple-nested list, so that each word string is reachable via three indices: word = document[i][j][k];
- record an index = defaultdict(list) containing a list of [i,j,k] lists for each word; and
- return document, index
Code I have so far:
================================================================
from collections import defaultdict
import re import spacy
nlp = spacy.load("en_core_web_md")
def load_book(book_id): with open(book_id + ".txt" , "r") as f: text = f.read() space = text.strip() paragraphs = space.split(" ")
return(document , index)
==================================================================
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
