Saturday, April 28, 2007

Proper conversion of Mueller dictionary to Unicode

Note: this article is a (bad) translation of my article on this subject written in russian.

This article describes more proper than Ubuntu (and maybe Debian) current package offers conversion of a Mueller dictionary to Unicode (UTF-8) with consequent conversion to dict format.
There is some reasons for doing this job:
  • Existing conversion from Mueller to dict has a few first dictionary articles corrupted (the ones that describe dictionary terms). I suppose this was caused by executing conversion script (to-dict) in the wrong locale. It should be executed in KOI8-R, not UTF-8.
  • More to that, original dictionary contains not just plain KOI8-R text, but SilIPA-encoded word transcriptions too. These transcriptions should be handled separately with "SilIPA-to-Unicode IPA Extensions" conversion.
  • More to that, the script to-dict itself contains a little bug, which caused some words starting with non-alphabetical character (dictionary terms, other words starting with dash or apostroph -- like 'cause, -shaped) to be excluded from dictionary index at all!

So I've decided to convert dictionary by myself. If you want to convert dictionary using my method, you'll have to download my script correct-translation.pl and corrected script to-dict (corrections -- script text converted to UTF-8 and options --allchars --utf8 in dictfmt call).

So, lets start. First of all, create temporary directory and put there original dictionary and those scripts:

~$ mkdir /tmp/mutf
~$ cd /tmp/mutf/
/tmp/mutf$ wget http://uj2.h15.ru/mutf/correct-translation.pl
...
/tmp/mutf$ wget http://uj2.h15.ru/mutf/to-dict
...
/tmp/mutf$ wget http://some.where/Mueller7GPL.koi
...
/tmp/mutf$ chmod 755 correct-translation.pl to-dict
/tmp/mutf$ ls -l
итого 5608
-rwxr-xr-x 1 andrey andrey 531 2005-07-06 16:20 correct-translation.pl
-rw-r--r-- 1 andrey andrey 5714222 2005-07-06 16:23 Mueller7GPL.koi
-rwxr-xr-x 1 andrey andrey 6302 2005-07-06 16:22 to-dict
/tmp/mutf$
Note: sorry, I can't put this scripts to some more "permanent" storage, but I can mail them to you if you can't download them.
Now, we're going to translate dictionary to UTF-8. Firstly, we need to convert dictionary using iconv and then, we need to correct transcriptions with correct-translation.pl:
/tmp/mutf$ cat Mueller7GPL.koi | iconv -f koi8-r -t utf-8 | \
> ./correct-translation.pl > Mueller7GPL.utf && rm -f Mueller7GPL.koi
/tmp/mutf$
Now we will convert dictionary to dict format:
/tmp/mutf$ ./to-dict --src-data Mueller7GPL.utf mueller7.data
Writing the header of mueller7.data..
Formatting data (Mueller7GPL.utf -> mueller7.data)..
.
/tmp/mutf$ ./to-dict --data-dict mueller7.data mueller7 && rm -f mueller7.data
dictfmt: mueller7.data -> mueller7.dict and mueller7.index..
46185 headwords
Compressing mueller7.dict..
.
/tmp/mutf$
Now we just need to install dictionary:
/tmp/mutf$ cp mueller7.* /usr/share/dictd/
/tmp/mutf$ dictdconfig -w && (killall dictd; dictd)
Resulting article can look like this: