Skip to content

Instantly share code, notes, and snippets.

@yappo
Created March 26, 2011 06:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yappo/888069 to your computer and use it in GitHub Desktop.
Save yappo/888069 to your computer and use it in GitHub Desktop.
* A history of search software in japan
今回紹介するGroongaは日本の検索ライブラリの中で新しいものです。
Groongaを紹介する前に、日本の検索事情について少しお話します。
Today I'm going to talk about a new search library from Japan.
First, I'll tell you something about how search works in Japan.
** use grep
文章を簡単に検索する方法としてgrepがあります。
日本では「fool search(馬鹿検索)」というスラングがあります。
One of the easiest ways to search is grep.
It's sometimes called "idiot search" in Japan.
この方法は大量の文章を検索するのには向いていません。しかも遅いです。
It's not good for searching lots of documentations... and it's slow.
ただし実装が簡単という利点があります。
However, it does have merit; it's easy to implement.
** using index
検索を高速で行うためには、どのwordがどの文章に含まれてるかを知っている必要があります。
You need to know which document contains which word to search things quickly.
It's easy for English.
But it's very difficult for Japanese.
*** word separate
英語は基本的にスペース区切りで単語が別れている。
(単数系や複数形等の処理が必要になる)
日本語は単語の区切りが機械的に判断出来ない。
Because English sentences are basically separated by white space.
(You need to handle declension and conjugation though)
You can't easily tell which character belongs to which word in Japanese.
**** in english
- "today is rainy."
- "today", "is", "rainy"
英語では、スペースで区切れば簡易なtokenizerが作れます。
So you can write a simple tokenizer for English by splitting sentences on white space.
**** in japanese
- "今日は雨です。"
- "今日", "は", "雨", "です", "。"
日本語では、スペースで区切らないので、文字列の意味を知っている必要がある。
漢字、かな文字などの種別毎に区切って良いわけでもない。
Japanese sentences are not separated by white space. So you need to know the meaning and context
of the words in the sentence.
You can't split based on whether a character is Kanji or Kana.
**** in japanese 2
- "私ははずかしいです。。"
- "私", "は", "はずかしい", "です", "。"
- in english "I am ashamed"
日本語では、漢字を使わないでかな文字を使う事が許容されるので、何処で区切ればいいかわからなくなる。
In Japanese you can transliterate with Kana instead of writing in Kanji. It makes tokenizing more difficult.
** KAKASHI (キャプチャ)
そこで日本では古くから"KAKASHI"と呼ばれるソフトウェアが開発された。
therefore, we have the KAKASHI develop in japan.
予め、膨大な日本語の辞書を用意しておき、辞書のデータを元に文章をセパレートする事ができます。
a lot of words dictionary for japan is prepared, that uses for tokenizing sentence.
殆どの場合は解決できる。
it is almost useful.
** 形態素解析 (詞素解析)
KAKASHIでは最長一致で単語を区切るため、しばしば文法を無視したtokenizeを行います。
KAKASHI is often perform wrong tokenize, because a longest-first search algorithm.
形態素解析では、学習した情報を元に最適な文法を解釈してセパレートを行うので、制度が高いです。
Morphological analysis is precision is high, because it use the grammar that learned.
*** MeCab (キャプチャ画像)
日本ではMeCabというソフトウェアが使われています。
MeCab is Morphological analysis software. japanese uses.
gronngaでもMeCabを使えます。
Groonga uses MeCab.
*** MeCab for 中文 (キャプチャ画像)
MeCab は言語に依存しない設計なので、中国語の辞書を作るプロジェクトもあります。
MeCab is language free. we have Project ちゃいニースディクショナリー for MeCab.
** n-gram
しかしながら、立派なアルゴリズムを駆使しても限界があります。
but, MeCab has limit of tokenize.
辞書を使うため、新しい名前がわからない。
MeCab not have new words, because using dictionary.
- ex. けいおん, K-ON
日本人は言葉を作るのが大好きなので追いつかない。
Japanese people like "Create New Words".
- ex. Twitter -> ヒウィッヒヒー
このような欠点を回避するためn-gramを使う事もあります。
It will solve, if N-Gram is used.
*** n-gram example (3-gram)
- けいおん -> "けいお", "いおん"
- K-ON -> "K-O", "-ON"
- Twitter -> "Twi", "wit", "itt", "tte", "ter"
- ヒウィッヒヒー -> "ヒウィ", "ウィッ", "ィッヒ", "ッヒヒ", "ヒヒー"
tri-gram で文を切った場合はこうなります。
このように、辞書を使わないで特定の文字数毎に切り分けるルールを使えば新しい単語にも対応できます。
この場合はindexのサイズが増える傾向があります。
** summary of word separator
- japanese is too hard
- but, we have a solution means
-- Morphological analysis
-- n-gram
日本語をセパレートするのは大変です。
しかし我々は解決する手段を作ってきました。
形態素解析やn-gram
* another search software in japan
groongaの紹介する前に、他の検索ソフトウェアを見てみます。
** Namazu
Namaze in english is catfish(鮎)
Namazuは、日本で古くから開発されている検索ソフトです。
indexer, searcher が付属しています。
組み込み用途に向きません。
Namazu is developed in Japan since early times, with an indexer and searcher.
Not suitable for embedding to another system.
** HyperEstraier
http://fallabs.com/hyperestraier/
2004年頃にリリースされました。
crawler, indexer, searcher が付属しています。
ライブラリだけを組み込み用に利用できます。
Released at 2004, with a crawler, indexer, searcher.
Suitable for embedding to another system.
** Rast
http://projects.netlab.jp/rast/
2005年にリリースされました。
develop by NaCl
これもライブラリだけを組み込み用に利用できます。
自分がPerlバインディングを書きました。
一時期iYappoでも使いましたが、インデックスの管理が面倒なので使うのを辞めました。
Released at 2005, developed by NaCl, suitable for embedding.
I wrote a Perl binding for it.
Used in iYappo, but stopped using it because of the troubles in indexing.
Rast is now deprecated.
** Senna
http://qwik.jp/senna/
2005年にリリースされました。
これもライブラリだけを組み込み用に利用できます。
JPA会長がPerlバインディングを書きました。
Sennaの代表的な使い方は、 MySQL にパッチを当てる事で MySQL の FUll Text Search から Senna 使います。
Released at 2005, suitable for embedding.
A Perl binding was wrote by @lestrrat.
Senna can be integrated into MySQL full text search system.
*** tritonn
http://qwik.jp/tritonn/
tritonn は、 MySQL に Senna のパッチを当てるためのプロジェクトです。
tritonn is a project to manage a patch of MySQL to integrate Senna.
>>
SELECT * FROM tbl WHERE MATCH(col) AGAINST("検索キーワード");
<<
のような形で SQL だけで検索が行えるので人気があります。
インデックスの作成も
>>
INSERT INTO t1 VALUES (3, "東京特許許可局");
<<
という、普通の SQL だけで行えるので、どんな Web アプリケーションからも簡単に使えます。
iYappoでも使っています。しかし、使い方を間違えると不安定になります。
私はSennaの開発者と協力をして安定化を行いました。
but, Senna is depricated.
** 次世代の検索システム
HyperEstraier, Senna, Rast が同時期にリリースされて、日本国内でも次世代の検索システムのブームがきました。
どれも使いやすいライブラリとして提供されているため、hacker達が気軽に検索機能を追加出来るようになったのです。
例えば Plagger では Plagger::Plugin::Search::Estraier, Plagger::Plugin::Search::Rast, Plagger::Plugin::Search::Senna などが作られました。
** moritapo 本のスクリーンショットを添える
最近日本では検索エンジンの良書が発売されています。
senna/groongaの開発に携わった森大二郎が書きました。
コンピュータの素人でもわかりやすい本です。
** Probably, you have question to "what about Lucene and else?".
貴方はおそらく"luceneとか他の話は?"と疑問を持つでしょう。
*** Lucene is not domestic in japan. Therefore, I do not talk a topic.
しかし、それらは日本の話ではないのでおこないません。
* groongaのスクリーンキャプチャ
これから本題のgroongaの話をします。
* groonga
http://groonga.org/
Groonga とは、 Senna の開発者が作った新しい検索ソフトウェアです。
私は開発に参加していません。 sory, i am not a developer.
Senna の欠点を補いつつ、高機能化したものです。
"1から書き直した方が良いよね"、という良くある話です。
彼らの会社のプロダクトで使う機能が実装されています。
** ニコニコ動画と大借家のスクリーンショット
わかりやすく言うとニコニコ動画関連だと私は思います。
** spec
- bundle groonga daemon
-- HTTP, memcached protocol, groonga protocol
- ライブラリだけの利用可能
- geolocation search
- 高速な集計クエリ
- groonga has not english document ;( (i was surprised)
- hack is too hard, because thin documents
ヘッダファイルにドキュメントが点在している。
** install
$ wget http://groonga.org/files/groonga/groonga-1.1.0.tar.gz
$ tar zxvf groonga-1.1.0.tar.gz && cd groonga-1.1.0
$ ./configure --prefix=/usr --localstatedir=/var
$ make && sudo make install
インストールは一般的な方法です。
** 少しだけ動かしてみましょう
(時間が無いとき"sory, skip this demo, because out of time.")
** MySQL Storage
Tritonn の後継として mroonga という MySQL ストレージエンジンが開発されている。
https://github.com/mroonga
ストレージエンジンなので、Tritonnのようなパッチをあてる必要が無くなります。
but, status is alpha.
*** example of mroonga
mysql> CREATE TABLE t1 (
> c1 INT PRIMARY KEY,
> c2 TEXT,
> _score FLOAT,
> FULLTEXT INDEX (c2)
> ) ENGINE = groonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected (0.22 sec)
mysql> insert into t1 values(1, "aa ii uu ee oo", null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values(2, "aa ii ii ii oo", null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values(3, "dummy", null);
Query OK, 1 row affected (0.00 sec)
mysql> select * from t1 where match(c2) against("ii") order by _score desc;
+----+----------------+--------+
| c1 | c2 | _score |
+----+----------------+--------+
| 2 | aa ii ii ii oo | 3 |
| 1 | aa ii uu ee oo | 1 |
+----+----------------+--------+
2 rows in set (0.00 sec)
Tritonn の時と同じクエリで利用できます。
** binding
Groonga は LL のバインディングが充実しています。
There're Groonga bindings in scripting languages
- pyhone
- php
- ruby (rroonga/ラングバ)
http://groonga.rubyforge.org/
gronnga開発者が積極的に開発をしている。
ドキュメントも充実している。
Groognga developpers works for rroonga and its documents,
but, rroonga has not the english document, neigher ;(
** perl binding
私が作っています。
https://github.com/yappo/p5-Groonga
まだまだ実装が少ない。
I'm working for it, but it's not yet completed.
*** キーワード貼付けにも使えるよ
ニコニコ大百科/ニコペディア でもやっている。
Groonga is used to link keywords, for example, in niconico-encycropedia (http://dic.nicovideo.jp/).
*** キーワードはりつけの Perl コード
Perl binding を使ってキーワードリンクを作るコードです。
groongaの実装を使って高速に動作します。
Here is a code to make keyword links with Perl Groonga binding. Very fast.
* Summary of this talk
日本での検索ソフトの概要を話しました
最近のホットトピックはGroongaです
残念ながら英語ドキュメントはありませんが、いつか用意されるでしょう
もし何かの参考になったら、僕も嬉しいです。
Making search engines in Japanese.
One of the hot topics is Groonga.
There's no English document ;( We'll write it in the near future.
I'm happy if it interests you
* 謝謝
Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment