Пример #1
0
    def test_word2roman(self):
        rhyme = Rhyme("しずおか")
        self.assertEqual(rhyme.roman(), "shizuoka")

        rhyme = Rhyme("シズオカ")
        self.assertEqual(rhyme.roman(), "shizuoka")

        rhyme = Rhyme("静岡")
        self.assertEqual(rhyme.roman(), "shizuoka")
Пример #2
0
    def test_vowel(self):
        rhyme = Rhyme("静岡")
        self.assertEqual(rhyme.vowel(), "iuoa")

        rhyme = Rhyme("ありがとう")
        self.assertEqual(rhyme.vowel(), "aiaou")

        rhyme = Rhyme("パイソン")
        self.assertEqual(rhyme.vowel(), "aion")
Пример #3
0
def get_rhymes(words1_neighbors, words2_neighbors, subword_frequency):
    '''
    Given a two lists of words, attempt to construct rhyme out of each of the
    |words1_neighbors| x |words2_neighbors| many word pairs. Order the generated rhymes
    by quality before returning.
    '''
    # Store the results using a set to avoid duplicates in case the same words appears in both sets
    rhyme_set = set()
    for neighbor1 in words1_neighbors:
        for neighbor2 in words2_neighbors:
            # If the words are identical, as sometimes happens, skip this word pair
            if neighbor1.grapheme == neighbor2.grapheme:
                continue
            # Generate the rhyme for only a single ordering, if the words need to be flipped
            # for quality reasons, that's handled within the 'get_rhyme' function
            # Not ideal that 'subword_frequency' has to be passed twice... consider refactoring
            rhyme, status, message = Rhyme.get_pun(neighbor1, neighbor2, subword_frequency)
            if status == 0:
                rhyme_set.add(rhyme)

    # Order the results in terms of rhyme quality, with better rhymes appearing earlier
    rhyme_list = list(rhyme_set)
    rhyme_list.sort(key=lambda x: x.ordering_criterion())

    return rhyme_list
def get_rhymes(words1_neighbors, words2_neighbors):
    '''
    Given a two lists of words, attempt to construct rhyme out of each of the
    |words1_neighbors| x |words2_neighbors| many word pairs. Order the generated rhymes
    by quality before returning.
    '''
    # Store the results using a set to avoid duplicates in case the same words appears in both sets
    rhyme_set = set()
    for neighbor1 in words1_neighbors:
        for neighbor2 in words2_neighbors:
            # If the words are identical, or one of the graphemes is black-listed, skip this word pair
            if neighbor1.grapheme == neighbor2.grapheme or neighbor1.grapheme.lower() in GRAPHEME_BLACKLIST or neighbor2.grapheme.lower() in GRAPHEME_BLACKLIST:
                continue
            # Generate the rhyme for only a single ordering, if the words need to be flipped
            # for quality reasons, that's handled within the 'get_rhyme' function
            rhyme, status, message = Rhyme.get_pun(neighbor1, neighbor2)
            if status == 0:
                rhyme_set.add(rhyme)

    # Order the results in terms of rhyme quality, with better rhymes appearing earlier
    rhyme_list = list(rhyme_set)
    rhyme_list.sort(key=lambda x: x.ordering_criterion())

    return rhyme_list
Пример #5
0
    def test_rhyme(self):
        rhyme = Rhyme("ありがとう")
        self.assertEqual(rhyme.rhyme(), "オリゴ糖")

        rhyme = Rhyme("ありがとう", len("ありがとう"))
        self.assertEqual(rhyme.rhyme(), "大麻草")

        rhyme = Rhyme("パイソン")
        self.assertEqual(rhyme.rhyme(), "厚切りジェイソン")

        rhyme = Rhyme("パイソン", len("パイソン"))
        self.assertEqual(rhyme.rhyme(), "")
Пример #6
0
def rhyme(word):
    return str(Rhyme(word))