bogofilter-nihongo.rb のインストール
(Mac OSX & Cygwin on Windows)

bogofilter-nihongo.rb で、メールの事前処理

をして、bogofilter に渡しています。


1. まえがき
1.1. 概要
1.2. 機能
2. インストール
2.1. References
2.2. make & install
3. 設定
4. 使い方
4.1. コマンドラインからの呼び出し
4.2. procmail からの呼び出し
4.3. Wanderlust からの運用
4.4. bogofilter に対する拡張
4.5. help

関連するページはこちら、

MacOSX & Cygwin on Windows のソフトの事

メール関係全体はこちら

Emacs 関係はこちら


1. まえがき

1.1. 概要

bogofilter-nihongo.rb で、メールの事前処理

をして、bogofilter に渡しています。

bogofilter-nihongo.rb は、東京工科大の冨永先生作の、prepare.rb を私が改造したものです。

内部で、bogofilter を呼んでおり、

ので、見かけ上、bogofilter を置き換え可能です。

以前紹介していた、PrepareMecab に対し、

したものになっています。

ruby はちゃんと勉強したわけではなくて、見よう見真似で書いてますので、可笑しい所はご容赦。取り敢えず、動作はしているようです。


1.2. 機能

その中で、rubymail、nkf-ruby、mecab-ruby を呼び出していますが、各プログラムは、

rubymail
nkf-ruby
mecab-ruby
bogofilter-nihongo.rb 自身では

な事をしています。


2. インストール

2.1. References

bogofilter-nihongo.rb は、東京工科大の冨永先生作の、prepare.rb を私が改造したものです。

Homepage
BogofilterNihongo
Source
bogofilter-nihongo.rb
Dependency
下記パッケージが必要です

2.2. make & install

download してきて、適当な所に置きます。私は、~/bin に置いてます。で

$ mv bogofilter-nihongo.rb.txt bogofilter-nihongo.rb
$ chmod 755 bogofilter-nihongo.rb

1行目の、

#!/usr/bin/ruby

は、環境に合わせて、変更してください。標準の、cygwin & MacOSX では、此の侭で大丈夫な筈。


3. 設定

これまで、kakasi でわかち書きをした DB をお使いの方は、DB を再構築してください。


4. 使い方

4.1. コマンドラインからの呼び出し

bogofilter-nihongo.rb に対し、

であれば、直接呼び出せます。

~/mail/spam/1 と言うメールファイルを、DB に spam として登録したい場合、

bash$ ~/bin/bogofilter-nihongo.rb -s --unicode=no -k 10 <  ~/mail/spam/1

~/mail/good/1 と言うメールファイルを、DB に no spam として登録したい場合、

bash$ ~/bin/bogofilter-nihongo.rb -n --unicode=no -k 10 <  ~/mail/good/1

~/mail/inbox/1 と言うメールファイルが、spam か否か見たい場合

bash$ ~/bin/bogofilter-nihongo.rb --unicode=no --spam-cutoff 0.9 -k 10 -v <  ~/mail/inbox/1

とする。

4.2. procmail からの呼び出し

Mail::ProcMailRc を参照ください。


4.3. Wanderlust からの運用

UNIX 系のOS(OSX 含む)の場合は、そのまま、bogofilter に置き換え可能。.wl に次の様に書きます。

(setq elmo-spam-scheme 'bogofilter)
(setq elmo-spam-bogofilter-program "bogofilter-nihongo.rb") ;; default: "bogofilter"
(setq elmo-spam-bogofilter-args '("--unicode=no" "-k" "10"))

NTEmacs、Meadow の場合、直接ruby script を叩けないので、

(setq elmo-spam-scheme 'bogofilter)
(setq elmo-spam-bogofilter-program "ruby.exe") ;; default: "bogofilter"
(setq elmo-spam-bogofilter-args '("bogofilter-nihongo.rb" "--unicode=no" "-k" "10"))

4.4. bogofilter に対する拡張

専ら、デバッグ用として、二つのオプションを追加しています。

option —filter
filter として動作。EUC に変換され、分かち書きされたメールを、標準出力に、出力する。分かち書き、動作確認用。 他の spam filter への入力用としても使えます。
option —debug
bogofilter のプロセスID、標準/エラー出力、終了ステータスを表示 専ら、open4 の作動確認用として使ってました。
bash$ ~/bin/bogofilter-nihongo.rb --debug --unicode=no -v -k 10 < ~/mail/inbox/1
pid        : 2872
stdout     : X-Bogosity: Unsure, tests=bogofilter, spamicity=0.501969, version=1.1.1
stderr     :
status     : #<Process::Status: pid=2872,exited(2)>
exitstatus : 2
X-Bogosity: Unsure, tests=bogofilter, spamicity=0.501969, version=1.1.1


4.5. help

help は、bogofilter の help に被っています。

bash$ bogofilter-nihongo.rb --help
bogofilter-nihongo version 0.1

Usage: ruby bogofilter-nihongo.rb [options] < message

bogofilter-nihongo original options:
  --filter                  - work like as encoder and wakati-gaki filter
  --help                    - show this message
  --debug                   - show bogofilter process status

other options will be passed through bogofilter

bogofilter version 1.1.1

Usage:  bogofilter [options] < message

help options:
  -h, --help                - print this help message.
  -V, --version             - print version information and exit.
  -Q, --query               - query (display) base bogofilter configuration.
  -QQ                       - display extended configuration info.
classification options:
  -p, --passthrough         - passthrough.
  -e, --ham-true            - in -p mode, exit with code 0 when the mail is not spam.
  -u, --update-as-scored    - score message as spam or non-spam and register accordingly.
  -M, --classify-mbox       - set mailbox mode.  Classify multiple messages in an mbox formatted file.
  -b, --classify-stdin      - set streaming bulk mode. Process multiple messages (files or directories) read from STDIN.
  -B, --classify-files=list - set bulk mode. Process multiple messages (files or directories) named on the command line.
  -R, --dataframe           - print an R data frame.
registration options:
  -s, --register-spam       - register message(s) as spam.
  -n, --register-ham        - register message(s) as non-spam.
  -S, --unregister-spam     - unregister message(s) from spam list.
  -N, --unregister-nonspam  - unregister message(s) from non-spam list.
general options:
  -c, --config-file=file    - read specified config file.
  -C, --no-config-file      - don't read standard config files.
  -d, --bogofilter-dir=path - specify directory for wordlists.
  -H, --no-header-tags      - disables header line tagging.
  -k, --db-cachesize=size   - set Berkeley DB cache size (MB).
  -l, --use-syslog          - write messages to syslog.
  -L, --syslog-tag=tag      - specify the tag value for log messages.
  -I, --input-file=file     - read message from 'file' instead of stdin.
  -O, --output-file=file    - save message to 'file' in passthrough mode.
parameter options:
  -mv1[,v2[,v3]]            - set user defined min_dev, robs, and robx values.
      --min-dev=v1, --robs=v2, --robx=v3
  -ov1[,v2]                 - set user defined spam and non-spam cutoff values.
      --spam-cutoff=v1, --ham-cutoff=v2
info options:
  -t, --terse               - set terse output mode.
  -T, --fixed-terse-format  - set invariant terse output mode.
  -q, --quiet               - suppress token statistics.
  -U, --report-unsure       - print statistics if spamicity is 'unsure'.
  -v, --verbosity           - set debug verbosity level.
  -y, --timestamp-date      - set date for token timestamps.
  -D, --debug-to-stdout     - direct debug output to stdout.
  -x, --debug-flags=list    - set flags to display debug information.
config file options:
  --option=value - can be used to set the value of a config file option.
                   see bogofilter.cf.example for more info.
  --block-on-subnets                return class addr tokens
  --bogofilter-dir                  directory for wordlists
  --charset-default                 default character set
  --db-cachesize                    Berkeley db cache in Mb
  --db-log-autoremove               enable/disable autoremoval of log files
  --db-transaction                  enable/disable transactions
  --ham-cutoff                      nonspam if score below this
  --header-format                   spam header format
  --log-header-format               header written to log
  --log-update-format               logged on update
  --min-dev                         ignore if score near
  --min-token-len                   min len for single tokens
  --max-token-len                   max len for single tokens
  --max-multi-token-len             max len for multi-word tokens
  --multi-token-count               number of tokens per multi-word token
  --ns-esf                          effective size factor for ham
  --replace-nonascii-characters     substitute '?' if bit 8 is 1
  --robs                            Robinson's s parameter
  --robx                            Robinson's x parameter
  --sp-esf                          effective size factor for spam
  --spam-cutoff                     spam if score above this
  --spam-header-name                passthrough adds/replaces
  --spam-subject-tag                passthrough prepends Subject
  --spamicity-formats               spamicity output format
  --spamicity-tags                  spamicity tag format
  --stats-in-header                 use header not body
  --terse                           report in short form
  --terse-format                    short form
  --thresh-update                   no update if near 0 or 1
  --timestamp                       enable/disable token timestamps
  --unicode                         enable/disable unicode based wordlist
  --unsure-subject-tag              like spam-subject-tag
  --user-config-file                configuration file
  --wordlist                        specify wordlist parameters

bogofilter is a tool for classifying email as spam or non-spam.

For updates and additional information, see
URL: http://bogofilter.sourceforge.net