CBETA 論壇 Goto CBETA
四月 19, 2024, 02:51:40 下午 *
歡迎光臨, 訪客. 請先 登入註冊一個帳號.

請輸入帳號, 密碼以及預計登入時間
新聞: 即日起歡迎使用 CBETA 新版討論區,本討論區僅供閱讀。
 
   首頁   說明 搜尋 登入 註冊  
頁: [1] 2 3
  列印  
作者 主題: 已將佛學字典(EBS)轉成標準字典檔(DICT Protocol),可用於Unix-like系統中的dictd  (閱讀 88510 次)
wxy
一星級
*
文章: 21


« 於: 六月 16, 2008, 07:28:00 下午 »

前段時間研究了一下DICT協議,寫了一個簡單Code,把佛學字典(EBS)的 .tit 和 .nr 合並,成 C5 格式的字典文件(DICT標準字典檔的一種),再經 dictfmt 轉成 dictd 可用的字典及索引,可以用標準客戶端程序 dict 來訪問了。這樣就可以在 Unix-like 的系統中使用佛學字典了。如果有主機提供訪問,就可以成為線上字典。使用 DICT 標準協議的好處是有許多不同平臺的客戶端 dict 程序可直接使用字典服務。有手機端的客戶程序,也有 Web-front 的客戶端可用瀏覽器來訪問的。

末學已將字典放在 sourceforge 上了,可以在 http://sourceforge.net/projects/budict/ 下載,歡迎大家使用。另在測試中發現字典有亂碼,查了一下,是原始文件就有少量亂碼,所以下一步要做的是校對字典。懇請有 plain text 格式文件的大德惠賜文檔,以便末學校對,去除亂碼,歡迎志願者一同來做校對。

字典使用的 screen snapshot:
已記錄

諸惡莫作
眾善奉行
wxy
一星級
*
文章: 21


« 回覆文章 #1 於: 六月 18, 2008, 03:47:58 上午 »

字典用了壓縮方式,共約14M,連同轉檔程序一起打包。如果手邊
有原 EBS 的字典,可以直接用程序把 .tit 和 .nr 文件轉成標準字
典檔,不必下載14M的打包文件,以節省網絡流量。源碼如下:

程式碼:
/*-
 * This program will combine .tit and .nr made by EBS into
 * one c5 format dict file.
 *
 * $Id: fo2dict.c,v 1.1 2008/06/15 02:14:11 wxy Exp $
 */

#include <stdio.h>

int main(int argc, char *argv[])
{
        FILE *f1, *f2;
        char fn1[256], fn2[256];
        int lf, cr, ul;
        int c1, c2, len1, len2, max1, max2, total;
        int i;
        int next;

        lf = (int) '\n';
        cr = (int) '\r';
        ul = (int) '_';
        next = 1;
        len1 = len2 = max1 = max2 = total = 0;

        if (argc != 2) {
                fprintf(stderr, "Usage: %s <file base>\n", argv[0]);
                return 1;
        }
        sprintf(fn1, "%s.tit", argv[1]);
        sprintf(fn2, "%s.nr", argv[1]);
        f1 = fopen(fn1, "r");
        if (NULL == f1) {
                fprintf(stderr, "Open %s failure!\n", fn1);
                return 1;
        }
        f2 = fopen(fn2, "r");
        if (NULL == f2) {
                fprintf(stderr, "Open %s failure!\n", fn2);
                return 1;
        }
        while ((c1 = getc(f1)) != EOF) {
                if (next) {
                        putc(lf, stdout);
                        for (i = 0; i < 5; i++) putc(ul, stdout);
                        putc(lf, stdout);
                        putc(lf, stdout);
                        next = 0;
                }
                if (0 == c1) {
                        total++;
                        putc(lf, stdout);
                        len1 = 0;
                        len2 = 0;
                        while ((c2 = getc(f2)) != EOF) {
                                if (0 == c2) break;
                                if (c2 != cr) putc(c2, stdout);
                                len2++;
                        }
                        max2 = len2 > max2 ? len2 : max2;
                        next = 1;
                        continue;
                }
                len1++;
                max1 = len1 > max1 ? len1 : max1;
                if (c2 != cr) putc(c1, stdout);
        }
        fclose(f1);
        fclose(f2);
        fprintf(stderr, "max len of key: %6d\n", max1);
        fprintf(stderr, "max len of con: %6d\n", max2);
        fprintf(stderr, "total key:      %6d\n", total);
        return 0;
}

README:
程式碼:
This project was created to transform Buddhadharma dictionaries
originally made by Electronic Buddhadharma Society (EBS) into
standard dictionary format of DICT protocol. Then dictionaries
can be access by a dictd server remotely or locally. The server
information are as follows:

  dictd 1.10.2/rf on FreeBSD 4.11-RELEASE
  On 127.0.0.1: up 07:45:04, 36 forks (4.6/hour)
 
  Database      Headwords         Index          Data  Uncompressed
  dfb                  31592        484 kB       2995 kB       5617 kB
  chen                  5875         78 kB        250 kB        489 kB
  szfs                  8781        144 kB       1057 kB       2274 kB
  fxcdtb                1045         16 kB        297 kB        646 kB
  fymyj                 1090         15 kB        237 kB        398 kB
  wdhy                  2050         41 kB        818 kB       1522 kB
  english-chinese       9948        181 kB       1245 kB       3019 kB
  fxcd                 14692        272 kB       2552 kB       5623 kB
  zen560                 552         11 kB        222 kB        405 kB
  theravada             1510         29 kB        196 kB        528 kB
  syfy                   571          8 kB        201 kB        330 kB
  yzcj                  1706         52 kB        296 kB        604 kB
  ldgs                  2126        105 kB       1682 kB       2505 kB

About 15M disk size needed in compressed. All .dict.dz and .index
are in data/ directory, and rfc2229.txt in doc/ directory. Later
more documentation will be written include Chinese translation.
Some scripts (dictd.conf, dictd.sh, and so on) are in examples/
directory. In src/ directory, fo2dict.c will convert .tit and .nr
files into standard dictionary format, and then can be processed
by `dictfmt' to make .dict and .index file. The usage is very
simple, compile it as:

% gcc -o fo2dict fo2dict.c

And suppose dfb.tit and dfb.nr are in the same directory, then

% ./fo2dict dfb

Then a C5 dictionary format will be output on stdout, and some
statistic information are shown in stderr. So if you want to save
it as file, just type:

% ./fo2dict dfb > dfb.c5.txt

To make .dict and .index, type

% dictfmt -c5 --allchars --locale zh_TW.Big5 dfb < dfb.c5.txt
INSTALL:
程式碼:
Please read README first. Before installing, make sure you have:

* dictd (better version 1.10.2 or later), if not, download it
  http://sourceforge.net/projects/dict/
* Chinese (Big5) input method available, and a terminal that
  can show Chinese characters such as rxvt, if not, please find
  Chinese-Howto documentation on your Unix-like system.

Then unpack the tarball as:

% tar zxvf budict.tar.gz -C /tmp
% cd /tmp/budict/examples
% ./dictd.sh start

To make sure if the dictd is running, try this:

% ps -ax | grep dictd

If you can see it is in the process list, then try:

% dict -I

you will get:

  dictd 1.10.2/rf on FreeBSD 4.11-RELEASE
  On 127.0.0.1: up 04:19:21, 4 forks (0.9/hour)
 
  Database      Headwords         Index          Data  Uncompressed
  dfb                  31592        484 kB       2995 kB       5617 kB
  chen                  5875         78 kB        250 kB        489 kB
  szfs                  8781        144 kB       1057 kB       2274 kB
  fxcdtb                1045         16 kB        297 kB        646 kB
  fymyj                 1090         15 kB        237 kB        398 kB
  wdhy                  2050         41 kB        818 kB       1522 kB
  english-chinese       9948        181 kB       1245 kB       3019 kB
  fxcd                 14692        272 kB       2552 kB       5623 kB
  zen560                 552         11 kB        222 kB        405 kB
  theravada             1510         29 kB        196 kB        528 kB
  syfy                   571          8 kB        201 kB        330 kB
  yzcj                  1706         52 kB        296 kB        604 kB
  ldgs                  2126        105 kB       1682 kB       2505 kB

That means the dictd works correctly, then you can try this:

% dict amitabha

The description of the word will be shown. And sure you can type
in Traditional Chinese characters after `dict'.

N.B.: All the examples supposed that you unpack the tarball in
directory `/tmp/budict', and if you unpack it into another dir,
please change directorys in dictd.conf which announcing the
.dict.dz and .index, and in dictd.sh (-c /tmp/budict/examples).
BTW, the DICTD macro in dictd.sh should also been set to the
right full path in your system because not all of the system
have the same default path.
dictd.conf:
程式碼:
database dfb {
        data "/tmp/budict/data/00dfb.dict.dz"
        index "/tmp/budict/data/00dfb.index"
}
database chen {
        data "/tmp/budict/data/01chen.dict.dz"
        index "/tmp/budict/data/01chen.index"
}
database szfs {
        data "/tmp/budict/data/02szfs.dict.dz"
        index "/tmp/budict/data/02szfs.index"
}
database fxcdtb {
        data "/tmp/budict/data/03fxcdtb.dict.dz"
        index "/tmp/budict/data/03fxcdtb.index"
}
database fymyj {
        data "/tmp/budict/data/04fymyj.dict.dz"
        index "/tmp/budict/data/04fymyj.index"
}
database wdhy {
        data "/tmp/budict/data/05wdhy.dict.dz"
        index "/tmp/budict/data/05wdhy.index"
}
database english-chinese {
        data "/tmp/budict/data/06english-chinese.dict.dz"
        index "/tmp/budict/data/06english-chinese.index"
}
database fxcd {
        data "/tmp/budict/data/07fxcd.dict.dz"
        index "/tmp/budict/data/07fxcd.index"
}
database zen560 {
        data "/tmp/budict/data/08560.dict.dz"
        index "/tmp/budict/data/08560.index"
}
database theravada {
        data "/tmp/budict/data/09theravada.dict.dz"
        index "/tmp/budict/data/09theravada.index"
}
database syfy {
        data "/tmp/budict/data/10syfy.dict.dz"
        index "/tmp/budict/data/10syfy.index"
}
database yzcj {
        data "/tmp/budict/data/11yzcj.dict.dz"
        index "/tmp/budict/data/11yzcj.index"
}
database ldgs {
        data "/tmp/budict/data/12ldgs.dict.dz"
        index "/tmp/budict/data/12ldgs.index"
}
dictd.sh:
程式碼:
#!/bin/sh

DICTD="/usr/local/sbin/dictd"

case "$1" in
        restart )
                $0 stop
                sleep 2
                $0 start
                ;;
        stop )
                killall dictd
                ;;
        start )
                echo ' Starting dictd service...'
                ${DICTD} -c /tmp/budict/examples/dictd.conf --locale zh_TW.Big5 > /dev/null &
                ;;
esac
ACKNOWLEDGEMENT:
程式碼:
The original data is from Electronic Buddhadharma Society (EBS)
and has been transformed into standard dictionary format following
DICT protocol. The transformation was made automatically by
programme. The website of Electronic Buddhadharma Society is:

http://www.baus-ebs.org/

末學所用系統是 FreeBSD,dictd 版本是 1.10.2,轉換成 C5 格式後,可
以在第一個``_____''之上加上上面 ACKNOWLEDGEMENT 內容,將成為
字典的前言聲明。這個 C5 格式的文件是可編輯的字典檔,如內容有誤,可
以編輯修改,確認無誤後,再用 dictfmt 生成 .dict 和 .index 文件。

已記錄

諸惡莫作
眾善奉行
cbeta
備位版工
四星級
*****
文章: 219


很高興能為您服務


個人網站
« 回覆文章 #2 於: 六月 18, 2008, 07:57:24 上午 »

謝謝 wxy 提供的資料, 因為我們很少用 unix 系統, 所以不清楚相關的資訊.

星際譯王 (http://stardict.sourceforge.net/cn/index.php) 也是不錯的一套軟體, 可以在某些 unix 下執行,
也有 windows 及 mac 的版本, 或許做成這種格式也是不錯的選擇.
已記錄

CBETA 中華電子佛典協會
地址: 11246 台北市北投區光明路276號4樓 
電話: +886-2-28932133
網站: http://www.cbeta.org
電子郵件: service@cbeta.org
贊助資訊: http://www.cbeta.org/donation/index.php
wxy
一星級
*
文章: 21


« 回覆文章 #3 於: 六月 30, 2008, 01:21:04 上午 »

謝謝 wxy 提供的資料, 因為我們很少用 unix 系統, 所以不清楚相關的資訊.

星際譯王 (http://stardict.sourceforge.net/cn/index.php) 也是不錯的一套軟體, 可以在某些 unix 下執行,
也有 windows 及 mac 的版本, 或許做成這種格式也是不錯的選擇.

不敢當,芹曝之獻,不足道。

星際沒用過,看了網站說明,其字典格式是專有的,近期
開始收費。另其使用圖形界面,有太多的 Features,有
些臃腫,對於僅僅使用文字字典者來說,不用這些特性。

末學創建這個項目初衷,是提供一個可以自由使用的在線
佛學辭典,符合標準 DICT 協議,開放源碼。目前使用的
版權是 Public Domain License,是最自由的一種開源
版權。另外基於 Telnet 方式的 BBS 可以使用字符界面
的標準客戶端程序提供在線字典功能。

剛剛將可編輯的字典文件上傳到
http://sourceforge.net/projects/budict/
是 C5 格式的 plain text 文件。可以編輯字典內容,
然後用 dictfmt 生成正文和索引。
« 最後編輯時間: 六月 30, 2008, 01:30:26 上午 由 wxy » 已記錄

諸惡莫作
眾善奉行
cbeta
備位版工
四星級
*****
文章: 219


很高興能為您服務


個人網站
« 回覆文章 #4 於: 六月 30, 2008, 04:52:55 下午 »

的確, 我自己好像也沒用過文字介面的字典, 對於有需要的人, 的確很方便.
已記錄

CBETA 中華電子佛典協會
地址: 11246 台北市北投區光明路276號4樓 
電話: +886-2-28932133
網站: http://www.cbeta.org
電子郵件: service@cbeta.org
贊助資訊: http://www.cbeta.org/donation/index.php
wxy
一星級
*
文章: 21


« 回覆文章 #5 於: 八月 27, 2008, 02:21:07 上午 »

剛剛加了一個 web-front CGI 代碼,可以用瀏覽器來
查詞。新版放在:

http://sourceforge.net/projects/budict/

Snapshot 如下:



Web page 做得比較簡單,不過可以通過修改源碼中的
文件來取得更好的效果。
已記錄

諸惡莫作
眾善奉行
小白角
二星級
**
文章: 45



« 回覆文章 #6 於: 九月 15, 2008, 04:51:22 上午 »

"這樣就可以在 Unix-like 的系統中使用佛學字典了。如果有主機提供訪問,就可以成為線上字典。使用 DICT 標準協議的好處是有許多不同平臺的客戶端 dict 程序可直接使用字典服務。有手機端的客戶程序,也有 Web-front 的客戶端可用瀏覽器來訪問的。"

太厉害了!这应该就是说可以在手机上看到佛经的意思了,能够提供在线的字典服务,也就是说,可以提供在线的手机浏览佛经的服务了。


已記錄

传说公元12000前,在大西洋有个大西洲,名叫亚特兰蒂斯,是我们纯净之心和梦想的天堂。
wxy
一星級
*
文章: 21


« 回覆文章 #7 於: 九月 16, 2008, 02:29:12 上午 »

在 sourceforge.net 上可以找到手機端的 dict 開源項目,手頭
沒有實驗環境,無法測試。修改一下 charset 的設置,應該可以
用。曾經試過 KDE 中的 kdict,圖形界面的,可以用,不過有個
折行的小問題,這可以通過將 C5 格式辭典內容適當折行來解決。
已記錄

諸惡莫作
眾善奉行
小白角
二星級
**
文章: 45



« 回覆文章 #8 於: 九月 18, 2008, 05:56:30 下午 »

哦!恩,好的,我已经下载了,谢谢您,我过段时间要自己学习建立KDE下的Apache服务器的,到时候,测试您这个软件,呵呵
正好,我也是KDE,呵呵呵
已記錄

传说公元12000前,在大西洋有个大西洲,名叫亚特兰蒂斯,是我们纯净之心和梦想的天堂。
wxy
一星級
*
文章: 21


« 回覆文章 #9 於: 九月 22, 2008, 01:58:53 上午 »

歡迎諸位大德下載使用。如果安裝有問題,可以發郵件給
末學,或者在論壇中垂詢。

這幾天增添了一段新的代碼,dict2fo.c,可以將 C5 格式
的詞典轉成 EBS 的 .tit 和 .nr,這樣就可以共享詞典文
件了。新版本已經上傳至 sourceforge.net 上。

http://sourceforge.net/projects/budict/

下一步計劃校對詞典,不知”五燈會元”和”閱藏知津”這兩本
書在 cbeta 中是否有已經校對好的電子版?
已記錄

諸惡莫作
眾善奉行
mushroom
一星級
*
文章: 1


« 回覆文章 #10 於: 九月 22, 2008, 09:18:08 下午 »

建議貴站架設線上字典網站,例如: http://dict.cbeta.org

可以在這兒下載 dict.org 的網站前端程式 (PERL 原始碼):
ftp://ftp.dict.org/pub/dict/www/Dict

在 FreeBSD 架設線上字典的步驟,可參閱這篇文章:
DICT@FreeBSD 架設程序
已記錄

香菇!
cbeta
備位版工
四星級
*****
文章: 219


很高興能為您服務


個人網站
« 回覆文章 #11 於: 九月 22, 2008, 11:08:04 下午 »

建議貴站架設線上字典網站,例如: http://dict.cbeta.org

其實我們一直想好好把現有且能公開的佛學辭典做一個整理,
可惜並沒有太多的時間可以讓我們關注這個層面。

然而您的建議我們也會參考看看,若不是要花費許多時間的工作,
或許會進行測試。
已記錄

CBETA 中華電子佛典協會
地址: 11246 台北市北投區光明路276號4樓 
電話: +886-2-28932133
網站: http://www.cbeta.org
電子郵件: service@cbeta.org
贊助資訊: http://www.cbeta.org/donation/index.php
wxy
一星級
*
文章: 21


« 回覆文章 #12 於: 九月 23, 2008, 02:21:23 上午 »

其實我們一直想好好把現有且能公開的佛學辭典做一個整理,
EBS 已經做好的辭典可以成為一個不錯的基礎,末學已經做
好 fo2dict.c 和 dict2fo.c 可以在 C5 格式和 EBS 格式文
件之間做轉換。C5 格式文件是純文本的,可以編輯,dictd
源碼中 test/ 目錄中有說明,上面兩個代碼中也可以讀到。

若不是要花費許多時間的工作,或許會進行測試。
末學查看過貴站 HTTP 頭信息,是 UNIX 主機上的 Apache,
用來構建在線詞典應該不難。如需測試,末學願助其成。

建議貴站架設線上字典網站,例如: http://dict.cbeta.org

可以在這兒下載 dict.org 的網站前端程式 (PERL 原始碼):
ftp://ftp.dict.org/pub/dict/www/Dict
dict.org 上提供的 Web-front 代碼 Dict(PERL 原始碼),
末學曾看過,需要修改少量代碼,主要是改 charset。末
學寫了一個 CGI 的 C 代碼,實現相同功能的,輸出頁面
用 sed 做過濾,加上相應 html 標簽。當時沒用 dict.org
上的源碼主要原因有二:一是不想用 perl,用 C;二是
整個項目用的是公用領域版權(Public Domain),開源版
權中最自由的一種,而 dict.org 用的是 GPL 版權,限制
比較多。
已記錄

諸惡莫作
眾善奉行
cbeta
備位版工
四星級
*****
文章: 219


很高興能為您服務


個人網站
« 回覆文章 #13 於: 十月 03, 2008, 02:12:16 上午 »

我想請教一下, 若我們自己把辭典資料放在 mysql 中, 寫一套 CGI 來查詢 (例如類似星際譯王) , 這樣在使用上有什麼差別嗎?
« 最後編輯時間: 十月 03, 2008, 02:26:41 上午 由 cbeta » 已記錄

CBETA 中華電子佛典協會
地址: 11246 台北市北投區光明路276號4樓 
電話: +886-2-28932133
網站: http://www.cbeta.org
電子郵件: service@cbeta.org
贊助資訊: http://www.cbeta.org/donation/index.php
wxy
一星級
*
文章: 21


« 回覆文章 #14 於: 十月 04, 2008, 02:14:24 上午 »

我想請教一下, 若我們自己把辭典資料放在 mysql 中, 寫一套 CGI 來查詢 (例如類似星際譯王) , 這樣在使用上有什麼差別嗎?
從功能上看都可以實現辭典的查詢;從純技術上看,使用
標準字典協議和相應軟件要好一些。mysql 是通用數據庫
軟件,沒有針對字典應用作優化,在存儲上和查找上都不
是最優。

從可操作性上看,使用標準字典協議利於辭典的編輯和校
對。C5 格式的字典檔是普通文件 (plain text),可以方
便用普通編輯軟件進行編輯和校對。如果使用 mysql ,
可能不太方便進行編輯校對(沒用過,僅從原理上推測)。

從協同開放性上看,使用標準字典協議比較好。DICT 協
議是一個標準的 Internet 協議,類似 HTTP,辭典資料
可以用標準的格式,便於交換和共享。

附:C5 文件格式在 dictd 項目中有解釋,大致如下
程式碼:
1: comments
2: comments
3: _____
4: word1
5:   definition of word1
6:   other lines of definitions.
7: _____
8: word2
9:   definition of word2
...

在第一個''_____''(連續五個下劃線,在一行的開始)出
現之前,可以寫些辭典說明資料,如出處、作者等;之
後每個''_____''出現,表明一個新詞的開始,後一行是
詞,再後續行都是解釋,直到下一個''_____''出現。本
來在新版的 budict 中應該給出說明,在寫了一段轉換
標準字典為原始字典文件之後。因為那段代碼用了一個
狀態轉換自動機,代碼比較晦澀,沒有寫太多說明性文
字,下一版補上。:-)
已記錄

諸惡莫作
眾善奉行
頁: [1] 2 3
  列印  
 
前往:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!