LoginSignup
0
1

More than 5 years have passed since last update.

elyzer -> NameError: name 'unicode' is not defined

Last updated at Posted at 2017-09-21

Update


Elyzer: Elasticsearch の検索 Issue で役に立つツール。

アナライザの各フィルターがどう動いてるか解るやつ

ただ、python のバージョン Issue? っぽい何かでしっかり動かなかった。。。

$ pip show elyzer
Name: elyzer
Version: 1.1.0
Summary: Step-by-Step Debug Elasticsearch Analyzers
Home-page: https://github.com/o19s/elyzer
Author: Doug Turnbull
Author-email: dturnbull@o19s.com
License: Apache
Location: /usr/lib/python3.4/site-packages
$ elyzer --es http://host:9200 --index esindex --analyzer my_analyzer 'スモモ'
Requires: elasticsearch
Traceback (most recent call last):
  File "/usr/bin/elyzer", line 9, in <module>
    load_entry_point('elyzer==1.1.0', 'console_scripts', 'elyzer')()
  File "/usr/lib/python3.4/site-packages/elyzer/__main__.py", line 42, in main
    es=es))
  File "/usr/lib/python3.4/site-packages/elyzer/elyzer.py", line 36, in getAnalyzer
    normalizeAnalyzer(analyzer)
  File "/usr/lib/python3.4/site-packages/elyzer/elyzer.py", line 19, in normalizeAnalyzer
    if (isinstance(analyzer['char_filter'], str) or isinstance(analyzer['char_filter'], unicode)):
NameError: name 'unicode' is not defined

とりあえず、以下の Patch でうごくっぽいけど、ダメかも。。

/usr/lib/python3.4/site-packages/elyzer/elyzer.py
def normalizeAnalyzer(analyzer):
    try:
-        if (isinstance(analyzer['char_filter'], str) or isinstance(analyzer['char_filter'], unicode)):
+        if (isinstance(analyzer['char_filter'], str)):
            analyzer['char_filter'] = [analyzer['char_filter']]
    except KeyError:
        analyzer['char_filter'] = []

動いた例

$ elyzer --es http://host:9200 --index esindex --analyzer my_analyzer 'すもももももももものうち'
CHAR_FILTER: kuromoji_iteration_mark
{0:す} {1:も} {2:も} {3:も} {4:も} {5:も} {6:も} {7:も} {8:も} {9:の} {10:う}        {11:ち}
TOKENIZER: kuromoji_user_dict
{0:すもも}   {1:も} {2:もも}      {3:も} {4:もも}      {5:の} {6:うち}
TOKEN_FILTER: kuromoji_baseform
{0:すもも}   {1:も} {2:もも}      {3:も} {4:もも}      {5:の} {6:うち}
TOKEN_FILTER: kuromoji_part_of_speech
{0:すもも}   {1:も} {2:もも}      {3:も} {4:もも}      {5:の} {6:うち}
0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1