Realiza un análisis de opiniones con la herramienta gcloud
En esta página, se muestra cómo comenzar a usar la API de Cloud Natural Language con el SDK de Google Cloud.
Para seguir la guía paso a paso sobre esta tarea directamente en la consola Google Cloud , haz clic en Guiarme:
Antes de comenzar
- 
    
      
        
        Sign in to your Google Account.If you don't already have one, sign up for a new account. 
- 
      Install the Google Cloud CLI. 
- 
          Si usas un proveedor de identidad externo (IdP), primero debes acceder a gcloud CLI con tu identidad federada. 
- 
        Para inicializar gcloud CLI, ejecuta el siguiente comando: gcloud init
- 
  
  
    Create or select a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith 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_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Natural Language API: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable language.googleapis.com 
- 
      Install the Google Cloud CLI. 
- 
          Si usas un proveedor de identidad externo (IdP), primero debes acceder a gcloud CLI con tu identidad federada. 
- 
        Para inicializar gcloud CLI, ejecuta el siguiente comando: gcloud init
- 
  
  
    Create or select a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith 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_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Natural Language API: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable language.googleapis.com 
- Comienza a usar la API de Natural Language en el idioma de tu elección con una biblioteca cliente de Cloud Natural Language. 
- Consulta los Conceptos básicos de Natural Language para obtener información conceptual sobre la formación de solicitudes de la API de Natural Language y manejar respuestas. 
- Prueba el instructivo de análisis de opiniones y explora las aplicaciones de ejemplo. 
Realiza una solicitud de análisis de entidades
gcloud
Usa la herramienta de línea de comandos degcloud para llamar al comando analyze-entities y usa la marca --content para especificar el texto que se analizará.
  
  
  
gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."
Línea de comandos
Usacurl para hacer una solicitud POST al método documents:analyzeEntities y proporciona el cuerpo de solicitud adecuado, como se muestra en el siguiente ejemplo.
En el ejemplo, se usa el comando gcloud auth application-default print-access-token a fin de obtener un token de acceso para la cuenta de servicio que creaste cuando configuraste el proyecto.
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' }"
Deberías ver una respuesta similar a la siguiente:
{ "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" }
Limpia
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID