Kozea/Pyphen

length 4

timbrookers opened this issue · 7 comments

Dear

I had followed you advice in using the pyphen.
I do have one more question.
I have question regarding for word with 4 letters. for example, "өвөл"
if i would use the word exactly as written it will give the result as "өвөл"
if i put space before it just like " өвөл" the result would be "ө-вөл", which is correct.

How shall get the desired result?

Thank you in advance.

Sincerely

Batnyam

liZe commented

Hi!

pyphen.Pyphen has left and right parameters defining the minimal number of characters at the beginning and the end of the words. The default value is 2 because many dictionaries don’t work with lower values (and users generally don’t want to get a single letter), but using 1 seems to work for your use case:

>>> dic = pyphen.Pyphen(lang='mn_MN', left=1, right=1)
>>> dic.inserted('өвөл')
'ө-вөл'

Let’s hope that this dictionary works well with one-letter syllables!

liZe commented

Let’s hope that this dictionary works well with one-letter syllables!

It looks like it is 🎉️.

LEFTHYPHENMIN 1
RIGHTHYPHENMIN 1

liZe commented

Sorry, we forgot to answer your previous comment.

Here’s a short sample you can adapt to your needs. It uses colorama that you’ll have to install.

from colorama import Fore, Style
from pyphen import Pyphen

text = 'Наран Лувсан ах олон сонин хэвлэнэ'
colors = (Fore.BLUE, Fore.RED, Fore.CYAN, Fore.MAGENTA, Fore.GREEN)
dic = Pyphen(lang='mn_MN', left=1, right=1)

words = text.split()
split_words = [dic.inserted(word).split('-') for word in words]
colored_split_words = [
    [color + syllable for color, syllable in zip(colors, syllables)]
    for syllables in split_words]
colored_words = [''.join(syllables) for syllables in colored_split_words]
colored_text = ' '.join(colored_words) + Style.RESET_ALL

print(colored_text)

It’s split into different steps with explicit variable names so that you can understand, but you’ll be able to use less code when you’ll be more confident with Python 😀️.

Have fun with Pyphen and Python!

Dear All

I had used the coding as you advised. It is working perfectly.
The converter result i am using in kivy Label. But the colors does not accepted and it is showing the color Code directly together with syllables.
How shall i solve this?

Sincerely

Batnyam

liZe commented

The converter result i am using in kivy Label. But the colors does not accepted and it is showing the color Code directly together with syllables.
How shall i solve this?

I can help you with Pyphen, but I’ve never used Kivy, so I won’t be able to give you a solution for this. You should ask on StackOverflow where you’ll have Kivy gurus!