Question: Question 4. Write a function called chapter_number. It should take a single argument, the text of a chapter from our dataset, and return the number

 Question 4. Write a function called chapter_number. It should take a

Question 4. Write a function called chapter_number. It should take a single argument, the text of a chapter from our dataset, and return the number of that chapter, as a Roman numeral. (For example, it should return the string "T" for the first chapter and "il" for the second.) If the argument doesn't have a chapter number in the same place as the chapters in our dataset, chapter_number can return whatever you like. To help you with this, we've included a function called text_before. Its documentation describes what it does. def text_before(full_text, pattern): **"Finds all the text that occurs in full_text before the specified pattern. Parameters full_text : str The text we want to search within. param2 : str The thing we want to search for. Returns str All the text that occurs in full_text before pattern. If pattern doesn't appear anywhere, all of full_text is returned. Examples >>> text_before("The rain in Spain falls mainly on the plain.", "Spain") 'The rain in >>> text_before("The rain in Spain falls mainly on the plain.", "ain") The r' >>> text_before("The rain in Spain falls mainly on the plain.", "Portugal") 'The rain in Spain falls mainly on the plain. return np.array(full_text.split(pattern)).item() def chapter_number(chapter_text): Question 4. Write a function called chapter_number. It should take a single argument, the text of a chapter from our dataset, and return the number of that chapter, as a Roman numeral. (For example, it should return the string "T" for the first chapter and "il" for the second.) If the argument doesn't have a chapter number in the same place as the chapters in our dataset, chapter_number can return whatever you like. To help you with this, we've included a function called text_before. Its documentation describes what it does. def text_before(full_text, pattern): **"Finds all the text that occurs in full_text before the specified pattern. Parameters full_text : str The text we want to search within. param2 : str The thing we want to search for. Returns str All the text that occurs in full_text before pattern. If pattern doesn't appear anywhere, all of full_text is returned. Examples >>> text_before("The rain in Spain falls mainly on the plain.", "Spain") 'The rain in >>> text_before("The rain in Spain falls mainly on the plain.", "ain") The r' >>> text_before("The rain in Spain falls mainly on the plain.", "Portugal") 'The rain in Spain falls mainly on the plain. return np.array(full_text.split(pattern)).item() def chapter_number(chapter_text)

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!