2012/07/23

英辞郎の辞書をコマンドラインから参照してみる

英単語の意味を調べるのに man(1) を使ってしまう人に贈る1行 という記事を拝見して、 自分の FreeBSD マシンで英辞郎の辞書を参照している方法を記事にしてみる。
要は英辞郎の辞書を EPWING 型式に変換して ndt サーバ経由で ndtpc コマンドから検索しているだけで、 検索コマンド自体は 1 行だが多少準備が必要となる。

英辞郎、和英辞郎、略辞郎、音辞郎の辞書を変換する。
英辞郎の辞書を EPWING 型式に変換するのは ports を利用すれば 何の問題もなく可能だ (若干ディスク容量が必要だが、 今となっては問題とならない容量だと思う)。
作業は英辞郎の CD-ROM をマウントした状態で実施すれば良いのだが、 CD-ROM は I/O が遅いのでローカルのファイルシステムに 辞書ファイルをコピーして実行しても良い。
ローカルにファイルをコピーした場合は DICT_PATH で 英辞郎の辞書ファイルのパスを指定すれば良い。
# cd /usr/ports/japanese/eijiro-fpw
# make DICT_PATH=辞書ファイルのパス install clean
# cd /usr/ports/japanese/waeijiro-fpw
# make DICT_PATH=辞書ファイルのパス install clean
# cd /usr/ports/japanese/ryakujiro-fpw
# make DICT_PATH=辞書ファイルのパス install clean
# cd /usr/ports/japanese/otojiro-fpw
# make DICT_PATH=辞書ファイルのパス install clean
            
この変換作業は結構時間が必要である。

ndtpd をインストールする
ndtpd は EB や EPWING などの辞書型式に対応している辞書サーバで、 FreeBSD では ebnetd という ports から導入可能である。
ports から導入すると ndtpd 以外に ebnetd、ebhttpd が インストールされるが今回は ndtpd のみ利用する。
# cd /usr/ports/japanese/ebnetd
# make install clean
# vi /usr/local/etc/ebnetd.conf
# cat << EOF >> /etc/rc.conf
> ndtpd_enable="YES"
> EOF
# chown nobody:nobody /var/run/ebnetd
# /usr/local/etc/rc.d/ebnetd.sh start
            
ebnetd.conf はコメントを参照にすれば簡単に設定できる。 今回はローカルサーバの自分しか利用しないので、 接続ホストや接続数を制限した。
### Port number `ndtpd' binds.
ndtp-port       ndtp

### Owner of the server process.
user            nobody

### Group of the server process.
group           nobody

### How many clients can be connected to the server at the same time.
max-clients     1

### Which hosts can or cannot connect to the server.
hosts           127.0.0.1

### Timeout seconds until the server disconnects an idle connection.
timeout         900

### Path to a working directory.
work-path       /var/run/ebnetd

### How many hit entries the server tries to find at a search.
max-hits        50

### The maximum size of text the server may send as a response to a client.
max-text-size   32768

### Syslog facility
syslog-facility local0

###
### Book entry
###
begin book
    ### Name of the book.
    name        eijiro

    ### Title of the book.
    title       eijiro

    ### Path to a top directory of the book.
    path        /usr/local/share/dict/eijiro-fpw

    ### How many clients can access the book at the same time.
    max-clients 1

    ### Which hosts can or cannot access to the book.
    hosts       127.0.0.1
end

begin book
    #
    # 以下 waeijiro の設定
    #
end

begin book
    # 
    # 以下 ryakujiro の設定
    #
end

begin book
    #
    # 以下 otojiro の設定
    #
end
            

作成された辞書を ebzip で圧縮する
EB ライブラリで使用されている圧縮方式で、 辞書のためのディスク容量を多少なりとも削減するために辞書を圧縮する。
# cd /usr/local/share/dict/eijiro-fpw
# ebzip --level 5
# cd /usr/local/share/dict/waeijiro-fpw
# ebzip --level 5
# cd /usr/local/share/dict/ryakujiro-fpw
# ebzip --level 5
# cd /usr/local/share/dict/otojiro-fpw
# ebzip --level 5
            

ndtpc をインストールする
ndtpc は perl で書かれた NDTP クライアントで、 こちら で公開されているので利用する。
今の所 FreeBSD の ports にはなっていない様なので、 ソースを取得してインストールする。
$ fetch http://www.tanu.org/~sakane/download/ndtpc-20050323a.tgz
$ tar -C /usr/local/src -zxvf ndtpc-20050323a.tgz
$ ./configure
# make install
            

これで以下のコマンドラインで辞書検索が可能になる。

$ ndtpc hello
DICT: 英辞郎
<4c33:560>hello
hello
【発音】helo'u 【変化】《複》hellos
[間投] こんにちは, あのう, やあ
<4c33:5f0>hello
Hello
[人名] エロ
DICT: 和英辞郎
DICT: 略語辞典
DICT: 音辞郎
    
ちなみに jvimkeywordprgndtpc を登録すると 単語の上で 'K' をタイプする事で辞書を検索できるので便利。

トラックバック
https://blog.bsdhack.org/index.cgi/FreeBSD/20120723.trackback
コメント














メッセージ: Ready to post a comment.


Copyright © 2008-2020 Mitzyuki IMAIZUMI. All rights reserved.