Payyans

From SMC Wiki

Background

To get you started with basics, we have to start from number system. As you might already know, computers understand only binary data ie zero or one. So how do we represent data in a way computers can understand? Using sequence of ones and zeros we can represent any number. Now what about letters? Character encoding is introduced as a way of representing characters as numbers. In ASCII encoding systems 7 bits (there is 8 bit variant as well) are used to represent a character. Using 7 bits, we can represent up to 2^7 (128) characters. It was sufficient to represent all characters in English/Latin and special characters (including control characters). But there are so many scripts around the world and using 128 numbers we cannot represent all of them.

There were different attempts to solve this issue. For European languages 8 bit ASCII was sufficient. We started using the same numbers (from 0 to 127) to represent characters in Indian languages, but internally the computer still handled it as English characters. But we substituted Indian language characters in font and fooled the computer into thinking we are using Indian languages. This was good enough for displaying Indian Languages on screen and printing, though other important tasks like sorting and searching was impossible, because internally they were still understood as English characters. This technique became widely popular and even now many popular new papers use this system. This kind of technique was so closely tied to a font that it requires the same font used for entering the data to be available on every system one wants to read it.

Now Unicode encoding comes into picture with a promise of uniquely identifying every character in the world. Now the limit of 128 (or 256 with 8 bit ASCII) characters is taken away and it became possible to have separate code points/numbers for each of Indian languages. There are different ways of representing this numbers and these are called encoding methods. Most popular is UTF-8 which uses variable number of bytes to represent a character. There is UTF-16 which uses 16 bits for representing a character. Unicode encoded data can be read using any Unicode font taking away the dependency on a particular font. OpenType specification for fonts has option for substituting sequence of characters with another glyph (glyph is the pictorial representation of a character). This takes care of conjuncts ie ka halant ka (क ् क) is substituted with kka (क्क).

Even though Unicode is used widely on the internet some applications used popularly for DTP still does not support them and many people did not move to Unicode. So there is lot if data encoded in ASCII format which needs to be converted to Unicode if we want to make them, readable without needing a specific font, search-able, sortable ...

Payyans is such a software written in python for converting ASCII font specific data into Unicode. Padma is firefox plugin which does the same for many Indian languages. Now it seems simple to map the ASCII data to its corresponding Unicode, but each font followed its own encoding and for every ASCII font, you need a separate mapping table. Moreover there are script specific reordering, like moving ikar from left to right (in ASCII ikar is added before the conjunct but in Unicode ikar is added after the conjunct), required for proper conversion.

For Devanagari conversion, the requirement is more complex than for Malayalam and so we need to adapt Payyans for supporting Devanagari. Work is already started and it needs handling of some specific cases.

പയ്യന്‍സ്

പയ്യന്‍സ് ആസ്കി ഫോണ്ടുകളുപയോഗിച്ചെഴുതിയ മലയാളത്തെ കമ്പ്യൂട്ടര്‍ പ്രൊസസ്സിങ്ങിനു യോജിച്ച യൂണിക്കോഡ് മലയാളത്തിലേക്കു് മാറ്റുവാനുള്ളാ ഒരു പ്രോഗ്രാമാണു്. ഫോണ്ടു് ഡിപ്പന്റന്‍സി വളരെക്കുറച്ചുകൊണ്ടു് ലളിതമായ ഒരു മാപ്പിങ്ങ് ഫയലിന്റെ സഹായത്തോടെ ടെക്സ്റ്റ്, പീഡിഎഫ് എന്നീ ഫോര്‍മാറ്റുകളില്‍ ആസ്കി ഫോണ്ടുകളുപയോഗിച്ചെഴുതിയ മലയാളത്തെ ഇതു് യൂണിക്കോഡിലേയ്ക്കാക്കുന്നു. യൂണിക്കോഡിലുള്ള ഫയലുകളെ ആസ്കി ഫോണ്ടുകള്‍ക്കു ചേര്‍ന്ന രൂപത്തിലാക്കാനും പയ്യന്‍സ് ഉപയോഗിക്കാം

ഇന്‍സ്റ്റാളേഷന്‍

ഗ്നു/ലിനക്സില്‍

ഡെബിയന്‍/ഉബുണ്ടു ഉപയോക്താക്കള്‍ ഏറ്റവും പുതിയ deb ഇവിടെ നിന്നും ഡൗണ്‍ലോഡ് ചെയ്ത് ഇന്‍സ്റ്റോള്‍ ചെയ്യുക.

ഫെഡോറ ഉപയോക്താക്കള്‍ ഏറ്റവും പുതിയ RPM ഇവിടെ നിന്നും ഡൗണ്‍ലോഡ് ചെയ്ത് ഇന്‍സ്റ്റോള്‍ ചെയ്യുക.

മറ്റ് വിതരണങ്ങള്‍ക്ക് ഉറവയില്‍ നിന്നും ഇന്‍സ്റ്റോള്‍ ചെയ്യാവുന്നതാണ്. പയ്യന്‍സ് ഉറവ ഇവിടെ നിന്നും ഡൗണ്‍ലോഡ് ചെയ്യുക. പൊതിക്കെട്ട് അഴിച്ചതിനു ശേഷം താഴെപ്പറയുന്ന ആജ്ഞ പ്രവര്‍ത്തിപ്പിച്ച് ഇന്‍സ്റ്റോള്‍ ചെയ്യുക:

sudo python setup.py install

വിന്‍ഡോസ്

ആദ്യമായി പൈത്തണിന്റെ വിന്‍ഡോസ് വേര്‍ഷന്‍ ഡൌണ്‍ലോഡ് ചെയ്യണം. 2.5 പതിപ്പു തന്നെ ഡൌണ്‍ലോഡ് ചെയ്യാന്‍ ശ്രദ്ധിക്കുക. പിന്നീട് സോഴ്‌സ് കോഡ് ഇവിടെ നിന്നും ഡൌണ്‍ലോഡ് ചെയ്യുക. സിപ്പ് ഫയലിനെ എക്സ്ട്രാക്റ്റ് ചെയ്തതിനു ശേഷം ആ ഫോള്‍ഡറിലേക്ക് പോവുക(കമാന്റ് പ്രോംപ്റ്റ് എടുത്തു്). അവിടെയുള്ള payyans എന്ന ഫോള്‍ഡറിനകത്ത് പ്രവേശിച്ച്

python payyan.py -i ascii_ml.txt -o unicode_ml.txt -m D:\Payyans\payyansv07\maps\karthika.map -d a2u 

എന്നിങ്ങനെ നല്‍കിയാല്‍ മതി.


ഉപയോഗിക്കുന്ന വിധം

ആസ്കി ഫയലുകളെ യൂണിക്കോഡാക്കാന്‍

ആസ്കി ഫയലിനെ ആദ്യം യുട്ടിഎഫ്-8 ലേയ്ക്കു് മാറ്റണം. താഴെ കൊടുത്ത ആജ്ഞ അതിനുപയോഗിയ്ക്കാം.

iconv -f ISO-8859-1 -t inputfile > output file
payyans -i asciifile.txt -m fontmap.map -o unicodefile.txt -d a2u
payyans -i asciifile.txt -m fontmap.map -d u2a > unicodefile.txt
payyans -m fontmap.map -o unicodefile.txt -d u2a < asciifile.txt
payyans -p -i ascii-pdffile.pdf -m fontmap.map -o  unicodefile.txt -d u2a
payyans --pdf --input-file ascii-pdffile.pdf --mapping-file fontmap.map --output-file unicodefile.txt -d u2a
payyans -h
payyans -v
payyans --help
payyans --version

യൂണിക്കോഡ് ഫയലുകളെ ആസ്കി ഫോണ്ട് എന്‍കോഡിങ്ങിലേക്കു മാറ്റാന്‍

payyans -i unicodefile.txt -m fontmap.map -o asciifile.txt -d u2a


Sample maps can be found in /usr/share/payyans/maps folder after intallation.

പീഡീഎഫ് ല്‍ നിന്നും യൂണിക്കോഡിലേക്കുള്ള മാറ്റം ഗ്നു/ലിനക്സില്‍ മാത്രമേ പ്രവര്‍ത്തിയ്ക്കു.. സ്കാന്‍ ചെയ്ത പീഡിഎഫ് അല്ല, ആസ്കി ഫോണ്ട് എന്‍കോഡ് ചെയ്ത പീഡിഎഫ് ആണു് ഉപയോഗിക്കേണ്ടതു്.

വികസിപ്പിച്ചതു്

  1. സന്തോഷ് തോട്ടിങ്ങല്‍
  2. നിഷാന്‍ നസീര്‍
  3. മനു എസ് മാധവ്
  4. രജീഷ് കെ നമ്പ്യാര്‍

മാപ്പിങ്ങ് ഫയല്‍

പയ്യന്‍സിനു ഒരു മാപ്പിങ്ങ് ഫയല്‍ അത്യാവശ്യമാണു്. ഇതു് ആസ്കി അക്ഷരങ്ങള്‍ക്കു് തത്തുല്യമായ യൂണിക്കോഡ് ഏതെന്നു നിര്‍വചിക്കുന്നു. വളരെ ലളിതമായ ഒരു ടെക്സ്റ്റ് ഫയലാണു് ഇതു്. ആസ്കിഅക്ഷരം=യൂണിക്കോഡ് എന്ന രീതിയിലുള്ള നിയമങ്ങളാണു് അതില്‍ ഉണ്ടാവുക. ആസ്കി ഫോണ്ടുകള്‍ വ്യത്യസ്ത മാപ്പിങ്ങ് ഉപയോഗിക്കുന്നതിനാല്‍ ഓരോ ഫോണ്ടിനും പ്രത്യേകം മാപ്പിങ് ഫയലുകള്‍ വേണം. മാപ്പിങ്ങ് ഫയല്‍ തയ്യാറാക്കാന്‍ ഒരു ടെക്സ്റ്റ് ഫയലില്‍ താഴെക്കാണിച്ചിരിക്കുന്ന ഉദാഹരണം പോലെ നിയമങ്ങളെഴുതി സേവ് ചെയ്യുക

#Give the rules in following format
# # എന്നതില്‍ തുടങ്ങുന്ന വരികള്‍ കമന്റുകളാണു്
w=ം
x=ഃ
A=അ
B=ക
C=ഇ
Cu=ഈ
D=ഉ
Du=ഊ
E=ഋ
F=എ
G=ഏ
sF=ഐ
H=ഒ
Hm=ഓ
Hu=ഔ
I=ക
J=ഖ
K=ഗ
L=ഘ
M=ങ
N=ച
O=ഛ

ഒഴിഞ്ഞ വരികള്‍ പ്രശ്നമല്ല. ഏതെങ്കിലും വരിയില്‍ പ്രശ്നമുണ്ടെങ്കില്‍ അതിന്റെ വിശദാംശങ്ങള്‍ ലൈന്‍ നമ്പര്‍ സഹിതം പ്രോഗ്രാം പറയും

സംരംഭങ്ങള്‍

മലയാളം വിക്കിസോഴ്സ് സംരംഭവുമായി ചേര്‍ന്നു് ആസ്കിയിലുള്ള പഴയ പുസ്തകങ്ങളെ യൂണിക്കോഡിലേക്കാക്കി മാറ്റുന്ന ഒരു സംരംഭം ആരംഭിച്ചിരിക്കുന്നു. ഇതിന്റെ ആദ്യപടിയായി മലയാള വ്യാകരണ ഗ്രന്ഥമായ ഏ.ആര്‍. രാജരാജവര്‍മ്മയുടെ കേരളപാണിനീയം യൂണിക്കോഡിലേയ്ക്കു മാറ്റുന്നു. മലയാളനോവല്‍ സാഹിത്യത്തിനു തുടക്കം കുറിച്ച ഓ.ചന്തുമേനോന്റെ ഇന്ദുലേഖ എന്ന നോവലും യൂണിക്കോഡിലേയ്ക്കു മാറ്റൂം

ശ്രീനാരായണഗുരു സമ്പൂര്‍ണ്ണ കൃതികള്‍ ,പയ്യന്‍സ് ഉപയോഗിച്ച് യൂണിക്കോഡിലേക്കാക്കി വിക്കിഗ്രന്ഥശാലയില്‍ [എത്തിച്ചു https://savannah.nongnu.org/forum/forum.php?forum_id=6471]

For Developers

Payyans provide python APIs and it can be used in your python applications. Some sample code snippets are given below

Ascii to Unicode:

from payyans import Payyans
p=Payyans("input.pdf","unicode.txt","/usr/share/payyans/maps/karthika.map")
p.ascii2unicode()

Unicode to Ascii:

from payyans import Payyans
p=Payyans("unicode.txt","ascii.txt","/usr/share/payyans/maps/karthika.map")
p.unicode2ascii()

ASCII word to Unicode:

from payyans import Payyan
p=Payyan()
p.mapping_filename="/usr/share/payyans/maps/indulekha.map"
unicode_word = p.word2Unicode(ascii_word)

Unicode word to ASCII:

from payyans import Payyan
p=Payyan()
p.mapping_filename="/usr/share/payyans/maps/indulekha.map"
ascii_word = p.word2ASCII(unicode_word)

Payyans Package Help

class Payyans
    |  Methods defined here:
    |  
    |  __init__(self, input_file, output_file, mapping_file)
    |  
    |  ascii2unicode(self)
    |  
    |  unicode2ascii(self)
    |  
    |  word2ASCII(self, unicode_str)
    |  
    |  word2Unicode(self, ascii_str)

How to create a font map?

  1. Install the font in your system if not already done
  2. Save tempalate.map as YourFontName.map
  3. Open YourFontName.map in a text editor, for example gedit or kate
  4. Select the font for the opened document as YourFontName (eg: gedit->preferences->fonts)
  5. In each line replace the question mark at the right side of = sign with what you see at left side of that. For eg: X = ? will be viewed as ത = ? with YourFontName, then make it as ത = ത
  6. Once all lines are finished with left and right side as equal. Your font map is ready!

നന്ദി

  1. ബൈജു. എം
  2. ഷിജു അലക്സ്
  3. അനൂപന്‍
"എന്റെ കമ്പ്യൂട്ടറിനു് എന്റെ ഭാഷ"
ഒരു സ്വതന്ത്ര മലയാളം കമ്പ്യൂട്ടിങ്ങ് സംരംഭം