<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>5.4. 補正 — groonga v3.0.5ドキュメント</title> <link rel="stylesheet" href="../_static/groonga.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '3.0.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <link rel="shortcut icon" href="../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5ドキュメント" href="../index.html" /> <link rel="up" title="5. サジェスト" href="../suggest.html" /> <link rel="next" title="5.5. 提案" href="suggestion.html" /> <link rel="prev" title="5.3. 補完" href="completion.html" /> </head> <body> <div class="header"> <h1 class="title"> <a id="top-link" href="../index.html"> <span class="project">groonga</span> <span class="separator">-</span> <span class="description">オープンソースのカラムストア機能付き全文検索エンジン</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../en/html/suggest/correction.html"><img src="../_static/us.png" alt="English">English page</a></li> </ul> </div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" accesskey="I">索引</a></li> <li class="right" > <a href="suggestion.html" title="5.5. 提案" accesskey="N">次へ</a> |</li> <li class="right" > <a href="completion.html" title="5.3. 補完" accesskey="P">前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../suggest.html" accesskey="U">5. サジェスト</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="correction"> <h1>5.4. 補正<a class="headerlink" href="#correction" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>このセクションでは以下の補正機能について説明します。:</p> <ul class="simple"> <li><p class="first">どのように動作するか</p> </li> <li><p class="first">使い方</p> </li> <li><p class="first">学習方法</p> </li> </ul> <div class="section" id="how-it-works"> <h2>5.4.1. どのように動作するか<a class="headerlink" href="#how-it-works" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>補正機能は補正した語を計算するために3種類の検索を使います。:</p> <blockquote> <div><ol class="arabic simple"> <li><p class="first">学習したデータを共起検索。</p> </li> <li><p class="first">登録されている語を類似検索。(実行しないこともある)</p> </li> </ol> </div></blockquote> <div class="section" id="cooccurrence-search"> <h3>5.4.1.1. 共起検索<a class="headerlink" href="#cooccurrence-search" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>共起検索はユーザの間違って入力した文字列から登録済みの語を検索します。共起検索ではユーザがどのように検索を実行したかを使います。ユーザがどのように検索したかはクエリログやアクセスログから学習します。</p> <p>例えば、ユーザが以下のように検索を実行したとします。:</p> <table border="1" class="docutils"> <colgroup> <col width="41%" /> <col width="59%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head"><p class="first last">クエリ</p> </th> <th class="head"><p class="first last">時刻</p> </th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><p class="first last">serach (入力ミス!)</p> </td> <td>2011-08-10T22:20:50+09:00</td> </tr> <tr class="row-odd"><td><p class="first last">search (修正!)</p> </td> <td>2011-08-10T22:20:52+09:00</td> </tr> </tbody> </table> <p>上記の検索実行ログから以下のような補正ペアを作ります。</p> <table border="1" class="docutils"> <colgroup> <col width="33%" /> <col width="67%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head"><p class="first last">入力</p> </th> <th class="head"><p class="first last">補正された語</p> </th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>serach</td> <td>search</td> </tr> </tbody> </table> <p>1分以内の連続して実行された検索をユーザが入力を補正したものとみなします。検索を実行した間の入力途中の入力シーケンスは、補正用の学習データとしては利用しません。</p> <p>ユーザが"serach"と入力した場合、共起検索は"saerch"を返します。なぜなら、"serach"が「入力」カラムにあり、対応する「補正される語」カラムの値が"search"だからです。</p> </div> <div class="section" id="similar-search"> <h3>5.4.1.2. 類似検索<a class="headerlink" href="#similar-search" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>類似検索はユーザの入力をトークナイズし、同じトークンを含んだ登録済みの語を検索します。トークナイズにはTokenBigramトークナイザーを使います。これは <a class="reference internal" href="../reference/executables/groonga-suggest-create-dataset.html"><em>groonga-suggest-create-dataset</em></a> が作るサジェストデータセットスキーマではデフォルトトークナイザーとしてTokenBigramトークナイザーを使っているからです。</p> <p>例えば、"search engine"という語が登録されているとします。ユーザが"web search service"や"sound engine"などで検索すると"search engine"が補正候補になります。なぜなら、"search engine"と"web search engine"は"search"という同じトークンを持つからです。また、"search engine"と"sound engine"は"engine"という同じトークンを持っています。</p> <p>"search engine"は"search"トークンと"engine"トークンにトークナイズされます。(groongaのTokenBigramトークナイザーは連続するアルファベットと数字を2文字にトークナイズしません。これは検索ノイズを減らす為です。確実に2文字でトークナイズするためにはTokenBigramSplitSymbolAlphaDigitを使います。)"web search service"は"web"トークンと"search"トークンと"service"トークンにトークナイズされます。"sound engine"は"sound"トークンと"engine"トークンにトークナイズされます。</p> </div> </div> <div class="section" id="how-to-use"> <h2>5.4.2. 使い方<a class="headerlink" href="#how-to-use" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaは補正機能を使うために <a class="reference internal" href="../reference/commands/suggest.html"><em>suggest</em></a> コマンドを用意しています。 <cite>--type correct</cite> オプションを使うと補正機能を利用できます。</p> <p>例えば、"saerch"と入力した時の補正結果取得するコマンドは以下のようになります。:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>suggest --table item_query --column kana --types correction --frequency_threshold 1 --query saerch # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # { # "correct": [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "search", # 1 # ] # ] # } # ] </pre></div> </div> </div> <div class="section" id="how-it-learns"> <h2>5.4.3. 学習方法<a class="headerlink" href="#how-it-learns" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>共起検索は学習データを使います。学習データはクエリログやアクセスログから作ります。学習データを作るためにはユーザが検索を実行したときの検索クエリとタイムスタンプが必要です。</p> <p>例えば、ユーザが"search"で検索したかったとします。しかし、ユーザは正しい"search"というクエリで検索を実行する前に間違って"saerch"で検索してしまいました。このユーザの入力シーケンスは以下のようになります。:</p> <blockquote> <div><ol class="arabic simple"> <li>2011-08-10T13:33:23+09:00: s</li> <li>2011-08-10T13:33:23+09:00: sa</li> <li>2011-08-10T13:33:24+09:00: sae</li> <li>2011-08-10T13:33:24+09:00: saer</li> <li>2011-08-10T13:33:24+09:00: saerc</li> <li><p class="first">2011-08-10T13:33:25+09:00: saerch (検索実行!)</p> </li> <li><p class="first">2011-08-10T13:33:29+09:00: serch (修正中…)</p> </li> <li><p class="first">2011-08-10T13:33:30+09:00: search (検索実行!)</p> </li> </ol> </div></blockquote> <p>以下のコマンドでこの入力シーケンスから学習できます。:</p> <div class="highlight-none"><div class="highlight"><pre>load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' [ {"sequence": "1", "time": 1312950803.86057, "item": "s"}, {"sequence": "1", "time": 1312950803.96857, "item": "sa"}, {"sequence": "1", "time": 1312950804.26057, "item": "sae"}, {"sequence": "1", "time": 1312950804.56057, "item": "saer"}, {"sequence": "1", "time": 1312950804.76057, "item": "saerc"}, {"sequence": "1", "time": 1312950805.76057, "item": "saerch", "type": "submit"}, {"sequence": "1", "time": 1312950809.76057, "item": "serch"}, {"sequence": "1", "time": 1312950810.86057, "item": "search", "type": "submit"} ] </pre></div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">5.4. 補正</a><ul> <li><a class="reference internal" href="#how-it-works">5.4.1. どのように動作するか</a><ul> <li><a class="reference internal" href="#cooccurrence-search">5.4.1.1. 共起検索</a></li> <li><a class="reference internal" href="#similar-search">5.4.1.2. 類似検索</a></li> </ul> </li> <li><a class="reference internal" href="#how-to-use">5.4.2. 使い方</a></li> <li><a class="reference internal" href="#how-it-learns">5.4.3. 学習方法</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="completion.html" title="前の章へ">5.3. 補完</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="suggestion.html" title="次の章へ">5.5. 提案</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/suggest/correction.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" >索引</a></li> <li class="right" > <a href="suggestion.html" title="5.5. 提案" >次へ</a> |</li> <li class="right" > <a href="completion.html" title="5.3. 補完" >前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../suggest.html" >5. サジェスト</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>