COTOHA API Portalの使用例です。
次と同じことを Node.js で行いました。
フォルダー構造
$ tree -a
.
├── .env
├── get_config.js
├── get_token.js
└── proper_noun.js
proper_noun.js
#! /usr/bin/node
// ---------------------------------------------------------------//// proper_noun.js//// Feb/23/2020//// ---------------------------------------------------------------varget_config=require('./get_config.js')varget_token=require('./get_token.js')// ---------------------------------------------------------------functionproper_noun_proc(config,sentence){varClient=require('node-rest-client').Clientconstheaders={"Content-Type":"application/json","Authorization":"Bearer "+config.access_token}constdata={"sentence":sentence,"type":"default"}consturl=config.developer_api_base+"v1/ne"constargs={data:data,headers:headers}varclient=newClient()client.post(url,args,function(data,response){llx=data["result"].lengthconsole.log("llx = "+llx)for(itindata["result"]){constunit=data["result"][it]console.log(unit['form'])}console.error("*** 終了 ***")})}// ---------------------------------------------------------------console.error("*** 開始 ***")constsentence="特急はくたかで富山に向かいます。それから、金沢に行って、兼六園に行きます。"constconfig=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