| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
Summary |
| 4 |
======= |
| 5 |
|
| 6 |
Groonga has tokenizer module that tokenizes text. It is used when |
| 7 |
the following cases: |
| 8 |
|
| 9 |
* Indexing text |
| 10 |
|
| 11 |
.. figure:: /images/reference/tokenizers/used-when-indexing.png |
| 12 |
:align: center |
| 13 |
:width: 80% |
| 14 |
|
| 15 |
Tokenizer is used when indexing text. |
| 16 |
|
| 17 |
* Searching by query |
| 18 |
|
| 19 |
.. figure:: /images/reference/tokenizers/used-when-searching.png |
| 20 |
:align: center |
| 21 |
:width: 80% |
| 22 |
|
| 23 |
Tokenizer is used when searching by query. |
| 24 |
|
| 25 |
Tokenizer is an important module for full-text search. You can change |
| 26 |
trade-off between `precision and recall |
| 27 |
<http://en.wikipedia.org/wiki/Precision_and_recall>`_ by changing |
| 28 |
tokenizer. |
| 29 |
|
| 30 |
Normally, :ref:`token-bigram` is a suitable tokenizer. If you don't |
| 31 |
know much about tokenizer, it's recommended that you choose |
| 32 |
:ref:`token-bigram`. |
| 33 |
|
| 34 |
You can try a tokenizer by :doc:`/reference/commands/tokenize` and |
| 35 |
:doc:`/reference/commands/table_tokenize`. Here is an example to |
| 36 |
try :ref:`token-bigram` tokenizer by |
| 37 |
:doc:`/reference/commands/tokenize`: |
| 38 |
|
| 39 |
.. groonga-command |
| 40 |
.. include:: ../../example/reference/tokenizers/tokenize-example.log |
| 41 |
.. tokenize TokenBigram "Hello World" |
| 42 |
|
| 43 |
"tokenize" is the process that extracts zero or more tokens from a |
| 44 |
text. There are some "tokenize" methods. |
| 45 |
|
| 46 |
For example, ``Hello World`` is tokenized to the following tokens by |
| 47 |
bigram tokenize method: |
| 48 |
|
| 49 |
* ``He`` |
| 50 |
* ``el`` |
| 51 |
* ``ll`` |
| 52 |
* ``lo`` |
| 53 |
* ``o_`` (``_`` means a white-space) |
| 54 |
* ``_W`` (``_`` means a white-space) |
| 55 |
* ``Wo`` |
| 56 |
* ``or`` |
| 57 |
* ``rl`` |
| 58 |
* ``ld`` |
| 59 |
|
| 60 |
In the above example, 10 tokens are extracted from one text ``Hello |
| 61 |
World``. |
| 62 |
|
| 63 |
For example, ``Hello World`` is tokenized to the following tokens by |
| 64 |
white-space-separate tokenize method: |
| 65 |
|
| 66 |
* ``Hello`` |
| 67 |
* ``World`` |
| 68 |
|
| 69 |
In the above example, 2 tokens are extracted from one text ``Hello |
| 70 |
World``. |
| 71 |
|
| 72 |
Token is used as search key. You can find indexed documents only by |
| 73 |
tokens that are extracted by used tokenize method. For example, you |
| 74 |
can find ``Hello World`` by ``ll`` with bigram tokenize method but you |
| 75 |
can't find ``Hello World`` by ``ll`` with white-space-separate tokenize |
| 76 |
method. Because white-space-separate tokenize method doesn't extract |
| 77 |
``ll`` token. It just extracts ``Hello`` and ``World`` tokens. |
| 78 |
|
| 79 |
In general, tokenize method that generates small tokens increases |
| 80 |
recall but decreases precision. Tokenize method that generates large |
| 81 |
tokens increases precision but decreases recall. |
| 82 |
|
| 83 |
For example, we can find ``Hello World`` and ``A or B`` by ``or`` with |
| 84 |
bigram tokenize method. ``Hello World`` is a noise for people who |
| 85 |
wants to search "logical and". It means that precision is |
| 86 |
decreased. But recall is increased. |
| 87 |
|
| 88 |
We can find only ``A or B`` by ``or`` with white-space-separate |
| 89 |
tokenize method. Because ``World`` is tokenized to one token ``World`` |
| 90 |
with white-space-separate tokenize method. It means that precision is |
| 91 |
increased for people who wants to search "logical and". But recall is |
| 92 |
decreased because ``Hello World`` that contains ``or`` isn't found. |