File size: 1,037 Bytes
e4b9a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
from typing import List

from pythainlp.corpus import thai_words
from pythainlp.khavee import KhaveeVerifier
from pythainlp.tokenize import syllable_tokenize

kv = KhaveeVerifier()
all_thai_words_dict = None


def rhyme(word: str) -> List[str]:
    """
    Find Thai rhyme

    :param str word: A Thai word
    :return: All list Thai rhyme words
    :rtype: List[str]

    :Example:
    ::

        from pythainlp.util import rhyme

        print(rhyme("จีบ"))
        # output: ['กลีบ', 'กีบ', 'ครีบ', ...]
    """
    global all_thai_words_dict
    list_sumpus = []
    if all_thai_words_dict == None:
        all_thai_words_dict = [
            i for i in list(thai_words()) if len(syllable_tokenize(i)) == 1
        ]
    for i in all_thai_words_dict:
        if kv.is_sumpus(word, i) and i != word:
            list_sumpus.append(i)
    return sorted(list_sumpus)