language_sentiment_gcs.yaml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. type: com.google.api.codegen.samplegen.v1p2.SampleConfigProto
  2. schema_version: 1.2.0
  3. samples:
  4. - region_tag: language_sentiment_gcs
  5. title: Analyzing Sentiment (GCS)
  6. description: Analyzing Sentiment in text file stored in Cloud Storage
  7. service: google.cloud.language.v1.LanguageService
  8. rpc: AnalyzeSentiment
  9. request:
  10. - field: document.gcs_content_uri
  11. value: gs://cloud-samples-data/language/sentiment-positive.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: ["Get overall sentiment of the input document"]
  30. - print: ["Document sentiment score: %s", $resp.document_sentiment.score]
  31. - print: ["Document sentiment magnitude: %s", $resp.document_sentiment.magnitude]
  32. - comment: ["Get sentiment for all sentences in the document"]
  33. - loop:
  34. collection: $resp.sentences
  35. variable: sentence
  36. body:
  37. - print: ["Sentence text: %s", sentence.text.content]
  38. - print: ["Sentence sentiment score: %s", sentence.sentiment.score]
  39. - print: ["Sentence sentiment magnitude: %s", sentence.sentiment.magnitude]
  40. - comment:
  41. - |
  42. Get the language of the text, which will be the same as
  43. the language specified in the request or, if not specified,
  44. the automatically-detected language.
  45. - print: ["Language of the text: %s", $resp.language]