language_sentiment_text.yaml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. type: com.google.api.codegen.samplegen.v1p2.SampleConfigProto
  2. schema_version: 1.2.0
  3. samples:
  4. - region_tag: language_sentiment_text
  5. title: Analyzing Sentiment
  6. description: Analyzing Sentiment in a String
  7. service: google.cloud.language.v1.LanguageService
  8. rpc: AnalyzeSentiment
  9. request:
  10. - field: document.content
  11. value: "I am so happy and joyful."
  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: ["Get overall sentiment of the input document"]
  28. - print: ["Document sentiment score: %s", $resp.document_sentiment.score]
  29. - print: ["Document sentiment magnitude: %s", $resp.document_sentiment.magnitude]
  30. - comment: ["Get sentiment for all sentences in the document"]
  31. - loop:
  32. collection: $resp.sentences
  33. variable: sentence
  34. body:
  35. - print: ["Sentence text: %s", sentence.text.content]
  36. - print: ["Sentence sentiment score: %s", sentence.sentiment.score]
  37. - print: ["Sentence sentiment magnitude: %s", sentence.sentiment.magnitude]
  38. - comment:
  39. - |
  40. Get the language of the text, which will be the same as
  41. the language specified in the request or, if not specified,
  42. the automatically-detected language.
  43. - print: ["Language of the text: %s", $resp.language]