Advertisement
lamiastella

gc_language_test.py

Mar 4th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Copyright 2016 Google Inc. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. #     http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16.  
  17. from google.auth import compute_engine
  18. from google.cloud import storage
  19. #storage_client = storage.Client(credentials="credentials.json", project="entity-based sentiment")
  20. #buckets = list(storage_client.list_buckets())
  21. #print(buckets)
  22.  
  23. def run_quickstart():
  24.     # [START language_quickstart]
  25.     # Imports the Google Cloud client library
  26.     # [START migration_import]
  27.     from google.cloud import language
  28.     from google.cloud.language import enums
  29.     from google.cloud.language import types
  30.     # [END migration_import]
  31.  
  32.     # Instantiates a client
  33.     # [START migration_client]
  34.     client = language.LanguageServiceClient()
  35.     # [END migration_client]
  36.  
  37.     # The text to analyze
  38.     text = u'Hello, world!'
  39.     document = types.Document(
  40.         content=text,
  41.         type=enums.Document.Type.PLAIN_TEXT)
  42.  
  43.     # Detects the sentiment of the text
  44.     sentiment = client.analyze_sentiment(document=document).document_sentiment
  45.  
  46.     print('Text: {}'.format(text))
  47.     print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))
  48.     # [END language_quickstart]
  49.  
  50.  
  51. if __name__ == '__main__':
  52.     run_quickstart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement