gcloud 도구를 사용하여 감정 분석 수행
이 페이지에서는 Google Cloud SDK를 사용하여 Cloud Natural Language API를 시작하는 방법을 설명합니다.
Google Cloud 콘솔에서 이 태스크에 대한 단계별 안내를 직접 수행하려면 둘러보기를 클릭합니다.
시작하기 전에
-
Google 계정에 로그인합니다.
아직 계정이 없으면 새 계정을 등록하세요.
- Google Cloud CLI를 설치합니다.
-
gcloud CLI를 초기화하려면 다음 명령어를 실행합니다.
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Cloud Natural Language API를 사용 설정합니다.
gcloud services enable language.googleapis.com
- Google Cloud CLI를 설치합니다.
-
gcloud CLI를 초기화하려면 다음 명령어를 실행합니다.
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Cloud Natural Language API를 사용 설정합니다.
gcloud services enable language.googleapis.com
항목 분석 요청하기
gcloud
gcloud
명령줄 도구를 사용하여 analyze-entities
명령어를 호출하고 --content
플래그를 사용하여 분석할 텍스트를 지정합니다.
gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."
명령줄
curl
을 사용하여 documents:analyzeEntities
메서드에 POST
요청을 하고 다음 예시와 같이 적절한 요청 본문을 제공합니다.
이 예시에서는 gcloud auth application-default print-access-token
명령어를 사용하여 프로젝트를 설정할 때 만든 서비스 계정에 대한 액세스 토큰을 가져옵니다.
curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ "https://language.googleapis.com/v1/documents:analyzeEntities" \ --data "{ 'document':{ 'type':'PLAIN_TEXT', 'content':'Michelangelo Caravaggio, Italian painter, is known for \'The Calling of Saint Matthew\'.' }, 'encodingType':'UTF8' }"
다음과 비슷한 응답이 표시됩니다.
{ "entities": [ { "name": "Michelangelo Caravaggio", "type": "PERSON", "metadata": { "wikipedia_url": "http://en.wikipedia.org/wiki/Caravaggio", "mid": "/m/020bg" }, "salience": 0.83047235, "mentions": [ { "text": { "content": "Michelangelo Caravaggio", "beginOffset": 0 }, "type": "PROPER" }, { "text": { "content": "painter", "beginOffset": 33 }, "type": "COMMON" } ] }, { "name": "Italian", "type": "LOCATION", "metadata": { "mid": "/m/03rjj", "wikipedia_url": "http://en.wikipedia.org/wiki/Italy" }, "salience": 0.13870546, "mentions": [ { "text": { "content": "Italian", "beginOffset": 25 }, "type": "PROPER" } ] }, { "name": "The Calling of Saint Matthew", "type": "EVENT", "metadata": { "mid": "/m/085_p7", "wikipedia_url": "http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)" }, "salience": 0.030822212, "mentions": [ { "text": { "content": "The Calling of Saint Matthew", "beginOffset": 69 }, "type": "PROPER" } ] } ], "language": "en" }
삭제
- Google Cloud 콘솔에서 리소스 관리 페이지로 이동합니다.
- 프로젝트 목록에서 삭제할 프로젝트를 선택하고 삭제를 클릭합니다.
- 대화상자에서 프로젝트 ID를 입력한 후 종료를 클릭하여 프로젝트를 삭제합니다.
다음 단계
Cloud Natural Language 클라이언트 라이브러리를 사용하여 선택한 언어로 Natural Language API를 시작합니다.
자연어 기본사항을 참조하여 Natural Language API 요청 작성 및 응답 처리에 대한 개념 정보를 습득합니다.
감정 분석 튜토리얼을 사용해 보고 샘플 애플리케이션을 둘러봅니다.