language_syntax_gcs.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_syntax_gcs
  5. title: Analyzing Syntax (GCS)
  6. description: Analyzing Syntax in text file stored in Cloud Storage
  7. service: google.cloud.language.v1.LanguageService
  8. rpc: AnalyzeSyntax
  9. request:
  10. - field: document.gcs_content_uri
  11. value: gs://cloud-samples-data/language/syntax-sentence.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 tokens returned from the API"]
  30. - loop:
  31. collection: $resp.tokens
  32. variable: token
  33. body:
  34. - comment: ["Get the text content of this token. Usually a word or punctuation."]
  35. - define: text = token.text
  36. - print: ["Token text: %s", text.content]
  37. - print: ["Location of this token in overall document: %s", text.begin_offset]
  38. - comment:
  39. - |
  40. Get the part of speech information for this token.
  41. Parts of spech are as defined in:
  42. http://www.lrec-conf.org/proceedings/lrec2012/pdf/274_Paper.pdf
  43. - define: part_of_speech = token.part_of_speech
  44. - comment: ["Get the tag, e.g. NOUN, ADJ for Adjective, et al."]
  45. - print: ["Part of Speech tag: %s", part_of_speech.tag]
  46. - comment: ["Get the voice, e.g. ACTIVE or PASSIVE"]
  47. - print: ["Voice: %s", part_of_speech.voice]
  48. - comment: ["Get the tense, e.g. PAST, FUTURE, PRESENT, et al."]
  49. - print: ["Tense: %s", part_of_speech.tense]
  50. - comment: ["See API reference for additional Part of Speech information available"]
  51. - comment:
  52. - |
  53. Get the lemma of the token. Wikipedia lemma description
  54. https://en.wikipedia.org/wiki/Lemma_(morphology)
  55. - print: ["Lemma: %s", token.lemma]
  56. - comment:
  57. - |
  58. Get the dependency tree parse information for this token.
  59. For more information on dependency labels:
  60. http://www.aclweb.org/anthology/P13-2017
  61. - define: dependency_edge = token.dependency_edge
  62. - print: ["Head token index: %s", dependency_edge.head_token_index]
  63. - print: ["Label: %s", dependency_edge.label]
  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]