language_syntax_text.yaml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. type: com.google.api.codegen.samplegen.v1p2.SampleConfigProto
  2. schema_version: 1.2.0
  3. samples:
  4. - region_tag: language_syntax_text
  5. title: Analyzing Syntax
  6. description: Analyzing Syntax in a String
  7. service: google.cloud.language.v1.LanguageService
  8. rpc: AnalyzeSyntax
  9. request:
  10. - field: document.content
  11. value: "This is a short sentence."
  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 tokens returned from the API"]
  28. - loop:
  29. collection: $resp.tokens
  30. variable: token
  31. body:
  32. - comment: ["Get the text content of this token. Usually a word or punctuation."]
  33. - define: text = token.text
  34. - print: ["Token text: %s", text.content]
  35. - print: ["Location of this token in overall document: %s", text.begin_offset]
  36. - comment:
  37. - |
  38. Get the part of speech information for this token.
  39. Parts of spech are as defined in:
  40. http://www.lrec-conf.org/proceedings/lrec2012/pdf/274_Paper.pdf
  41. - define: part_of_speech = token.part_of_speech
  42. - comment: ["Get the tag, e.g. NOUN, ADJ for Adjective, et al."]
  43. - print: ["Part of Speech tag: %s", part_of_speech.tag]
  44. - comment: ["Get the voice, e.g. ACTIVE or PASSIVE"]
  45. - print: ["Voice: %s", part_of_speech.voice]
  46. - comment: ["Get the tense, e.g. PAST, FUTURE, PRESENT, et al."]
  47. - print: ["Tense: %s", part_of_speech.tense]
  48. - comment: ["See API reference for additional Part of Speech information available"]
  49. - comment:
  50. - |
  51. Get the lemma of the token. Wikipedia lemma description
  52. https://en.wikipedia.org/wiki/Lemma_(morphology)
  53. - print: ["Lemma: %s", token.lemma]
  54. - comment:
  55. - |
  56. Get the dependency tree parse information for this token.
  57. For more information on dependency labels:
  58. http://www.aclweb.org/anthology/P13-2017
  59. - define: dependency_edge = token.dependency_edge
  60. - print: ["Head token index: %s", dependency_edge.head_token_index]
  61. - print: ["Label: %s", dependency_edge.label]
  62. - comment:
  63. - |
  64. Get the language of the text, which will be the same as
  65. the language specified in the request or, if not specified,
  66. the automatically-detected language.
  67. - print: ["Language of the text: %s", $resp.language]