Skip to content

Commit

Permalink
feat: use libindic-unicode-conversion-maps
Browse files Browse the repository at this point in the history
To get template to automatically populate font list we are also making
a change in libindic-web which passes in any "data" attribute back
into the template during rendering
  • Loading branch information
asdofindia committed Oct 23, 2023
1 parent 908e8a9 commit c5d838f
Show file tree
Hide file tree
Showing 17 changed files with 12 additions and 2,534 deletions.
71 changes: 6 additions & 65 deletions libindic/payyans/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import codecs # കൊടച്ചക്രം
import os # ശീലക്കുട
from libindic.normalizer import Normalizer
from libindic.unicode_conversion_maps import maps
from .reader import Reader


Expand All @@ -55,16 +56,15 @@ def __init__(self):
self.mapping_filename = ""
self.rulesDict = None
self.pdf = 0
self.data = {"fonts": maps.keys()}
self.normalizer = Normalizer()

def Unicode2ASCII(self, unicode_text, font):
unicode_text = self.normalizer.normalize(unicode_text)
index = 0
ascii_text = ""
self.direction = "u2a"
self.mapping_filename = os.path.join(os.path.dirname(__file__),
'maps', font + ".map")
self.rulesDict = self.LoadRules()
rulesReverse = maps[font]
self.rulesDict = {v: k for k, v in rulesReverse.items()}
while index < len(unicode_text):
'''കൂട്ടക്ഷരങ്ങള്‍ക്കൊരു കുറുക്കുവഴി'''
for charNo in [3, 2, 1]:
Expand Down Expand Up @@ -104,10 +104,7 @@ def Unicode2ASCII(self, unicode_text, font):
return ascii_text

def ASCII2Unicode(self, ascii_text, font):
self.direction = "a2u"
self.mapping_filename = os.path.join(os.path.dirname(__file__),
'maps', font + ".map")
self.rulesDict = self.LoadRules()
self.rulesDict = maps[font]

prebase_ascii_letters = [k for k, v in self.rulesDict.items() if v in prebase_letters]
postbase_ascii_letters = [k for k, v in self.rulesDict.items() if v in postbase_letters]
Expand Down Expand Up @@ -174,69 +171,13 @@ def isPostbase(self, letter):
'''
return letter in postbase_letters

def LoadRules(self):
'''
ഈ സംഭവമാണു് മാപ്പിങ്ങ് ഫയല്‍ എടുത്തു് വായിച്ചു പഠിക്കുന്നതു്.
'''
# if(self.rulesDict):
# return self.rulesDict
rules_dict = dict()
line = []
line_number = 0
rules_file = codecs.open(self.mapping_filename, encoding='utf-8',
errors='ignore')
while True:
'''
ലൈന്‍ നമ്പര്‍ , മാപ്പിങ്ങ് ഫയലില്‍ തെറ്റുണ്ടെങ്കില്‍
പറയാന്‍ ആവശ്യാണു്
'''
line_number = line_number + 1
original_text = rules_file.readline()
try:
text = unicode(original_text) # noqa: F821
except BaseException:
text = original_text
if text == "":
break
'''കമന്റടിച്ചേ മത്യാവൂന്നു വെച്ചാ ആവാം. ഒട്ടും മുഷിയില്ല്യ'''
if text[0] == '#':
continue
'''
കമന്റടി പതിവുപോലെ മൈന്റ് ചെയ്യണ്ട ഒന്നും കണ്ടില്യാ
കേട്ടില്യാന്നു വെച്ചു നടന്നോളൂ(മനസ്സില്‍ ചിരിച്ചോളൂ)
'''
line = text.strip()
if(line == ""):
continue
'''ലൈനൊന്നും ല്യാ, മോശം.. ങും പോട്ടെ. വേറെ ലൈന്‍ പിടിക്കാം'''
if(len(line.split("=")) != 2):
'''എന്തോ പ്രശ്നണ്ടു്. ന്നാ അതങ്ങടു തുറന്നു പറഞ്ഞേക്കാം'''
print("Error: Syntax Error in the Ascii to Unicode Map "
"in line number ", line_number)
print("Line: " + text)
'''പരിപാടി നിര്‍ത്താം '''
return 2 # Error - Syntax error in Mapping file
'''ഇടതന്‍'''
lhs = line.split("=")[0]
'''വലതന്‍'''
rhs = line.split("=")[1]
'''ഇതിനിടക്കിനി മൂന്നാമനു സ്കോപ്പിണ്ടോ? '''
'''മറക്കാതെ ഇരിക്കട്ടെ. ആവശ്യം വരും '''
lhs = lhs.strip()
rhs = rhs.strip()
if self.direction == 'a2u':
rules_dict[lhs] = rhs
else:
rules_dict[rhs] = lhs
rules_file.close()
return rules_dict

def get_module_name(self):
return "Payyans Unicode-ASCII Converter"

def get_info(self):
return "ASCII data - Unicode Convertor based on font maps"



def getInstance():
return Payyans()
191 changes: 0 additions & 191 deletions libindic/payyans/maps/ambili.map

This file was deleted.

Loading

0 comments on commit c5d838f

Please sign in to comment.