LoginSignup
7
6

More than 5 years have passed since last update.

【GAS】【UiPath】テキスト分析API ~感情判定、誤字脱字チェック、要約、キーワード抽出~*(自然言語処理

Last updated at Posted at 2019-02-22

はじめに

GASからGoogle CloudのNatural Language APIを叩いて、品詞を分類する記事はみつかったものの、
感情=ネガポジ分析については、なかったので知見を共有します

またjson配列の抽出方法について、不明点がございましたら本稿に少し含んでおりますので、ご覧ください。
※おまけで感情判定以外のAPIについても、UiPathから叩く方法など追加しました

感情判定

使用するAPI
Cloud Natural Language API
-1.0 ~ 0 ~ 1.0 の幅で、ネガティブ(悲しみ・怒り)~ニュートラル~ポジティブのscoreを返します。
※APIキーを発行するところは、情報溢れてますので割愛

以下、コーディング例

悲しい文章

function myFunction() {

  /*---------------------------
    GASで感情分析API叩く
   --------------------------*/

  var API_KEY = PropertiesService.getScriptProperties().getProperty("key");
  //***分析する文章を書く***
  var content = "友情は多くは見せかけであり、恋は多くの愚かさにすぎない。"
 //レスポンスはJSONで返る
function analyzeSentiment(content){
  var data = {
    'document' : {
      'type' : 'PLAIN_TEXT',
      'language' : 'ja',
      'content' : content
    },
    'encodingType': 'UTF8'
  }; 
  var params = {
    'contentType' : 'application/json',
    'method' : 'post',
    'payload' : JSON.stringify(data)
  };
  var url = 'https://language.googleapis.com/v1/documents:analyzeSentiment?key=' + API_KEY;
  return UrlFetchApp.fetch(url, params);
}
 Logger.log(JSON.parse(analyzeSentiment(content))["documentSentiment"]["score"])
}


※json配列の抽出を json["documentSentiment"]["score"]と取得す
る。json.属性.属性や、事例として納めておきます。
※ちなみに上記例では、socre(ネガポジ判定)は-0.4(悲しい)とでます。

本稿で、今後以下もまとめます。

誤字脱字チェック(途中)

Proofreading api
リクルートの誤字脱字判定

誤字
function myFunction() {


  /*---------------------------
    GASで誤字検知API叩く
   --------------------------*/

  var API_KEY = PropertiesService.getScriptProperties().getProperty("key");
  var A3rt_KEY = PropertiesService.getScriptProperties().getProperty("a3rt");
  //***分析する文章を書く***
  var content = "システムあb企画から開発"


 //レスポンスはJSONで返る
function analyzeSentiment(content){
  var data = {
    'document' : {
      'type' : 'PLAIN_TEXT',
      'language' : 'ja',
      'content' : content
    },
    'encodingType': 'UTF8'
  }; 
  var params = {
    'contentType' : 'application/json',
    'method' : 'post',
    'payload' : JSON.stringify(data)
  };

  //var url = 'https://language.googleapis.com/v1/documents:analyzeSentiment?key=' + API_KEY;
  var url = 'https://api.a3rt.recruit-tech.co.jp/proofreading/v2/typo?apikey='+A3rt_KEY+'&sentence='+content;
  return UrlFetchApp.fetch(url, params);
}
 Logger.log(JSON.parse(analyzeSentiment(content))["checkedSentence"])
}


output:システム <<あ>> <<b>> 企画から開発

キーワード抽出(途中)

Text Analytics API

UiPathでAPIを叩いた際の、デモをします(予定)

Cognitive Activitity のパッケージを追加して、サイドバーの Microsoft Text Analysisを配置して、任意文字列のキーワードの抽出ロボットを作成。
20190213.png

おわりに

GASでAPIを叩くと
自動返信誤字判定
と組み合わせて、業務日報に誤字チェックして返信する等用途が広がる点で便利かなと考えます。

参考

https://life89.jp/gas_cloud_natural_lang_api_post/
https://activities.uipath.com/lang-ja/docs/google-text-analysis

7
6
0

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
7
6