def prepositionSearch(filter): filteredText = [] for line in poemList: line = line.strip().split(' ') words = [] for i, word in enumerate(line): if line == ['']: #checking for a stanza break break if word[0].isalpha( ): #in the case of Dover beach, my code reads the word '--'; these two lines address the issue key = word[0] punctuationNote = 'undefined' #this establishes a system to still analyze words that are followed by a punctuation mark like 'to-night,' if not word[-1].isalpha(): punctuationNote = word[-1] word = word[:-1] if word in dict[ key]: #if the word is a preposition, it is marked by capitalization if 'P' in dict[key][word]: word = word.upper() elif key.lower() + word[1:] in dict[key.lower( )]: #this allows words with a capitalized first letter to be double-checked. Most of these words are at the beginning of new sentences. if 'P' in dict[key.lower()][key.lower() + word[1:]]: word = word.upper() if punctuationNote == 'undefined': #adds words without punctuation marks words.append(word) else: words.append( word + punctuationNote) #adds words with punctuation marks filteredText.append( words ) #after the analysis, the entire line is appended to the FilteredText list printPoem(filteredText) #sends filteredText to the printing function
def capitalizeWord(word, capsChars): ''' salaD for char in capsChar, GOING BACKWARDS - start at end! count = 0; determine capNumber cn. capitalize word at index CN - 1. then count++ next caps char determine capNmber CN. capitalize word at index CN - 1 + count ''' if capsChars[0] == '█': return word.upper() count = 0 for i in range(len(capsChars) - 1, 0 - 1, -1): capsChar = capsChars[i] word = capitalizeSpecificLetterAtIndex( word, m_capChar_i[capsChar] - 1 - count) count += 1 return word