Google Cloud Natural Language

텍스트의 감정, 엔터티 및 콘텐츠를 분석하기 위해 Google Cloud Natural Language gRPC API를 호출하는 형식화된 인터페이스입니다.

소개

Google Cloud Natural Language는 감정, 엔터티 및 콘텐츠 범주를 포함하여 텍스트에서 인사이트를 추출합니다. gRPC API는 google.cloud.language.v1.LanguageService 서비스를 통해 제공되며, TLS를 통해 language.googleapis.com:443에서 접근하고, 주요 메서드는 AnalyzeSentiment, AnalyzeEntitiesClassifyText입니다.

요청은 TsgcGRPCLanguageAnalyzeSentimentRequestTsgcGRPCLanguageAnalyzeEntitiesRequest와 같은 형식화된 클래스로 작성되며, 각각 DocType이 PLAIN_TEXT로 설정된 Document와 분석할 텍스트 콘텐츠를 함께 전달합니다.

아래 예제는 서비스 계정 JWT로 인증하고, Natural Language 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, 일반 텍스트 문장에 대해 AnalyzeSentiment를 호출합니다.


    TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
    oHTTP2->Host = "language.googleapis.com";
    oHTTP2->Port = 443;
    oHTTP2->TLS = true;

    TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
    oGRPC->Client = oHTTP2;

    // service-account JWT authentication
    oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
    oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://language.googleapis.com/";
    oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);

    // build the typed request and call the method
    TsgcGRPCLanguageAnalyzeSentimentRequest *oRequest = new TsgcGRPCLanguageAnalyzeSentimentRequest();
    oRequest->Document->DocType = "PLAIN_TEXT";
    oRequest->Document->Content = "I really love this product, it works great!";
    TsgcGRPCResponse *oResponse = oGRPC->Call("google.cloud.language.v1.LanguageService", "AnalyzeSentiment", oRequest->ToBytes());
    ShowMessage(oResponse->DataString);
    delete oRequest;

Methods

Name설명
AnalyzeSentiment문서의 전반적인 감정을 분석하여 점수와 크기를 반환합니다.
AnalyzeEntities문서에서 명명된 엔터티(사람, 장소, 조직)를 감지합니다.
ClassifyText문서를 콘텐츠 범주로 분류합니다.

Demo

작동하는 샘플은 데모 폴더 Demos/21.GRPC/14.Natural_Language에서 제공되며, AnalyzeSentiment 메서드로 인증하고 텍스트의 감정을 분석하는 방법을 보여줍니다.

참조