def getNearRhymes(inputString): rhymes = [] pron1 = Wordsmith.tokenize(inputString) words = Wordsmith.getRelevantWords(inputString) if not words: return [] for word in words: word = str(word) if inputString == word: continue elif "'" in word: continue pron2 = Wordsmith.tokenize(word) if not pron2: continue score = nearRhymeScore(pron1, pron2) if score > 0: rhymes.append((word, score)) return sorted(rhymes, key=lambda t: t[1], reverse=True)
def check(inputString, word): if inputString == word: return -1 pron1 = Wordsmith.tokenize(inputString) pron2 = Wordsmith.tokenize(word) print pron1 print pron2 return nearRhymeScore(pron1, pron2)
def add(self, word): stress = Wordsmith.getStress(Wordsmith.tokenize(word)) if (len(stress) < 1): return False phone = stress[-1][1] if phone not in self.buckets.keys(): self.buckets[phone] = [] if not word in self.buckets[phone]: self.buckets[phone].append(word)
def get_rhyme_score(word1, word2): if word1 == word2: return 0 pron1 = Wordsmith.tokenize(word1) pron2 = Wordsmith.tokenize(word2) return nearRhymeScore(pron1, pron2)
def getListFromWord(self, word): stress = Wordsmith.getStress(Wordsmith.tokenize(word)) if (len(stress) < 1): return False phone = stress[-1][1] return self.get(phone)
def getListFromWord(self,word): stress = Wordsmith.getStress(Wordsmith.tokenize(word)) if (len(stress) < 1): return False phone = stress[-1][1] return self.get(phone)
def get_rhyme_score(word1,word2): if word1 == word2: return 0 pron1 = Wordsmith.tokenize(word1) pron2 = Wordsmith.tokenize(word2) return nearRhymeScore(pron1,pron2)