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 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
Get step-by-step solutions from verified subject matter experts
