Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9042

COTOHA でキーワードの抽出 (Node.js)

$
0
0

COTOHA API Portalの使用例です。

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

COTOHA でキーワードの抽出

フォルダー構造

$ tree -a
.
├── akai_rousoku.txt
├── .env
├── get_config.js
├── get_token.js
└── key_word.js
key_word.js
#! /usr/bin/node
// ---------------------------------------------------------------////  key_word.js////                  Feb/23/2020//// ---------------------------------------------------------------varfs=require("fs")varget_config=require('./get_config.js')varget_token=require('./get_token.js')// ---------------------------------------------------------------functionkey_word_proc(config,doc){varClient=require('node-rest-client').Clientconstheaders={"Content-Type":"application/json","Authorization":"Bearer "+config.access_token}constdata={"document":doc,"type":"default"}conststr_json=JSON.stringify(data)consturl=config.developer_api_base+"v1/keyword"constargs={data:str_json,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']+"\t"+unit['score'])}console.error("*** 終了 ***")})}// ---------------------------------------------------------------console.error("*** 開始 ***")constfilename=process.argv[2]console.error(filename)if(fs.existsSync(filename)){constdoc=fs.readFileSync(filename,'utf8')constconfig=get_config.get_config_proc()try{get_token.get_token_proc(config,doc,key_word_proc)}catch(error){console.error("*** error *** from get_token_proc ***")console.error(error)}}else{console.error("*** error *** "+filename+" doesn't exist. ***")}// ---------------------------------------------------------------

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

実行コマンド

export NODE_PATH=/usr/lib/node_modules
./key_word.js akai_rousoku.txt

Viewing all articles
Browse latest Browse all 9042

Trending Articles