Cloud Natural Language API ã¨ã¯
GCP ã® ããã¹ãåæç¨ API ã§ãã
使ãæ¹ï¼å°å ¥ï¼
å ¬å¼ããã¥ã¡ã³ã ãå ¨ã¦ã§ãããä¸é¨ããã£ãã¨ãããæ¸ãã¦ããã¾ãã
1. èªè¨¼ç¨ã® JSON ãã¡ã¤ã«ã®åå¾
èªè¨¼ç¨ã® JSON ãã¡ã¤ã«ï¼ç§å¯éµè¾¼ã¿ï¼ã¯ãGCP ã®ãIAM ã¨ç®¡çãã¡ãã¥ã¼ããããµã¼ãã¹ã¢ã«ã¦ã³ãããé¸æãã¦ä½æãã¾ããããªãã·ã§ã³ãã¨ãã¦è¨å®ã§ããå 容ã¯ã¹ããããã¦ã大ä¸å¤«ã§ãã
ãã® JSON ãã¡ã¤ã«ã¯å度ãã¦ã³ãã¼ããããã¨ãã§ããªãã®ã§ã大åã«åãæ±ãã¾ãã
2. Ruby 2.7 ã§ã¯ 'google-protobuf' gem ã®ãã¼ã¸ã§ã³ã 3.11.1 ã«ããå¿ è¦ããã
Ruby 2.7 ã®å ´å㯠'google-cloud-language' gem ã®ä¾åã§å ¥ã£ã¦ãã 'google-protobuf' gem ã®ãã¼ã¸ã§ã³ãæ示çã« 3.11.1 ã«æå®ããå¿ è¦ãããã¾ããçç±ã¯æ¬¡ã®ã¨ããã§ãã
3. èªè¨¼ç¨ã® JSON ãã¡ã¤ã«ã®æå®ã¯ã³ã¼ãå ã§ãå¯è½
èªè¨¼ç¨ã® JSON ãã¡ã¤ã«ãæå®ããæ¹æ³ã¯ãå ¬å¼ããã¥ã¡ã³ãã«ã¯ä»¥ä¸ã®ããã«æ¸ããã¦ãã¾ãã
ç°å¢å¤æ° GOOGLE_APPLICATION_CREDENTIALS ãããµã¼ãã¹ ã¢ã«ã¦ã³ã ãã¼ãå«ã¾ãã JSON ãã¡ã¤ã«ã®ãã¡ã¤ã«ãã¹ã«è¨å®ãã¾ãã
ãã®æ¹æ³ã¨ã¯å¥ã«ãRuby ã®ã³ã¼ãããå ´æãæå®ãããã¨ãã§ãã¾ã*1ãå ·ä½çã«ã¯ gem ã®ããã¥ã¡ã³ã ã«æ¸ããã¦ããéãã§ã以ä¸ã®ããã«ãã¾ãã
Google::Cloud::Language.configure do |config| config.credentials = '/path/to' end
4. å ¬å¼ããã¥ã¡ã³ãã«ãã 'language.analyze_sentiment' 以å¤ã®æ å ±ãåå¾ããæ¹æ³
å
¬å¼ããã¥ã¡ã³ãã§ã¯ã¬ã¹ãã³ã¹ã®å¯¾è±¡ã¨ã㦠analyze_sentiment
ãæå®ãã¦ã¾ããCloud Natural Language API ã«ã¯ä»ã®ã¬ã¹ãã³ã¹ãããï¼å
¬å¼ãµã¤ãåç
§ï¼ãããããã®ã¬ã¹ãã³ã¹ãåå¾ããããã®ã¡ã½ãã㯠gem ã®ããã¥ã¡ã³ãã«è¨è¼ãããã¾ãã
éæ
GCP ã®ã¢ã«ã¦ã³ããããã¸ã§ã¯ãã®è¨å®ãAPI ã®æå¹å ãªã©ã¯ä¸è¬çãªæ¹æ³ã§ OK ã§ãã
*1:ç°å¢å¤æ°ã«ããã¡ã¤ã«ã®å ´æãè¨å®ã§ããã®ã§ãæè»ã«é é¿ã§ãã¾ã