def __get_possible_words(self, state, line_number, line_position): prev_word = state.lyrics[line_number][line_position - 1].lower() #WHAT IF FIRST WORD gram_dict = util.getGramDict(self.genre_db[self.genre]) if gram_dict.get(prev_word) is None: gram = util.chooseRandomGram(self.genre_db, self.genre) return [gram] possibleWords = gram_dict[prev_word] words = [word for word in possibleWords] return words
def __get_possible_words2(self, state, line_number, line_position): wordThreeAway = None wordTwoAway = None wordOneAway = None line = state.lyrics[line_number] if line_position >= 1: wordOneAway = line[line_position - 1].lower() if line_position >= 2: wordTwoAway = line[line_position - 2].lower() if line_position >= 3: wordThreeAway = line[line_position - 3].lower() possibleWords = util.getPossibleWords(self.genre_db[self.genre],wordThreeAway, wordTwoAway, wordOneAway) if len(possibleWords) == 0: gram = util.chooseRandomGram(self.genre_db, self.genre) return [gram] else: return possibleWords