Question: Why is the function ` wordsnopunc / 1 ` ( replacing all punctuation with spaces before breaking into words ) failing? How can I edit
Why is the function wordsnopuncreplacing all punctuation with spaces before breaking into words failing? How can I edit my code to create a secondary function that returns the first n words of the text?
Now replace all punctuation with spaces before breaking into words. The function should be called wordsnopunc
CONSULT
sYour code here
wordsnopuncX :
openalicetxt read, Str Step : Open the file for reading
readstringStr Input Step : Read the entire content of the file into the Text variable
stringcharsInput CharList Convert input string to list of characters
replacepunctuationCharList CleanList Replace punctuation with spaces
stringcharsCleanString CleanList Convert back to string
splitstringCleanString Words Split the string into words
closeStr Step : Close the file stream
Prolog: Warning: tmptmplvgjrwjpl::
Prolog: Warning: Singleton variables: XWords
Prolog: Warning: tmptmplvgjrwjpl::
Prolog: Warning: Singleton variables: Str
Prolog: ERROR: tmptmplvgjrwjpl::
Prolog: ERROR: No permission to modify static procedure close
true
wordsnopuncX X X
Traceback most recent call last:
File usrlocallibpythondistpackagesswiprologkernelkernelpy line in doexecute
self.executecode
File usrlocallibpythondistpackagesswiprologkernelkernelpy line in execute
result self.thread.querycode
File usrlocallibpythondistpackagesswiplserverprologmqipy line in query
return self.returnprologresponse
File usrlocallibpythondistpackagesswiplserverprologmqipy line in returnprologresponse
raise PrologErrorjsonResult
swiplserver.prologmqi.PrologError: existenceerrorprocedurereplacepunctuation,
Question #
Now rewrite wordsnopunc above as wordsn to return the first n words of the text. It should take two arguments: n and the returned text.
CONSULT
Your code here
wordsn
The "Project", "Gutenberg", "eBook", of
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
