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 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 nearRhymeScore(pron1, pron2): stress1 = Wordsmith.getStress(pron1) stress2 = Wordsmith.getStress(pron2) if not stress1 or not stress2: return -1 if ((len(stress1) - len(stress2)) > 1): return -1 match = 0 if (len(stress1) > len(stress2)): tempStress = stress1 stress1 = stress2 stress2 = tempStress tempPron = pron1 pron1 = pron2 pron2 = tempPron for i in range(1, len(stress1) + 1): # Check same stress pattern of word if (stress1[-i][0] == stress2[-i][0]): match += 1 score = nearSyllableScore(stress1[-i], stress2[-i]) if (score < 0): match = -1 break elif (i == 1) and (score * 1.5 < 1): match = -1 break else: consonantScore = 0 if (stress1[-i][2] > 0) and (stress2[-i][2] > 0) and ( stress1[-i][2] < len(pron1) - 1) and (stress2[-i][2] < len(pron2) - 1): index1 = stress1[-i][2] index2 = stress2[-i][2] # Check surrounding consonants for closeness consonantScore = nearConsonantScore(pron1[index1 + 1], pron2[index2 + 1]) if i == 1: score *= 1.5 if score > 1: consonantScore *= 2.5 # if i == 2: # consonantScore *=1.5 # print i # print stress1[-i] # print stress2[-i] # print score # print consonantScore match += score match += consonantScore return match
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 nearRhymeScore(pron1, pron2): stress1 = Wordsmith.getStress(pron1) stress2 = Wordsmith.getStress(pron2) if not stress1 or not stress2: return -1 if (len(stress1) - len(stress2)) > 1: return -1 match = 0 if len(stress1) > len(stress2): tempStress = stress1 stress1 = stress2 stress2 = tempStress tempPron = pron1 pron1 = pron2 pron2 = tempPron for i in range(1, len(stress1) + 1): # Check same stress pattern of word if stress1[-i][0] == stress2[-i][0]: match += 1 score = nearSyllableScore(stress1[-i], stress2[-i]) if score < 0: match = -1 break elif (i == 1) and (score * 1.5 < 1): match = -1 break else: consonantScore = 0 if ( (stress1[-i][2] > 0) and (stress2[-i][2] > 0) and (stress1[-i][2] < len(pron1) - 1) and (stress2[-i][2] < len(pron2) - 1) ): index1 = stress1[-i][2] index2 = stress2[-i][2] # Check surrounding consonants for closeness consonantScore = nearConsonantScore(pron1[index1 + 1], pron2[index2 + 1]) if i == 1: score *= 1.5 if score > 1: consonantScore *= 2.5 # if i == 2: # consonantScore *=1.5 # print i # print stress1[-i] # print stress2[-i] # print score # print consonantScore match += score match += consonantScore return match
def getListFromWord(self,word): stress = Wordsmith.getStress(Wordsmith.tokenize(word)) if (len(stress) < 1): return False phone = stress[-1][1] return self.get(phone)