In: Computer Science
Please use Python!
def getText(file):
This function should open the file named file, and return the contents of the file formatted as a single string. During processing, you should (i) remove any blank lines, (ii) remove any lines consisting entirely of CAPITALIZED WORDS , and (iii) replace any explicit ’\n’ (newline) characters with spaces unless directly preceeded by a ’-’ (hyphen), in which case you should simply remove both the hyphen and the newline, restoring the original word.
def getText(file):
pass
def flushMarks(text):
This function should take as input a string such as what might be returned by getText() and return a new string with the following modifications to the input:
Remove possessives, i.e., "’s" at the end of a word;
Remove ’)’, ’(’, ’,’, ’:’, ’-’, ’_’, ’...’, ’"’ and "’"; and Replace ’!’, ’?’ and ’;’ with ’.’
A condition of this function is that it should be easy to change or extend the substitutions made. In other words, a function that steps through each of these substitutions in an open-coded fashion will not get full credit; write your function so that the substitutions can be modified or extended without having to significantly alter the code. Here’s a hint: if your code for this function is more than a few lines long, you’re probably not doing it right.
# Specification: takes a string, text, and removes possessives ('s)
# and most punctuation ('(),:\'"- —_').
#
def flushMarks(text):
pass