Skip to content

LTN/Plone

Sections
Personal tools
You are here: Home » Members » poonlap's Home » dictd

English - Thai dictd database

ฐานข้อมูลพจนานุกรม อังกฤษ - ไทย สำหรับ dictd

DICT โปรโตคอล

DICT โปรโตคอลเป็น RFC (Request For Comment) ที่เรียกว่าเป็นโปรโตคอลกึ่งมาตรฐานสำหรับการสร้างพจนานุกรมแบบ server-client. ในโปรโตคอลนี้ได้กำหนดกฏเกณฑ์เกี่ยวกับเซิฟร์เวอร์ไว้หลายอย่างเช่น
  • เซิฟร์เวอร์จะใช้ TCP โปรโตรคอลทางพอร์ต 2628
  • เซิฟร์เวอร์สามารถเก็บฐานข้อมูลของพจนานุกรมได้หลายฉบับ.
  • เซิฟร์เวอร์เป็นตัวโต้ตอบกับ client โดยการรับคำที่ต้องการหาแล้วตอบความหมายกลับไป. ฟอร์แมตที่จะตอบกลับไม่ได้ระบุไว้ว่าต้องเป็นอย่างไร.
  • เซิฟร์เวอร์มี strategy รองรับในการหาคำให้เช่น define, match, regular expression, soundex, lev เป็นต้น.

dictd - dict

dictd เป็นเซิฟร์เวอร์ที่สร้างตามข้อกำหนดของ DICT โปรโตคอล. ส่วน dict เป็นโปรแกรมติดต่อกับเซิฟร์เวอร์แบบบรรทัดคำสั่ง. ส่วน client อื่นๆที่เป็นที่รู้จักกันดีได้แก่ kdict. นอกจาก client ที่เป็นโปรแกรมแล้วยังทำเป็น web interface แบบ dict.org ได้ด้วย.

ฐานข้อมูลพจนานุกรม

ฐานข้อมูลพจนานุกรมของ dictd เป็นพจนานุกรมที่เผยแพร่ฟรีเช่น FOLDOC, Webster ฯลฯ.

ฐานข้อมูลภาษาไทยไม่รู้ว่ามีใครหรือยังเลยลองเอาข้อมูลของ HopeDict มาทำดู. แต่ก็ไม่ได้เอาข้อมูลมาจาก HopeDict โดยตรง, เอามาจาก KdictThai. Perl สคริปต์ (ส่วนหนึ่งของ cetdict) ต่อไปนี้จะเอาข้อมูลออกมาจาก dictdata.db ซึ่ง Berkley DB แล้วเขียนเป็น plain text ให้. สำหรับเรื่องราวเกี่ยวกับ dictdata.db อ่านเรื่องที่เกี่ยวข้องได้จาก cetdict.

#!/usr/bin/perl
use DB_File;
 
$dictfile = "/usr/share/dict/th/dictdata.db";
 
$DB = tie %hash,  'DB_File', $dictfile, O_RDONLY, 0000, $DB_BTREE
    or die "Can not open $dictfile";
 
while( ($k, $v) = each(%hash)){
    chop($k);
    chop($v);
    chop($v);
 
    print "_____\n\n";
    print "$k\n";
    print "$k ";
    print format_result($v), "\n";
 
}
 
 
my @keywords = ("abbr.", "fr.", "adj.", "adv.", "Music.", "n.", "L.", "pl.",
                "prep.", "vt.", "vi.", "pt.", "pp.", "pron.", "v.", "interj.",
                "conj.", "adj.,n.", "adj.,adv.");
                                                                                
sub format_result {
    my $line = shift;
    $line =~ s/(^\(.+\){1}) / $1\n/;# check reading first
    $line = "\n" . $line if ( $1 eq "");# newline if no reading
    $line =~ s/\#\#\#S./\n\nSynonym: /;
    $line =~ s/\#\#\#A./\nAnonym: /;
    foreach $i (@keywords)
    {
        $line =~ s/\s${i}\s/\n${i} /;
    }
    $line .= $reset;
    return $line;
}

แล้วก็จะได้ไฟล์ผลลัพธ์, สมมติให้เป็นชื่อ thaihope.tis-620. ไฟล์นี้จริงๆแล้วแก้ไขด้วยมือเล็กน้อยเพราะมีส่วนที่ไม่ถูกต้องอยู่.

เตรียมฐานข้อมูล

เมื่อได้ไฟล์ thaihope.tis-620 แล้วก็แปลงเป็น UTF-8 เพื่อที่จะไปใช้กับ dictd.
$ iconv -f tis620 -t utf8 -o thaihope.utf-8 thaihope.tis-620
จริงๆแล้วไม่แปลงเป็น UTF-8 ก็ได้แต่ควรจะใช้ UTF-8 จะได้ถูกต้องตามสากลและใช้ RFC ข้างบนก็แนะนำด้วย.

แก้ไขไฟล์ thaihope.utf-8 โดยการเพิ่มข้อมูลเกี่ยวกับเนื้อหาความเป็นมาของพจนานุกรม. แล้วก็สั่งคำสั่งดังนี้.

$ dictfmt -c5 thaihope < thaihope.utf-8
เสร็จแล้วก็จะได้ไฟล์สองไฟล์คือ thaihope.dict และ thaihope.index. ให้เอาไฟล์สองไฟล์นี้ไปไว้ที่ dictd จะหาเจอเช่น /usr/lib/dict. แต่ก่อนจะเอาไปไว้ให้บีบอัดไฟล์ thaihope.dict เพื่อให้ขนาดเล็กลง.
$ dictzip thaihope.dict
แล้วจะได้ไฟล์ thaihope.dict.dz.

ดาว์นโหลด

ติดตั้ง

เอาไฟล์ thaihope.dict.dz และ thaihope.index ไปไว้ที่ที่ dictd จะหาเจอเช่น /usr/lib/dict/ แล้วรัน dictd
# /etc/init.d/dictd start
 * Starting dictd...
 * Scanning for dictionaries...
 * Done, 3 dictionary indexes found.                                      [ ok ]
ในเครื่องนี้มีพจนานุกรม 3 เล่มซึ่งหนึ่งในนั้นคือ thaihope.

Kdict

ให้ใช้ kdict เพื่อติดต่อกับเซิฟร์เวอร์ (localhost).

ตั้งค่า hostname จาก "Settings"->"Configure Kdict" ให้เป็น localhost. และคลิ้ก "Server"->"Get capabilities" ก็จะเห็น thaihope ปรากฏอยู่.

gnome-dict

"Edit"->"Preference" ให้ server เป็น localhost และเลือกพจนานุกรมภาษาไทยเป็นปริยาย. ตอนนี้มี bug ที่ไฟล์ข้อมูลคือมันจะมองไม่เห็นชื่อพจนานุกรม.

คำสั่ง dict

dict เป็นโปรแกรมแบบบรรทัดคำสั่งตัวอย่างการใช้เช่น
$ dict dict://localhost/d:dictionary:thaihope
$ dict -s regexp dict://localhost/m:dict:thaihope
$ dict -d thaihope -h localhost -s regexp "^t.*y$"

Created by poonlap
Last modified 2005-06-01 02:35 PM
 

Powered by Plone

This site conforms to the following standards: