I decided to add ruby text in kanji. I made it in the process. Code below
def hiragana_split(s):
    #Divide the original text with hiragana
    #List of Japanese syllabary
    fifty_text = [chr(i) for i in range(12353, 12436)] + ['。', '、']
    split_list = []
    #Whether it is hiragana
    start_point = 0
    section = ''
    for i in range(len(s) - 1):
        if not (s[i] in fifty_text) == (s[i + 1] in fifty_text):
            split_list += [s[start_point:i + 1]]
            start_point = i + 1
    return split_list
if __name__ == '__main__':
    s = 'I have no idea where I was born. I remember only crying in a dim and damp place.'
    print(hiragana_split(s))
# ['where', 'Raw', 'It was', 'Register', 'I can't get it.', 'what', 'But', 'Dim', 'Bullying', 'Place', 'so', 'Meow meow crying', 'Was there', 'Thing', 'Only', 'Memory']
        Recommended Posts