{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "nlp-sample1.ipynb", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "code", "metadata": { "id": "TCA5-9PRLmQP" }, "source": [ "from googleapiclient.discovery import build\n", "lservice = build('language', 'v1', developerKey=APIKEY)\n", "import json\n", "text = '今日は朝から晴れていてとても気持ちがいい。明日も晴れるだろうか。どうなのかな... なんだか心配だ。'\n", "\n", "response = lservice.documents().analyzeSentiment(\n", " body={\n", " 'document': {\n", " 'type': 'PLAIN_TEXT',\n", " 'content': text,\n", " 'language': 'ja'\n", " }\n", " }).execute()\n", "# print(response)\n", "\n", "sentiment1 = response['documentSentiment']['score']\n", "if sentiment1 < 0:\n", " print(\"ネガティブな文章です。\")\n", "else:\n", " print(\"ポジティブな文章です。\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "boCI7Nk5S9JR" }, "source": [ "import getpass\n", "\n", "APIKEY = getpass.getpass()" ], "execution_count": null, "outputs": [] } ] }