language_entity_sentiment_text.yaml 2.9 KB

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