Help us understand the problem. What is going on with this article?

COTOHA で固有名詞の抽出

COTOHA API Portal の使用例です。

参考ページ

APIリファレンス
固有表現抽出

次の文から固有名詞を抽出してみます。

特急はくたかで富山に向かいます。それから、金沢に行って、兼六園に行きます。

フォルダー構造

$ tree -a
.
├── .env
├── get_config.py
├── get_token.py
└── proper_noun.py
proper_noun.py
#! /usr/bin/python
# -*- coding:utf-8 -*-
#
#   proper_noun.py
#
#                       Feb/22/2020
# ----------------------------------------------------------------------
import sys
import json
import requests
# ----------------------------------------------------------------------
from get_config import get_config_proc
from get_token import get_token_proc
# ----------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
config = get_config_proc()
access_token = get_token_proc(config)
#
sentence = "特急はくたかで富山に向かいます。それから、金沢に行って、兼六園に行きます。"
#
headers={
    "Content-Type": "application/json",
    "Authorization": "Bearer " + access_token
    }
#
data = {
    "sentence": sentence,
    "type": "default"
    }

str_json = json.dumps(data)
url = config['DEVELOPER_API_BASE_URL'] + "v1/ne"
try:
    rr=requests.post(url,headers=headers,data=str_json)
    dict_aa = json.loads(rr.text)
    llx = len(dict_aa['result'])
    sys.stderr.write("llx(result) = %d\n" % llx)
#
    for unit in dict_aa['result']:
        print(unit['form'])
except Exception as ee:
    sys.stderr.write("*** error *** in requests.post ***\n")
    sys.stderr.write(str(ee) + "\n")
#
sys.stderr.write("*** 終了 ***\n")
# ----------------------------------------------------------------------

get_config.py get_token.py はこちら
COTOHA API で構文解析

実行結果

$ ./proper_noun.py
*** 開始 ***
llx(result) = 3
富山
金沢
兼六園
*** 終了 ***
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした