Ejemplo n.º 1
0
def chrono(ctx, app_id, sentence_file, json_flag, sentence, doc_time,
           request_id):
    # type: (Context, unicode, Optional[IO], bool, unicode, unicode, unicode) -> None  # NOQA
    """Extract expression expressing date and time and normalize its value """

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

    api = GoolabsAPI(app_id)
    ret = api.chrono(
        sentence=sentence,
        doc_time=doc_time,
        request_id=request_id,
    )

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

    for pair in ret['datetime_list']:
        click.echo(u'{0}: {1}'.format(text(pair[0]), pair[1]))
Ejemplo n.º 2
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}