ã¨ã ã¹ãªã¼ã¨ã³ã¸ãã¢ãªã³ã°ã°ã«ã¼ã AIã»æ©æ¢°å¦ç¿ãã¼ã ã§ã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ããã¦ããä¸æ(@po3rin) ã§ããæè¿ãAIã»æ©æ¢°å¦ç¿ãã¼ã é ä¸ã®æ¤ç´¢åºç¤ãã¼ã ã§Elasticsearchã®AnalyzerãKuromojiããSudachiã«ç§»è¡ãã¾ãããä»åã¯Sudachi移è¡ã®èæ¯ã¨ãSudachiã®æ¦è¦ãå®éã«ç§»è¡ããã«ããã£ã¦ã®ããã»ã¹ã注æäºé ãã話ããã¾ãã
- 対象èªè
- ãªãSudahchiã«ç§»è¡ããã®ã
- Sudachiã¸ã®ç§»è¡æ¦ç¥ã¨å®è·µ
- ä»ä½¿ã£ã¦ããKuromojiã¦ã¼ã¶ã¼è¾æ¸ãSudachiã¦ã¼ã¶ã¼è¾æ¸ã«ç§»è¡ãã
- ä»ä½¿ã£ã¦ããã·ããã è¾æ¸ããSudachiæ£è¦åæ©è½ã§ã¾ããªãããã®ãåé¤ãã
- 平仮å/ã«ã¿ã«ãã®æ£è¦åè¾æ¸ãä½ã
- 移è¡æã®Sudachiåãæ¿ãæ¦ç¥
- 移è¡å¾ã®å½±é¿ã®äºå確èª
- Sudachi移è¡æã®ããããã¤ã³ã
- Sudachi移è¡ã®çµæ
- ãã¾ã
- ã¾ã¨ã
対象èªè
- Elasticsearchãå°ãã§ã使ã£ããã¨ãããæ¹
- Elasticsearchã¨Sudachiã®é£æºã«èå³ããã
- 表è¨ããçã®èª²é¡ã解決ãããæ¤ç´¢ã¨ã³ã¸ãã¢
ãªãSudahchiã«ç§»è¡ããã®ã
æ¤ç´¢åºç¤ãã¼ã ãæ±ãã¦ããæ¤ç´¢ã®èª²é¡
ã¨ã ã¹ãªã¼æ¤ç´¢åºç¤ãã¼ã ã§ã¯å»çãã¡ã¤ã³ç¹åã®æ¤ç´¢ã¨ã³ã¸ã³ãä½æãã¦ãã¾ããå¼ç¤¾ã®æ¤ç´¢ã®èª²é¡ã¨ãã¦ã表è¨æºããã¨ãè¤åèªã®åå²ããæãããã¾ãã
å»çãã¡ã¤ã³ã¯ç¹ã«è¡¨è¨æºãã®å¤§ããªåéãªã®ã§ããããã®è§£æ±ºã¯æ¤ç´¢ã¨ã³ã¸ã³ã®ç²¾åº¦åä¸ã«å¯ä¸ãã¾ããä¾ãã°ãèãã/èã¬ã³/èçããªã©ã®å¹³ä»®å/ã«ã¿ã«ã/æ¼¢åã®æºããããã¾ããKuromojiã§ã¯ã·ããã ã§å ¨ã¦ã®å°éç¨èªã®è¡¨è¨æºããå®ç¾©ãã¦å¸åããã¨ãã対çãããã¾ãã
// ã·ããã è¾æ¸ã§èçã®è¡¨è¨æºãã«å¯¾å¿ããä¾ èãã,èã¬ã³,èç
ããããå»çç¨èªã®è¡¨è¨æºããã¿ã¼ã³ã¯é常ã«å¤ããå ¨ã¦ãã·ããã è¾æ¸ã§ã¾ããªãã®ã¯å°é£ã§ããã¾ãè¾æ¸ã®éç¨ã³ã¹ããä¸ããã¾ãã
ã¾ããå»çç¨èªã¯è¤åèª(2ã¤ä»¥ä¸ã®åèªãé£çµãã¦ãå¥ã®1ã¤ã®èªãå½¢é ã£ããã®)ãé常ã«å¤ãããå´ä½æ§çå¿çå åèã¹ãã³ãçç½®å¾ãã®ããã«ãã©ãã¾ã§ãæ§æè¦ç´ åä½ã¨ãããã®å¤å®ã«ææ§æ§ãçãããã®ãå¤ãããããæ¤ç´¢ã®å質ãä¸ããåå ã«ãªãã¾ãã
ç¹ã«å»çç¨èªã§ã¯ãããæ§ãã¨ãã表ç¾ãé »åºããç åã®åé¡ã示ãããã«å¤ãç¨ãããã¦ãã¾ããä¾ãã°ãå 天æ§å å足ãã¯å 天æ§ã¨ããæå³çãªåé¡ãå«ãã ç åã§ããããããå»çç¨èªã®è¤åèªãå¤ããã¦ããåå ã®1ã¤ã§ããä»ã«ããè¡æ§ããå¤å·æ§ããªã©ããããªãããæ§ããå«ãè¤åèªãåå¨ãã¾ããå»çç¨èªã®è¤åèªã®æ§æè¦ç´ ã決å®ããããã®ç 究ãåå¨ããå»çç¨èªã®æ§æèªã®æå³çã«ãã´ãªã¼ãåé¡ãã試ã¿ãããã¾ãã
Kuromojiã®ã¦ã¼ã¶ã¼è¾æ¸ã«ãããã®å»çè¤åèªãå«ãã¨å¤§ããªåé¡ãçºçãã¾ããKuromojiã¯ã¦ã¼ã¶ã¼è¾æ¸ã«é£æ¥ã³ã¹ããå«ãäºãã§ãããã¦ã¼ã¶ã¼è¾æ¸ã«å®ç¾©ãã¦ããåèªã®åä½ã§å½¢æ ç´ è§£æããã¦ãã¾ãã¾ããä¸è¨ã¯Kuromojiã¦ã¼ã¶ã¼è¾æ¸ã使ã£ã¦ãå 天æ§å å足ããå®ç¾©ããä¾ã§ãã
// Kuromojiã¦ã¼ã¶ã¼è¾æ¸ã§å»çè¤åèªãå®ç¾©ããä¾ å 天æ§å å足,å 天æ§å å足,ã»ã³ãã³ã»ã¤ãã¤ãã³ã½ã¯,åè©
ãã®ããã«å®ç¾©ããå ´åãããã¥ã¡ã³ãã«ã¦ã¼ã¶ã¼è¾æ¸ã«å®ç¾©ããã¦ãããå 天æ§å å足ããåºã¦ãã¦ããå 天æ§å å足ãã¨ãããã¼ã¯ã³ã§ã¤ã³ããã¯ã¹ãããã®ã§ãã¯ã¨ãªãå å足ãã§ãã®ããã¥ã¡ã³ãã«ããããã¾ãããKuromojiã«é¢ãã¦ã¯n-bestã§åã£ã¦ããæ¹æ³ãæãããã¾ãããæé©ãªè¤åèªã®åå²ã«ãªã£ã¦ããªãäºãå¤ããããããªæ¤ç´¢çµæã«ãªã£ã¦ãã¾ãäºãããã¾ãã
ã¾ã¨ããã¨æã ã®WANTã¯ä¸è¨ã«éç´ããã¾ãã
- å»çç¨èªã®è¡¨è¨æºãã«å¯¾å¿ããã
- å»çè¤åèªã®è¾æ¸ãæ£ããåå²ããã
ä½è«ã§ãããããã§ç´¹ä»ãã以å¤ã«ãå»çèªç¶è¨èªå¦çã®åéã§ã¯å»çãã¡ã¤ã³ç¹æã®èª²é¡ãããã¾ãããããã«èå³ã®ããæ¹ã¯ä¸è¨ã®æ¸ç±ããªã¹ã¹ã¡ã§ãã
Sudachiã¨ã¯
ããã¾ã§ã«ç´¹ä»ããåé¡ã解決ããããã«ã¨ã ã¹ãªã¼æ¤ç´¢åºç¤ãã¼ã ã§ã¯kurmojiããSudachiã«ç§»è¡ãã¾ãããSudachiã¯æ¥æ¬èªå½¢æ ç´ è§£æå¨ã§ãããéçºã¯ã¯ã¼ã¯ã¹å¾³å³¶äººå·¥ç¥è½NLPç 究æã主ã«è¡ãªã£ã¦ãã¾ãã
Sudachiã§ã¯åå²ã¢ã¼ã(A/B/C)ãé¸ã¹ãå©ç¨ã·ã¼ã³ã«å¿ãã¦åå²æ¹æ³ãå¤ããäºãã§ãã¾ãã
$ echo 'å¿æ¿ç´°å' | sudachipy -m C -s full å¿æ¿ç´°å åè©,åºæåè©,ä¸è¬,*,*,* å¿æ¿ç´°å echo 'å¿æ¿ç´°å' | sudachipy -m B -s full å¿æ¿ åè©,æ®éåè©,ä¸è¬,*,*,* å¿æ¿ ç´°å åè©,æ®éåè©,ä¸è¬,*,*,* ç´°å
ã¾ããSudachiã§ã¯å®æçã«è¾æ¸ã«æ°èªã»åºæ表ç¾ã追å ããã¦ãããææ°ã®ã¢ãããã¼ãã§ã¯ãã¾ãé²/ã¾ã延é²æ¢çéç¹æªç½®ããªã©ã追å ããããã¨ãããªãæ°ããåèªã追å ãã¦ããã¾ãã
ããã¦Sudachiã§ã¯æè»ãªã¦ã¼ã¶ã¼è¾æ¸å®ç¾©ãæ£è¦åæ©è½ãçµã¿è¾¼ã¾ãã¦ãããæã ãæã¤èª²é¡ã¨é常ã«ç¸æ§ãè¯ãã§ãã
ä¾ãã°ãèãããããèã¬ã³ãã¯ãèçãã«ããã©ã«ãã§æ£è¦åã§ãã¾ãã
$ echo 'èãã' | sudachipy -m C -s full èãã åè©,æ®éåè©,ä¸è¬,*,*,* èç $ echo 'èã¬ã³' | sudachipy -m C -s full èã¬ã³ åè©,æ®éåè©,ä¸è¬,*,*,* èç
Sudachiã®ã¦ã¼ã¶ã¼è¾æ¸ã§ã¯é£æ¥ã³ã¹ããåå²ã¢ã¼ããã¨ã®åå²æ¹æ³ãå®ç¾©ã§ãã表ç¾åè±ãã«ã¦ã¼ã¶ã¼è¾æ¸ãæ±ãã¾ããä¾ãã°ãçºä½æ§å¿æ¿ç´°åãã®ãããªè¤åèªã¯ä¸è¨ã®ããã«ã¦ã¼ã¶ã¼è¾æ¸ãä½æãã¾ãã
// Sudachiã¦ã¼ã¶ã¼è¾æ¸ã§ãçºä½æ§å¿æ¿ç´°åããå®ç¾©ããä¾ çºä½æ§å¿æ¿ç´°å,4786,4786,5000,çºä½æ§å¿æ¿ç´°å,åè©,æ®éåè©,ä¸è¬,*,*,*,,çºä½æ§å¿æ¿ç´°å,*,C,584006/434835/428494/619020,2756385/428494/619020,*
ãã¨ã§ã¦ã¼ã¶ã¼è¾æ¸ãã©ã¼ãããã«ã¤ãã¦ã¯èª¬æãã¾ããããã®ããã«å®ç¾©ãã¦ãããã¨ã§åå²ã¢ã¼ãBã§ã¯ãçºä½æ§/å¿æ¿/ç´°åããã¢ã¼ãCã§ã¯ãçºä½æ§å¿æ¿ç´°åãã¨å½¢æ ç´ è§£æã§ãã¾ããããã¯å®å ¨ä¸è´ã®å ´åã¯ã¹ã³ã¢ãé«ããã¦ãé¨åä¸è´ã§ããããããããã¨ããç¨éã§ã¯é常ã«æç¨ã§ãã
ãã®ããã«Sudachiãå©ç¨ããã¨å»çç¨èªç¹æã®è¡¨è¨æºããè¤åèªåé¡ã«å¯¾ãã¦ããç¨åº¦å¯¾å¿ã§ããããã«ãªãã¾ãã
Sudachiã¸ã®ç§»è¡æ¦ç¥ã¨å®è·µ
Elasticsearchãã¼ããã使ãå§ããã¨ãã¯ãSudachiãã©ã°ã¤ã³ã®ããã¥ã¡ã³ãã解説è¨äºãè¦ãã°ããã«ä½¿ãå§ãããã¨ãã§ãã¾ãã
ãããããã§ã«Elasticsearchãéç¨ãã¦ããå ´åã¯ãæ¢åã®è¾æ¸ãã·ããã è¾æ¸ããã§ã«åå¨ãããããã®æ¢åãªã½ã¼ã¹ã移è¡ããã®ã¯å°ãæåã®ãããä½æ¥ã§ãã
ã¾ããAnalyzerã®å¤æ´ã¯æ¤ç´¢çµæã«å¤§ããªå½±é¿ãããã®ã§äºåã«æ¤ç´¢çµæã確èªã§ããããã«ãã¦ããå¿ è¦ãããã¾ãã
æã ã®ç§»è¡ã§ã¯ä»¥ä¸ã®ç§»è¡ããã»ã¹ãè¨ç»ãã¾ããã
- ä»ä½¿ã£ã¦ããKuromojiã¦ã¼ã¶ã¼è¾æ¸ãSudachiã¦ã¼ã¶ã¼è¾æ¸ã«ç§»è¡ãã
- ä»ä½¿ã£ã¦ããã·ããã è¾æ¸ããSudachiæ£è¦åæ©è½ã§è³ãããã®ãåé¤ãã
- 平仮å/ã«ã¿ã«ãã®æ£è¦åè¾æ¸ãä½ã
- 移è¡æã®Sudachiåãæ¿ãæ¦ç¥
- 移è¡å¾ã®å½±é¿ã®äºå確èª
ããããã¯å®éã«ã¨ã ã¹ãªã¼æ¤ç´¢åºç¤ãã¼ã ãã©ã®ããã«Sudachiã«ç§»è¡ããããã話ããã¾ãã
ä»ä½¿ã£ã¦ããKuromojiã¦ã¼ã¶ã¼è¾æ¸ãSudachiã¦ã¼ã¶ã¼è¾æ¸ã«ç§»è¡ãã
SudachiããKuromojiã«ç§»è¡ããéã«ãã§ã«éç¨ãã¦ããã¦ã¼ã¶ã¼è¾æ¸ããããªããããSudachiè¾æ¸ã«å¤æãã¦ãããå¿ è¦ãããã¾ããã¦ã¼ã¶ã¼è¾æ¸ãä½ã£ãå ã«ãªãã³ã¼ãã¹ããã£ãã¨ãã¦ãSudachiç¨ã«å¤æã¹ã¯ãªãããæ°ããæ¸ãã®ã¯ã³ã¹ãããããã¾ããããã§æ¤ç´¢åºç¤ãã¼ã ã§éçºããkuro2sudachiã¨ããè¾æ¸å¤æãã¼ã«ã使ã£ã¦è¾æ¸ã®ç§»è¡ãã¾ããããã®ãã¼ã«ã¯OSSã¨ãã¦å ¬éãã¦ãã¾ãã
Kuromojiã¦ã¼ã¶ã¼è¾æ¸ã§ä»ä¸ãã¦ããåè©ãã¨ã«é£æ¥ã³ã¹ããåå²æ¹æ³ãæå®ã§ããããªãæè»ã«è¾æ¸ãå¤æã§ãã¾ãã
ä¾ãã°è¨å®ãã¡ã¤ã«ã§ä¸è¨ãå®ç¾©ãã¾ãã
{ "åè©": { "sudachi_pos": "åè©,æ®éåè©,ä¸è¬,*,*,*", "left_id": 4786, "right_id": 4786, "cost": 5000, "split_mode": "C", "unit_div_mode": [ "A", "B" ] } }
åè©
ã¨ããåè©ãã¤ããåèªãSudachiã®åè©ä½ç³»ã«åããã¦åè©,æ®éåè©,ä¸è¬,*,*,*
ã«å¤æãã¾ããåè©ãã¨ã«é£æ¥ã³ã¹ããå©ç¨ããåå²ã¢ã¼ããå®ç¾©ã§ãã¾ããkuro2sudachiã®å
é¨ã§ã¯SudachiPyãã¢ã¸ã¥ã¼ã«ã¨ãã¦å©ç¨ããå½¢æ
ç´ è§£æããçµæãåå²æ
å ±ã¨ãã¦ç»é²ãã¦ãã¾ãã
ããã§kuro2sudachiãå®è¡ããã¨ãä¸è¨ã®ããã«åè©å¤æãé£æ¥ã³ã¹ãä»ä¸ãåå²ã¢ã¼ãå®ç¾©æ¸ã¿ã®Sudachiè¾æ¸ãæã«å ¥ãã¾ãã
$ cat kuromoji_dict.txt èåããã±ã質,èåããã±ã質,èåããã±ã質,åè© çºä½æ§å¿æ¿ç´°å,çºä½æ§å¿æ¿ç´°å,çºä½æ§å¿æ¿ç´°å,åè© $ kuro2sudachi kuromoji_dict.txt -o sudachi_user_dict.txt -c convert_config.json --ignore $ cat sudachi_user_dict.txt èåããã±ã質,4786,4786,5000,èåããã±ã質,åè©,æ®éåè©,ä¸è¬,*,*,*,,èåããã±ã質,*,C,*,660881/810248,* çºä½æ§å¿æ¿ç´°å,4786,4786,5000,çºä½æ§å¿æ¿ç´°å,åè©,æ®éåè©,ä¸è¬,*,*,*,,çºä½æ§å¿æ¿ç´°å,*,C,584006/434835/428494/619020,2756385/428494/619020,*
Sudachiã®è¾æ¸ãã©ã¼ãããã«é¢ãã¦ã¯å ¬å¼ã®ããã¥ã¡ã³ããã覧ãã ããããã¨ã§è©³ãã説æãã¾ããkuro2sudachiã§ã¯åå²æ å ±ãæ§æèªã®IDã«å¤æãã¦ã¦ã¼ã¶ã¼è¾æ¸ã«è¨è¼ãã¾ããããã¯ã¦ã¼ã¶ã¼è¾æ¸ã®ãã«ãé度ããããããã§ãã
ä»ä½¿ã£ã¦ããã·ããã è¾æ¸ããSudachiæ£è¦åæ©è½ã§ã¾ããªãããã®ãåé¤ãã
Sudachiã®æ£è¦åã§äºè¶³ããåå¯ããã·ããã ã«å®ç¾©ããå¿ è¦ã¯ãªãã®ã§ãããããåé¤ãã¦è»½ãã·ããã è¾æ¸ã«ãã¦ããããã¨ããã§ãã
ä¾ãã°å¼ç¤¾ã®ã·ããã è¾æ¸ã«ã¯ãããã±ã質,èç½è³ªãã¨ããå®ç¾©ãããã¾ããããããã¯Sudachiã®æ£è¦åã§æºããå¸åã§ãã¾ãã
echo 'ããã±ã質' | sudachipy -m C ããã±ã質 åè©,æ®éåè©,ä¸è¬,*,*,* èç½è³ª
ä»åã®ç§»è¡ã§ã¯ç§ãOSSã¨ãã¦å ¬éãã¦ããchinormfilterã¨ãããã¼ã«ã使ã£ã¦ãããå®ç¾ãã¾ããã
ãã®ãã¼ã«ã使ã£ã¦Sudachiæ£è¦åã§ã¾ããªãããã®ãåé¤ãã¾ãã
$ cat tests/text.txt ã¬ããªããã,ã¬ããªããã¤ã ãªã³ã´ => ææª é£²ã,åã tlc => tlc,å ¨èºæ°é ãªã³ããã±ã質,ãªã³èç½è³ª,ãªã³ã¿ã³ãã¯è³ª $ chinormfilter tests/test.txt -o out.txt $ cat out.txt ã¬ããªããã,ã¬ããªããã¤ã tlc => tlc,å ¨èºæ°é
ãã®ããã»ã¹ã§å¼ç¤¾ã§ã¯ã·ããã è¾æ¸ã340è¡ãã284è¡ã«æ¸ããã¾ããã
平仮å/ã«ã¿ã«ãã®æ£è¦åè¾æ¸ãä½ã
Sudachiã§ã¯ããç¨åº¦å¹³ä»®å/ã«ã¿ã«ã/æ¼¢åã®è¡¨è¨æºãã«å¯¾å¿ãã¦ããã¾ãããå ¨ã¦ã«å¯¾å¿ãã¦ããã訳ã§ã¯ããã¾ãããä¾ãã°ããããã¦ãã¼ããã¯Sudachiè¾æ¸ã§æªå®ç¾©ã§ãããå½¢æ ç´ è§£æããã¨ããããªçµæã«ãªãã¾ãã
echo 'ãããã¦ãã¼ã' | sudachipy -m C -s core ãã 代åè©,*,*,*,*,* æ¤ã ãã¦ã åè©,ä¸è¬,*,*,ä¸ä¸æ®µ-ã¿è¡,å½ä»¤å½¢ æ¨ã¦ã ã¼ è£å©è¨å·,ä¸è¬,*,*,*,* ã¼ ã å©åè©,*,*,*,æèªå©åè©-ãª,é£ä½å½¢-ä¸è¬ ã
å»çãã¡ã¤ã³ã®æ¤ç´¢ã§ã¯å¤ãã®ã«ã¿ã«ããåºç¾ããã¦ã¼ã¶ã¼ã¯å¹³ä»®åã§ãããã®åèªãæ¤ç´¢ãã¾ãããã®ãããããã©ã«ãã®Sudachiã§æ£è¦åã§ããªã平仮åãã«ã¿ã«ãã«å¯ãã¦ããããã¨ããã§ããããã§ä»åã®ç§»è¡ã«åããã¦å¹³ä»®åãã«ã¿ã«ãã«æ£è¦åããSudachiã¦ã¼ã¶ã¼è¾æ¸ãä½æãã¾ããããããå®ç¾ããããã®hirakanadicã¨ãããã¼ã«ãOSSã¨ãã¦å ¬éãã¦ãã¾ãã
ãã®ãã¼ã«ã§ã¯åºã¦ããæªå®ç¾©ã®ã«ã¿ã«ããæ¤ç¥ãã¦ããã®å¹³ä»®å表ç¾ãã«ã¿ã«ãã«æ£è¦åããå½¢ã§ã¦ã¼ã¶ã¼è¾æ¸ãä½æãã¾ãã
$ cat example/input.txt ã³ã¬ã¹ããã¼ã«å¤ é°ã®ããã«ã㢠濾èæ§ãªã³ãè « ã³ãªããã¯ããªã¦ã ã»ã¦ã«ã»ã©ã³ã¹ææç $ hirakanadic example/input.txt -o out.txt $ cat out.txt ãããã¦ãã¼ã,5146,5146,7000,ãããã¦ãã¼ã,åè©,æ®éåè©,ä¸è¬,*,*,*,ã³ã¬ã¹ããã¼ã«,ã³ã¬ã¹ããã¼ã«,*,*,*,*,* ã¸ãã«ã,5146,5146,7000,ã¸ã000,ã«ã,åè©,æ®éåè©,ä¸è¬,*,*,*,ãã«ãã¢,ãã«ãã¢,*,*,*,*,* ãããã°ãã¦ããã,5146,5146,7ãããã°ãã¦ããã,åè©,æ®éåè©,ä¸è¬,*,*,*,ã³ãªããã¯ããªã¦ã ,ã³ãªããã¯ããªã¦ã ,*,*,*,*,* ãããããã,5146,5146,7000,ãããããã,åè©,æ®éåè©,ä¸è¬,*,*,*,ã¦ã«ã»ã©ã³ã¹,ã¦ã«ã»ã©ã³ã¹,*,*,*,*,*
平仮åãå ¨ã¦ã·ããã ã§å®ç¾©ããæ¹æ³ãããã¾ããããã®ããã«Sudachiã¦ã¼ã¶ã¼è¾æ¸ã§æ£è¦åãå®ç¾©ããæ¹ãSudachiã®æ¹éã«åãããããã®ã§ããã®æ¹æ³ãæ¡ç¨ãã¦ãã¾ãã
移è¡æã®Sudachiåãæ¿ãæ¦ç¥
Analyzerã®ABãã¹ããããéã«ã¯åãindexã«2ã¤ã®Analyzerãå¿
è¦ã§ããä¾ãã°title
ã¨title_sudachi
ãªã©ãããããã®Analyzeræ¯ã«ãã£ã¼ã«ããåããã¨ãAPIã®ãªãªã¼ã¹é åºãè¤éã«ãªãããã¼ã¿æå
¥Batchã®æ¹ä¿®ãå¿
è¦ã«ãªã£ã¦ãã¾ãã
ããã§æã
ã¯ç§»è¡æ¦ç¥ã¨ãã¦Elasticsearchã®multi-fields
ãæ¡ç¨ãããã¨ã«ãã¾ããã
åããã£ã¼ã«ãã«è¤æ°ã®æ¹æ³ã§ããã¥ã¡ã³ããæ ¼ç´ããããã«è¨å®ã§ãã¾ããããã使ãã¨ä¸è¨ã®ãããªmappingã«ãªãã¾ãã
// ... "title": { "type": "text", "analyzer": "knuth_doc_analyzer", "search_analyzer": "knuth_search_analyzer", "fields": { "sudachi": { "type": "text", "analyzer": "sudachi_doc_analyzer", } } }, // ...
ãããã¦ããã¨APIãä¿®æ£åã«Aliasãåãæ¿ãã¦ãã対象ãã£ã¼ã«ããtitle
ã§å¤ãããªãã®ã§å½±é¿ãªãåããã¾ããAliasãåãæ¿ãã¦ãããABãã¹ãä»å
¥ç¾¤ã®ã¯ã¨ãªã®åãå
ãtitle.sudachi
ã«å¤ãã¦ãããã°ç§»è¡å®äºã§ãããã®ã¡ãªããã¯ãã¼ã¿æå
¥Batchãªã©ãæå
¥ããå
ã®ãã£ã¼ã«ãã®å¤æ´ãå¿
è¦ãªããã¨ã§ãããã®ããã«multi-fields
ãæ¡ç¨ãããã¨ã§Analyzerã®ç§»è¡ãã¹ã ã¼ãºã«é²ãããã¨ãã§ãã¾ãã
移è¡å¾ã®å½±é¿ã®äºå確èª
Analyzerã®ç§»è¡æã«ã¯æ¤ç´¢çµæã大ããå¤ããæããããã¾ãããªãªã¼ã¹åã«çµæã®å¤åãã¦ã¼ã¶ã¼ã«ã¨ã£ã¦åé¡ããªãããäºåãã§ãã¯ããå¿ è¦ãããã¾ãã
å¼ç¤¾ã§ã¯ä¸è¨ã®ããã«Kuromoji/Sudachiã®çµæãCSVã§åºåããã¹ãã¬ããã·ã¼ãã§ã¤ã³ãã¼ããã¦æ¯è¼ããããã«ãã¾ãããã¹ãã¬ããã·ã¼ãã§åºãã®ã¯ãã¸ãã¹ãµã¤ãã®äººéã§ã確èªã§ããããã«ããããã§ãã
ãã¼ã¯ã¼ã,before_hits,after_hits,before_tokens,after_tokens_a,after_tokens_c ã¼ããã,çµç³,2,1156,ãã¦ã³ã¦/çµç³,èè±/çµç³,èè±/çµç³ // 以ä¸çç¥
ã¹ãã¬ããã·ã¼ãã®è¡¨è¨ã ã¨ãã®ããã«ãªãã¾ãã
before/afterã¯ããããKuromoji/Sudachiã®çµæã§ãbefore_hitsã¯ç§»è¡åã®ãããæ°after_hitsã¯ç§»è¡å¾ã®ãããæ°ã§ããabefore_tokensã¯ç§»è¡åã®çµæã§fter_tokens_a/after_tokens_cã¯ããããSudachiåå²ã¢ã¼ãA/Bã®çµæã§ãã
äºåãã§ãã¯ã®ãã¤ã³ãã¨ãã¦ããããæ°ãåå¾ã§å¤§ããæ¸å°ãã¦ãããã®ã¯åç¾çã大ããä¸ãã£ã¦ããå¯è½æ§ãããã¾ããããããå®æ§çã«ç¢ºèªãã¦åé¡ãèµ·ãã¦ããªãã確èªãã¾ããããéã«ãããæ°ã大ããå¢ãã¦ããå ´åã¯ãåè©ãã£ã«ã¿ã¼ã®è¨å®ãã¹ã§æ¤ç´¢ã«å¿ è¦ãªãã¼ã¯ã³ãåããã¦ããå¯è½æ§ãããã®ã§ããã¡ãããã§ãã¯ãã¦ããã¾ãããã
ãã®ããã«äºåã«ç§»è¡æã®åé¡ãããç¨åº¦ç¢ºèªã§ãã¾ããæã ã¯ãã®æ¹æ³ã§ç§»è¡æã®åè©ãã£ã«ã¿ã¼ã®è¨å®ãã¹ãSudachiã§å¯¾å¿ã§ãã¦ããªã表è¨æºãã®åé¡ãªã©ãæ¤åºã§ãã¾ããã
å¼ç¤¾ã®ãªãªã¼ã¹å¾ã®ABãã¹ãã«ã¤ãã¦ã¯ç¾å¨å®æ½ä¸ã§ããABãã¹ãã®çµæã¨è©³ããæ¹æ³ã®è©±ã¯ã¾ãå¾æ¥ããã°ã§å ±åãããã¨æãã¾ãã
Sudachi移è¡æã®ããããã¤ã³ã
æå¾ã«Sudachi移è¡æã«ããã£ããã¤ã³ããã話ããã¾ãã
Aåå²ã¨Sudachiã·ããã è¾æ¸ã®åã¿åãããæªã
Aåå²ã¢ã¼ãã§Sudachiãæä¾ãã¦ããã·ããã è¾æ¸ã使ããã¨ããã¨ããããªæåãããããã¨ã©ã¼ãåºãããã¾ããããã¯Sudachiã·ããã è¾æ¸ã«ç»é²ããã¦ããåèªãåºæ¬çã«Cåå²åä½ã®åèªã§ãããããAåå²ã¢ã¼ãã§ä½¿ããã¨ããã¨ããããªtokenizeã«ãªãã¾ãã
å®éã«å¼ç¤¾ã§ã¯ãèªå® çé¤ãã¨ããåèªã§ã¨ã©ã¼ã«ãªããã¨ãçºè¦ãã¾ããã
çç±ã追ã£ã¦ã¿ã¾ããããSudachiã·ããã è¾æ¸ã«ãèªå® ãã¨ããã·ããã ãå®ç¾©ããã¦ãã¾ãã
御家,ã家,ããã¡,å¾¡å® ,ãå® ,èªå®
ããã§ãèªå® çé¤ãã¨ããåèªãAåå²ã¢ã¼ã+Sudachiã·ããã è¾æ¸ã®çµã¿åããã§Analyzeããã¨ä¸è¨ã®çµæã«ãªãã¾ã(å°ãé·ãã®ã§æããããã§ãã¾ã)ã
offsetãpositionãã¿ãã¨æããã«ã·ããã ã°ã©ãããããããªã£ã¦ãã¾ããããã¯ãããããã·ããã ãããã«Sudachiã§åå²ããã¦ãã¾ãçµæèµ·ããåé¡ã§ãã
å®éã«åå²ã¢ã¼ãA/Cã§å½¢æ ç´ è§£æããçµæã¯ä¸è¨ã«ãªãã¾ãã
echo 'ã家' | sudachipy -m A -s full ã æ¥é è¾,*,*,*,*,* 御 家 åè©,æ®éåè©,ä¸è¬,*,*,* 家 echo 'ã家' | sudachipy -m C -s full ã家 åè©,æ®éåè©,ä¸è¬,*,*,* 御家
ãã®çµæããAåå²ã¢ã¼ãã ã¨ã·ããã å±éããåèªãããã«å½¢æ ç´ è§£æããã¦ãã¾ããã¨ããããã¾ããå¼ç¤¾ã§ã¯ä¸æ¦ãAåå²ã¢ã¼ããå©ç¨ããAnalyzerã ãã·ããã è¾æ¸ãå¤ããã¨ã§å¯¾å¦ãã¦ãã¾ããã¾ããä»ã®åé¿çã¨ãã¦ã¯Aåå²ã§ã¯ãªãã·ããã ã ããåé¤ããã·ããã è¾æ¸ãä½æããæ¹æ³ãããã¾ããææ¬çãªè§£æ±ºæ¹æ³ã¯ã¾ã 調æ»ä¸ãªã®ã§ãåãåé¡ã«å½ãã£ãæ¹ã®è§£æ±ºçãããã°æ¯éæãã¦ããã ãããã§ãã
ã¦ã¼ã¶ã¼è¾æ¸ã®ãã«ãé度 ~ æ§æèªIDãæ§æèªæ å ±ã ~
Sudachiã®ã¦ã¼ã¶ã¼è¾æ¸ã®åå²æ å ±ã¯æ§æèªã®IDã¾ãã¯æ§æèªæ å ±ãè¨è¼ãããã¨ã«ãªãã¾ãã
// æ§æèªIDã§åå²æ å ±ãè¨è¿° èåããã±ã質,4786,4786,5000,èåããã±ã質,åè©,æ®éåè©,ä¸è¬,*,*,*,,èåããã±ã質,*,C,*,660881/810248,* // æ§æèªæ å ±ã§åå²æ å ±ãè¨è¿° èåããã±ã質,4786,4786,5000,èåããã±ã質,åè©,æ®éåè©,ä¸è¬,*,*,*,,èåããã±ã質,*,C,*,"èå,åè©,æ®éåè©,ãµå¤å¯è½,*,*,*,ã¦ã¦ã´ã¦/ããã±ã質,åè©,æ®éåè©,ä¸è¬,*,*,*,ã¿ã³ãã¯ã·ã",*
æåkuro2sudachiã¯è¾æ¸ã®ã¡ã³ããã³ã¹å®¹ææ§(ã©ã®ããã«åå²ãã¦ããããããã«ãããç¶æ )ã®ããã«åå²æ å ±ãæ§æèªæ å ±ã§è¨è¿°ãããã¿ã¼ã³ãæ¡ç¨ãã¦ãã¾ãããããããè¾æ¸ããã«ãããæã«é常ã«æéããããããã«ããå ¨ãçµãããªãã¨ããç¾è±¡ãçºçãã¦ãã¾ããã
åå ã¯SudachiPyã§æ§æèªæ å ±ããIDãå¼ã£å¼µã£ã¦ããã³ã¼ããè¾æ¸ã®ç·å½¢æ¢ç´¢ããã¦ããçºã§ããå¼ç¤¾ããç¾å¨TRIEã使ãå®è£ ãææ¡ãã¦ãã¾ãã
ãã¡ãã¾ã ãã¼ã¸ãããªãã®ã§ãkuro2sudachiã§ã¯æ§æèªIDã§è¨è¿°ãããã¨ã§ä¸æ¦å¯¾å¦ãã¦ãã¾ãã
Sudachi移è¡ã®çµæ
移è¡ã®çµæãæ§ã
ãªã¯ã¨ãªã§æ¤ç´¢çµæãæ¹åãã¾ããããã®ç« ã§ã¯Kuromojiã¨Sudachiã®ç§»è¡æã®åå¾æ¯è¼ã示ããSudachiã®ã¡ãªãããå確èªãã¾ããã¦ã¼ã¶ã¼è¾æ¸ãã·ããã è¾æ¸ã«ç»é²ãã¦ãããã®ã¯å¤ãã¦ããªãã®ã§Kuromojiã¨Sudachiã®ç´ç²ãªæ©è½æ¯è¼ã§ããã¡ãªã¿ã«Sudachiã§ä½¿ã£ã¦ããã·ã¹ãã è¾æ¸ã¯sudachi_full.dic
ãå©ç¨ãã¦ãã¾ãã
æå¾ã«ãç§ãæããSudachiã«ç§»è¡ãããã¨ã§çºçãããã¡ãªãããç°¡åã«ç´¹ä»ãã¾ãã
ã·ã¹ãã è¾æ¸ã®å å®åº¦
Kuromojiã ã¨ãããããããªã©ãè¾æ¸ã«ãªãã£ãããã«å½¢æ ç´ è§£æã®çµæããããããªã£ã¦ããããSudachiè¾æ¸ã¯èªå½ãè±å¯ãªãããããããããæ¤ç´¢ã§ããä»ã¾ã§ãããããªãã£ãããã¥ã¡ã³ãããããããããã«ãªãã¾ããã
query | kuromoji | sudachi C mode | ãããæ°å¤å | åè |
---|---|---|---|---|
ãããã çã¿ | ã¡ / ã·ã© / ç㤠| ç®é / çã¿ | 0 â 791 | ãããããããã·ã¹ãã è¾æ¸ã«ãã |
é¦ãã ãç¸ | é¦ / ã³ãªã« / ç¸ | é¦åã / ç¸ | 48 â 6 | ãããæ°ã¯ä¸ãã£ããPrecisionãä¸ãã£ã¦ãã |
æ©å®¤ äºé² | æ© / 室 / äºé² | æ©å®¤ / é²æ¢ / äºé² | 65 â 78 | ãæ©å®¤ããã·ã¹ãã è¾æ¸ã«ãã |
ã¡ãªã¿ã«Kuromojiã®æ¹ã§å¹³ä»®åãã«ã¿ã«ãã«ãªã£ã¦ããã®ã¯ãfilterã§å¹³ä»®åãå¼·å¶çã«ã«ã¿ã«ãã«å¯ãã¦ããå½±é¿ã§ããããã¯å¹³ä»®åãå¼·å¶çã«ã«ã¿ã«ãã«å¯ããã¨ããå°çã®å¯¾çããã¦ããçºã§ãã
ä¸æ¹ã§ããã¹ãç ããªã©ã¯Sudachiã«ãå®ç¾©ããªãã£ãã®ã§ãèªå½ãå¤ãã¨ã¯ããããã¯ããã¡ãã§ãã¦ã¼ã¶ã¼è¾æ¸ã§èªå½ãè£å®ããå¿ è¦ã¯ããããã§ãã
æ£è¦å
Sudachiã®æ£è¦åã§ãã¼ããããããèè±ãã«æ£è¦åã§ãããªã©ãRecallãå¤§å¹ ã«åä¸ãã¾ããã
query | kuromoji mode | sudachi C mode | ãããæ°å¤å | åè |
---|---|---|---|---|
ã¼ããã çµç³ | ãã¦ã³ã¦ / çµç³ | èè± / çµç³ | 2 â 1156 | ãã¼ããã/èè±ããå¯ããã¦ãã |
ã¡ããã¬ããµã¼ã æããå¤ | ã¡ããã¬ããµã¼ã / æã¬ã³å¤ | ã¡ããã¬ããµã¼ã / æçå¤ | 13 â 17 | ãæããå¤/æçå¤ããå¯ããã¦ãã |
ä¸æ¹ã§Sudachiæ£è¦åã§ã¯ãæ²»ã/ç´ããã«å¯ãã¦ãããããã®ã§ãã¢ããªã±ã¼ã·ã§ã³ã«ãã£ã¦ã¯æ£è¦åãå°ãããããã«ãªãå¯è½æ§ãããã¾ãã
echo 'æ²»ã' | sudachipy -m C -s core æ²»ã åè©,ä¸è¬,*,*,äºæ®µ-ã©è¡,çµæ¢å½¢-ä¸è¬ ç´ã
ãã®ãããªãã®ã¯ã¦ã¼ã¶ã¼è¾æ¸ã§ä¸æ¸ãå¯è½ãªã®ã§ãããæ°ã«ãªãæ£è¦åãããã°ä¸æ¸ããã¦ãããã¨ããå§ããã¾ãã
åå²æ å ±å®ç¾©
ã¦ã¼ã¶ã¼è¾æ¸ã«é£æ¥ã³ã¹ããåå²æ å ±ãé©åã«å®ç¾©ã§ããããã«ãªããã¦ã¼ã¶ã¼è¾æ¸ã§ãææããã°ããããã£ã¦ããææãå¼·å¼µã£ã¦ãããã«ãããããããã«ãªãã¾ããã
query | kuromoji | sudachi A mode | sudachi C mode | ãããæ°å¤å | åè |
---|---|---|---|---|---|
ææããã°ã | ææããã°ã | ææ / å¼·å¼µã | ææããã°ã | 8 â 425 | åå²æ å ±ãåå²ã¢ã¼ãæ¯ã«å©ç¨ã§ãã¦ãã |
è³è «ç åæçç¶ | è³è «ç / åæ / çç¶ | è³ / è «ç / åæ / çç¶ | è³è «ç / åæçç¶ | 22 â 25 | åå²æ å ±ã§ãè³ã®è «çãã«ãè³è «çãããããããããã«ãªã£ã |
ãã¡ãªãã: ã¦ã¼ã¶ã¼è¾æ¸ã®ç®¡çã³ã¹ã
ä¸æ¹ã§ãã¡ãªãããåå¨ããã¨æã£ã¦ãã¾ããè¾æ¸ã表ç¾è±ãã«ãªãååã§ãã¦ã¼ã¶ã¼è¾æ¸ã®ç®¡çã³ã¹ããå°ãä¸ããã¾ããã¾ãã¯ã¦ã¼ã¶ã¼è¾æ¸ãã©ã¼ãããã§ãããKuromojiã¨æ¯è¼ããã¨é常ã«è¤éã«ãªã£ã¦ããã®ããããã¾ããããããã¤ã³ãã§èª¬æããããã«å¤§ããªè¾æ¸ããã«ãããéã«ã¯æ§æèªIDæå®ãããå¿ è¦ãããã®ã§ãã©ããªåå²ã«ãªã£ã¦ãããä¸è¦åãããªããªã£ã¦ãã¾ãã
$ cat kuromoji_dict.txt èåããã±ã質,èåããã±ã質,èåããã±ã質,åè© çºä½æ§å¿æ¿ç´°å,çºä½æ§å¿æ¿ç´°å,çºä½æ§å¿æ¿ç´°å,åè© $ cat sudachi_user_dict.txt èåããã±ã質,4786,4786,5000,èåããã±ã質,åè©,æ®éåè©,ä¸è¬,*,*,*,,èåããã±ã質,*,C,*,660881/810248,* çºä½æ§å¿æ¿ç´°å,4786,4786,5000,çºä½æ§å¿æ¿ç´°å,åè©,æ®éåè©,ä¸è¬,*,*,*,,çºä½æ§å¿æ¿ç´°å,*,C,584006/434835/428494/619020,2756385/428494/619020,*
ã¾ããKuromojiã®æã«æ¯ã¹ã¦ã¦ã¼ã¶ã¼è¾æ¸ã®ãã«ããªã©ã®å·¥ç¨ãä½åã«çºçãã¾ã(ãã¡ããèªååããã°è¯ãã§ãã)ãæã ã®å ´åã¯æ¤ç´¢å質åä¸ã®ã¡ãªãããè¾æ¸ã®ç®¡çã³ã¹ããä¸åãã¨èãã¦ãã¾ãã
ãã¾ã
ããã¾ã§ã«ç´¹ä»ããä¸é£ã®Sudachi移è¡ã®ä¸ã§ã¨ã ã¹ãªã¼ã®æ¤ç´¢åºç¤ãã¼ã ãããã¦ã¼ã¶ã¼è¾æ¸ã®ãã«ãé度ãã§ç´¹ä»ããPR以å¤ã«1ã¤ã®Issueã¨1ã¤ã®PRãä½æãã¾ããã
ã¾ãã¯æ°è©ãå«ãåå²æ
å ±ããã«ãã§ããªãåé¡ã§ããããã¯Sudachiè¾æ¸ãã©ã¼ãããã®ãã¼ãµã¼ããè¦åºãã¨ãã¦ã® 1 ãããè¡çªå·1ãã«èª¤èªãã¦ããããã«èµ·ãã¦ããåé¡ã§ããããã¡ãã¯ãã§ã«ä¿®æ£ããã¼ã¸ããã¾ãããææ°ã®ãªãªã¼ã¹ã§ããv0.5.2ã«ã¯å
¥ã£ã¦ããªãã®ã§åãåé¡ã«å½ãã£ãå ´åã¯develop
ãã©ã³ããå©ç¨ãã¾ãããã
github.com
ãã¨ã¯Exceptionãreturnãã¦ãããã¹ã®ä¿®æ£ã¨ã¨ã©ã¼ã¡ãã»ã¼ã¸ã®è©³ç´°åã§ãããã¡ãããã¼ã¸ããã¾ããã github.com
Sudachiã¯æ¬çªéç¨ã«ååèããããå質ãæã£ã¦ãã¾ãããã¾ã ã¾ã æé·éç¨ãªã®ã§ããããããã©ãã©ãã³ã³ããªãã¥ã¼ããã¦ããããã§ãã
ã¾ã¨ã
ä»åã¯Elasticsearchã§Sudachiãå©ç¨ããæ¹æ³ã¨ãã¨ã ã¹ãªã¼æ¤ç´¢åºç¤ãã¼ã ã§KuromojiããSudachiã«ç§»è¡ãã話ããã¾ãããSudachiã«ç§»è¡ãã¦æ¤ç´¢ã®ä½é¨ãé常ã«è¯ããªãã¾ããããã¾ã çæ³ã®å»çæ¤ç´¢ã¨ã³ã¸ã³ã¨ã¯è¨ããªãã®ã§ããããããã©ãã©ãæ¤ç´¢æ¹åããã¦ããã¾ãã
移è¡æã«ä½ã£ããã¼ã«ãOSSã¨ãã¦å ¬éãã¦ããã®ã§PRãå¾ ã¡ãã¦ããã¾ãï¼
kuro2sudachi(è¾æ¸å¤æ) github.com
chinormfilter(Sudachiæ£è¦åã§ã¾ããªããã·ããã ã®åé¤) github.com
hirakanadic(Sudachiæ£è¦åã§ããªã平仮åã®æ£è¦åè¾æ¸çæ) github.com
We're hiring !!!
ã¨ã ã¹ãªã¼ã§ã¯æ¤ç´¢&æ¨è¦åºç¤ã®éçº&æ¹åãéãã¦å»çãåé²ãããã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãï¼ ç¤¾å ã§ã¯æ¥ã æ¤ç´¢ãæ¨è¦ã«ã¤ãã¦ã®è°è«ãæ´»çºã«è¡ããã¦ãã¾ãã
ãã¡ãã£ã¨è©±ãèãã¦ã¿ãããããã¨ãã人ã¯ãã¡ãããï¼ jobs.m3.com