Exemple #1
0
def morph(ctx, app_id, sentence_file, json_flag, sentence, info_filter,
          pos_filter, request_id):
    # type: (Context, unicode, Optional[IO], bool, unicode, unicode, unicode, unicode) -> None  # NOQA
    """ Morphological analysis for Japanese."""

    app_id = clean_app_id(app_id)
    sentence = clean_sentence(sentence, sentence_file)

    if info_filter:
        info_filter = info_filter.replace(',', '|')

    if pos_filter:
        pos_filter = pos_filter.replace(',', '|')

    api = GoolabsAPI(app_id)
    ret = api.morph(
        sentence=sentence,
        info_filter=info_filter,
        pos_filter=pos_filter,
        request_id=request_id,
    )

    if json_flag:
        click.echo(format_json(api.response.json()))
        return

    for words in ret['word_list']:
        for word in words:
            click.echo(','.join(word))
Exemple #2
0
def get_posChecker(keyword_list):
    app_id = "72557413b523d38db2d1de26f8095928d43d6d0882707ed41249f9edb643db45"
    api = GoolabsAPI(app_id)
    check_list = []
    for keyword in keyword_list:
        check_list.append(
            str(api.morph(sentence=keyword)["word_list"][0][0][1]))
    if len(list(set(check_list))):
        return True
    else:
        return False
Exemple #3
0
def get_request(text):
    api = GoolabsAPI(key)

    response = api.morph(sentence=text)
    return response
Exemple #4
0
def get_promise_content(letter):
    api = GoolabsAPI(GOO_API_KEY)
    index = 0
    # letter = "クリスマスに岩見と一緒に東京駅に来て"
    # 時刻情報正規化API
    # chrono_response = api.chrono(sentence=letter)
    # 固有表現抽出API
    entity_response = api.entity(sentence=letter)
    # 形態素解析API
    # morph_response = api.morph(sentence=letter)

    date = ''
    hour = ''
    min = ''
    place = ''

    for i in range(len(entity_response["ne_list"])):

        # 日付の抽出
        if entity_response["ne_list"][i][1] == "DAT":
            day_response = api.chrono(sentence=entity_response["ne_list"][i][0])

            if len(day_response['datetime_list']) != 0:
                date = day_response["datetime_list"][0][1]

                # 約束内容の要素番号を算出
                day = entity_response["ne_list"][i][0]
                index = letter.find(day) + len(day)

        # 時間の抽出
        elif entity_response["ne_list"][i][1] == "TIM":
            time_len = len(entity_response["ne_list"][i][0])

            for j in range(time_len):

                if entity_response["ne_list"][i][0][j] == u"時":
                    hour = entity_response["ne_list"][i][0][0:j]
                    hour_n = j

                    # 約束内容の要素番号を算出
                    time = entity_response["ne_list"][i][0]
                    index = letter.find(time) + len(time)

                    if j != time_len - 1:
                        if entity_response["ne_list"][i][0][j + 1] == u"半":
                            min = "30"

                elif entity_response["ne_list"][i][0][j] == u"分":
                    min = entity_response["ne_list"][i][0][hour_n + 1:j]

        elif entity_response["ne_list"][i][1] == "LOC":
            place = entity_response["ne_list"][i][0]

    # 約束内容を出力
    # 約束内容の最初の文字に格助詞が入ってるか調べる
    morph_response = api.morph(sentence=letter[index:len(letter)])
    if morph_response["word_list"][0][0][1] == u"格助詞" or morph_response["word_list"][0][0][1] == u"読点":
        par_len = len(morph_response["word_list"][0][0][0])

        content = letter[index + par_len:len(letter)]
    else:
        content = letter[index:len(letter)]

    return {'date': date, 'hour': hour, 'min': min, 'content': content, 'place': place}
Exemple #5
0
    unix_socket="/Applications/MAMP/tmp/mysql/mysql.soc\
k",
    host="localhost",
    db="Wordrop",
    user="******",
    passwd="root",
    charset="utf8")

cur = connector.cursor()

cur.execute("select * from home;")

app_id = "2d84d0d734ebefeb1f4dcf8ae106ec9d2f3b72a5be084a1014d6e27a9002ffef"
api = GoolabsAPI(app_id)

response = api.morph(pos_filter="名詞", sentence=tex)  #sentenceにある言葉を形態素解析する
value = response["word_list"]  #形態素解析の結果を代入                             \

response = api.entity(sentence=value)  #名詞の固有表現を求める                   \

list = response.values()

pp(value)

response = api.entity(sentence=value[0][0][0])

print type(value)

ss = []
count = 0
Exemple #6
0
    for row in f:
        chat_text = row
        print(row)

app_id = "13346dab6a67b41a884de45bcbf4bdc523ced4da711c35346f0a8501ef0b23fe"
api = GoolabsAPI(app_id)

echat_text = chat_text.encode('shift-jis')
uchat_text = echat_text.decode('shift-jis')
# # See sample response below.
# ret = api.entity(sentence=uchat_text)
# with open('./data/entity_response.json', 'w', newline='', encoding='utf-8') as f:
#   f.write(str(ret))

# See sample response below.
ret = api.morph(sentence=uchat_text)
with open('./data/morph_response.json', 'w', newline='',
          encoding='utf-8') as f:
    f.write(str(ret))
# print (json.dumps(ret, sort_keys = True, indent = 4))
# {'word_list': [[['トイレットペーパー', '名詞', 'トイレットペーパー'], \
# ['を', '格助詞', 'ヲ'], ['5', 'Number', 'ゴ'], ['個', '助数詞', 'コ'], \
# ['持', '動詞語幹', 'モ'], ['っ', '動詞活用語尾', 'ッ'], ['て', '動詞接尾辞', 'テ'], \
# ['い', '動詞語幹', 'イ'], ['く', '動詞接尾辞', 'ク'], ['よ', '終助詞', 'ヨ'], ['。', '句点', '$']]], \
# 'request_id': 'labs.goo.ne.jp\t1477797716\t0'}

for i in ret:
    groupDict = ret[i]
    break

# print (groupDict[0][0][0])