LoginSignup
2

More than 3 years have passed since last update.

COTOHA で固有名詞の抽出 (Node.js)

Posted at

COTOHA API Portal の使用例です。

次と同じことを Node.js で行いました。

COTOHA で固有名詞の抽出

フォルダー構造

$ tree -a
.
├── .env
├── get_config.js
├── get_token.js
└── proper_noun.js
proper_noun.js
#! /usr/bin/node
// ---------------------------------------------------------------
//
//  proper_noun.js
//
//                  Feb/23/2020
//
// ---------------------------------------------------------------
var get_config = require('./get_config.js')
var get_token = require('./get_token.js')
// ---------------------------------------------------------------
function proper_noun_proc(config,sentence)
{
    var Client = require('node-rest-client').Client

    const headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer " + config.access_token
        }

    const data = {
        "sentence": sentence,
        "type": "default"
        }

    const url = config.developer_api_base + "v1/ne"

    const args = {
        data: data,
        headers: headers
        }

    var client = new Client()

    client.post(url, args, function (data, response) {
    llx = data["result"].length
    console.log("llx = " + llx)
    for (it in data["result"])
        {
        const unit = data["result"][it]
        console.log(unit['form'])
        }
        console.error ("*** 終了 ***")
    })
}

// ---------------------------------------------------------------
console.error ("*** 開始 ***")

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

const config = get_config.get_config_proc()

get_token.get_token_proc(config,sentence,proper_noun_proc)

// ---------------------------------------------------------------

get_config.js get_token.js はこちら
COTOHA API で構文解析 (Node.js)

実行コマンド

export NODE_PATH=/usr/lib/node_modules
./proper_noun.js

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
2