language_entity_sentiment_gcs.yaml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. type: com.google.api.codegen.samplegen.v1p2.SampleConfigProto
  2. schema_version: 1.2.0
  3. samples:
  4. - region_tag: language_entity_sentiment_gcs
  5. title: Analyzing Entity Sentiment (GCS)
  6. description: Analyzing Entity Sentiment in text file stored in Cloud Storage
  7. service: google.cloud.language.v1.LanguageService
  8. rpc: AnalyzeEntitySentiment
  9. request:
  10. - field: document.gcs_content_uri
  11. value: gs://cloud-samples-data/language/entity-sentiment.txt
  12. comment: |
  13. Google Cloud Storage URI where the file content is located.
  14. e.g. gs://[Your Bucket]/[Path to File]
  15. input_parameter: gcs_content_uri
  16. - field: document.type
  17. value: PLAIN_TEXT
  18. comment: "Available types: PLAIN_TEXT, HTML"
  19. - field: document.language
  20. value: en
  21. comment: |
  22. Optional. If not specified, the language is automatically detected.
  23. For list of supported languages:
  24. https://cloud.google.com/natural-language/docs/languages
  25. - field: encoding_type
  26. value: UTF8
  27. comment: "Available values: NONE, UTF8, UTF16, UTF32"
  28. response:
  29. - comment: Loop through entitites returned from the API
  30. - loop:
  31. collection: $resp.entities
  32. variable: entity
  33. body:
  34. - print: ["Representative name for the entity: %s", entity.name]
  35. - comment: ["Get entity type, e.g. PERSON, LOCATION, ADDRESS, NUMBER, et al"]
  36. - print: ["Entity type: %s", entity.type]
  37. - comment: ["Get the salience score associated with the entity in the [0, 1.0] range"]
  38. - print: ["Salience score: %s", entity.salience]
  39. - comment: ["Get the aggregate sentiment expressed for this entity in the provided document."]
  40. - define: sentiment = entity.sentiment
  41. - print: ["Entity sentiment score: %s", sentiment.score]
  42. - print: ["Entity sentiment magnitude: %s", sentiment.magnitude]
  43. - comment:
  44. - |
  45. Loop over the metadata associated with entity. For many known entities,
  46. the metadata is a Wikipedia URL (wikipedia_url) and Knowledge Graph MID (mid).
  47. Some entity types may have additional metadata, e.g. ADDRESS entities
  48. may have metadata for the address street_name, postal_code, et al.
  49. - loop:
  50. map: entity.metadata
  51. key: metadata_name
  52. value: metadata_value
  53. body:
  54. - print: ["%s = %s", metadata_name, metadata_value]
  55. - comment:
  56. - |
  57. Loop over the mentions of this entity in the input document.
  58. The API currently supports proper noun mentions.
  59. - loop:
  60. collection: entity.mentions
  61. variable: mention
  62. body:
  63. - print: ["Mention text: %s", mention.text.content]
  64. - comment: ["Get the mention type, e.g. PROPER for proper noun"]
  65. - print: ["Mention type: %s", mention.type]
  66. - comment:
  67. - |
  68. Get the language of the text, which will be the same as
  69. the language specified in the request or, if not specified,
  70. the automatically-detected language.
  71. - print: ["Language of the text: %s", $resp.language]