From e0afca6e304a496f109601fc4633491c8573b525 Mon Sep 17 00:00:00 2001 From: Vishnu Sanal T <50027064+VishnuSanal@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:22:23 +0530 Subject: [PATCH] Add functions to list available maps & to view the mappings for a given map (#20) * list available maps * print map * update README with usage of map listing functions * Update README.md --- README.md | 21 +++++++++++++-------- libindic/payyans/core.py | 12 ++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ba7917a..798347f 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,19 @@ to Unicode and vice-versa. More fonts can be added by placing their maps in ## Usage ``` ->>> from libindic.payyans import Payyans ->>> instance = Payyans() ->>> result = instance.ASCII2Unicode("aebmfw", "ambili") ->>> print(result) -മലയാളം ->>> result2 = instance.Unicode2ASCII(u"കേരളം", "ambili") ->>> print(result2) -tIcfw +from libindic.payyans import Payyans + +instance = Payyans() + +result = instance.ASCII2Unicode("aebmfw", "ambili") +print(result) # മലയാളം + +result2 = instance.Unicode2ASCII(u"കേരളം", "ambili") +print(result2) # tIcfw + +instance.listAvailableMaps() # Haritha, ML-TTAmbili, ML-TTKarthika, ML-TTNandini, ML-TTRevathi, MLB-TTIndulekha, Manorama, Matweb, TM-TTValluvar, banglapedia, charaka, panchari, revathi, uma + +instance.printMap('Haritha') # prints the whole mapping file ``` [Watch this video to know more about what ASCII and Unicode encodings are](https://smc.org.in/articles/ascii-unicode-fonts) diff --git a/libindic/payyans/core.py b/libindic/payyans/core.py index 74226bf..5f0a3be 100755 --- a/libindic/payyans/core.py +++ b/libindic/payyans/core.py @@ -135,6 +135,18 @@ def ASCII2Unicode(self, ascii_text, font): return unicode_text # മതം മാറ്റി തിരിച്ചു കൊടുക്ക്വാ ! + def listAvailableMaps(self): + for key in maps.keys(): + print(key, end=", ") + + def printMap(self, font): + rules = self.getRules(font) + + print("{:<3} {:<6}".format('Key', 'Target')) + + for key, val in rules.items(): + print("{:<2} : {:<3}".format(key, val), end="\n") + def getVowelSign(self, vowel_letter, vowel_sign_letter): vowel = vowel_letter.encode('utf-8') vowel_sign = vowel_sign_letter.encode('utf-8')