def writeRhymes(): countryInfo = util.readExamples("country")["country"] hiphoprapInfo = util.readExamples("hiphoprap")["hiphoprap"] popInfo = util.readExamples("pop")["pop"] wordMap = {} lines = countryInfo["lines"] lines += hiphoprapInfo["lines"] lines += popInfo["lines"] for line in lines: line = line.split(" ") for word in line: word = word.lower() if word not in wordMap: wordMap[word] = word values = wordMap.values() fo = open("rhymes.txt", "w") ct = 0 for word in values: if "," in word: splitArr = word.split(",") for splitWord in splitArr: print "%i. finding rhyme for: %s" % (ct,splitWord) fo.write("%s:" % splitWord.encode('utf8')) splitWord = turnNumIntoString(splitWord) rhymes = util.findRhymes(splitWord) for i in range(len(rhymes)): text = "%s," % rhymes[i] if i != len(rhymes) - 1 else "%s" % rhymes[i] fo.write(text.encode('utf8')) fo.write("\n") ct += 1 else: print "%i. finding rhyme for: %s" % (ct,word) fo.write("%s:" % word.encode('utf8')) word = turnNumIntoString(word) rhymes = util.findRhymes(word) for i in range(len(rhymes)): text = "%s," % rhymes[i] if i != len(rhymes) - 1 else "%s" % rhymes[i] fo.write(text.encode('utf8')) fo.write("\n") ct += 1 fo.close()
def getRhymeDeduction(self, w1,w2,cost): rhymes1 = util.findRhymes(w1) rhymes2 = util.findRhymes(w2) if w2 in rhymes1 or w1 in rhymes2: return int(cost * 0.8) return 0