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:

  1. split a book into paragraphs and loop over them, but
  2. process each paragraph with spacy;
  3. store the document as a triple-nested list, so that each word string is reachable via three indices: word = document[i][j][k];
  4. record an index = defaultdict(list) containing a list of [i,j,k] lists for each word; and
  5. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!