Guest User

Untitled

a guest
Jun 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import six
  2. from google.cloud import language
  3. from google.cloud.language import enums
  4. from google.cloud.language import types
  5.  
  6. text = 'President Kennedy spoke at the White House.'
  7.  
  8. client = language.LanguageServiceClient()
  9.  
  10. if isinstance(text, six.binary_type):
  11. text = text.decode('utf-8')
  12.  
  13. # Instantiates a plain text document.
  14. document = types.Document(
  15. content=text,
  16. type=enums.Document.Type.PLAIN_TEXT)
  17.  
  18. # Detects syntax in the document. You can also analyze HTML with:
  19. # document.type == enums.Document.Type.HTML
  20. tokens = client.analyze_syntax(document).tokens
  21.  
  22. for token in tokens:
  23. part_of_speech_tag = enums.PartOfSpeech.Tag(token.part_of_speech.tag)
  24. print(u'{}: {}'.format(part_of_speech_tag.name,
  25. token.text.content))
Advertisement
Add Comment
Please, Sign In to add comment