Kozea / Pyphen

Hy-phen-ation made easy
https://courtbouillon.org/pyphen
Other
198 stars 24 forks source link

length 4 #46

Closed timbrookers closed 1 year ago

timbrookers commented 1 year ago

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 1 year ago

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 1 year ago

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

It looks like it is 🎉️.

https://github.com/Kozea/Pyphen/blob/ebc37d13b83a77e2376d6a72e92ac5356e07883d/pyphen/dictionaries/hyph_mn_MN.dic#L14-L15

timbrookers commented 1 year ago

Hello there

Well done thank you.

I have another question, would it we possible to use color for syllables. I mean using different colors to define the syllables. For example in my case, ө-вөл, ө would be let's say Red color and вөл would be in blue color

Sincerely

Batnyam

On Fri, Dec 16, 2022, 10:33 PM Guillaume Ayoub @.***> wrote:

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!

— Reply to this email directly, view it on GitHub https://github.com/Kozea/Pyphen/issues/46#issuecomment-1354945530, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEQWC5HF6ODCLQUP4CIYWLWNR4T3ANCNFSM6AAAAAAS6ICV4Y . You are receiving this because you authored the thread.Message ID: @.***>

liZe commented 1 year ago

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!

timbrookers commented 1 year ago

Awesome, thanks!

On Sat, Dec 17, 2022 at 2:53 AM Guillaume Ayoub @.***> wrote:

Sorry, we forgot to answer your previous comment.

Here’s a short sample you can adapt to your needs. It uses colorama https://pypi.org/project/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!

— Reply to this email directly, view it on GitHub https://github.com/Kozea/Pyphen/issues/46#issuecomment-1355419889, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEQWC5GTRQ22FQ5KN3EI23WNS3B5ANCNFSM6AAAAAAS6ICV4Y . You are receiving this because you authored the thread.Message ID: @.***>

timbrookers commented 1 year ago

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 1 year ago

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!