Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started