From c69e7e16a99cd6f861453fbac392b0740c0ee7b1 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Tue, 28 Feb 2017 11:24:31 -0800 Subject: [PATCH] Updates client library to version 0.23.0 [(#832)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/832) --- .../snippets/cloud-client/quickstart.py | 2 +- .../snippets/cloud-client/requirements.txt | 2 +- .../samples/snippets/cloud-client/snippets.py | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/google-cloud-language/samples/snippets/cloud-client/quickstart.py b/packages/google-cloud-language/samples/snippets/cloud-client/quickstart.py index 3b42ac65ab67..3fd703a567ee 100644 --- a/packages/google-cloud-language/samples/snippets/cloud-client/quickstart.py +++ b/packages/google-cloud-language/samples/snippets/cloud-client/quickstart.py @@ -28,7 +28,7 @@ def run_quickstart(): document = language_client.document_from_text(text) # Detects the sentiment of the text - sentiment = document.analyze_sentiment() + sentiment = document.analyze_sentiment().sentiment print('Text: {}'.format(text)) print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude)) diff --git a/packages/google-cloud-language/samples/snippets/cloud-client/requirements.txt b/packages/google-cloud-language/samples/snippets/cloud-client/requirements.txt index afd4c94e7f9c..07685057df83 100644 --- a/packages/google-cloud-language/samples/snippets/cloud-client/requirements.txt +++ b/packages/google-cloud-language/samples/snippets/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-language==0.22.2 +google-cloud-language==0.23 diff --git a/packages/google-cloud-language/samples/snippets/cloud-client/snippets.py b/packages/google-cloud-language/samples/snippets/cloud-client/snippets.py index c0f5f8a37226..94d1db4a23a7 100644 --- a/packages/google-cloud-language/samples/snippets/cloud-client/snippets.py +++ b/packages/google-cloud-language/samples/snippets/cloud-client/snippets.py @@ -35,7 +35,7 @@ def sentiment_text(text): # Detects sentiment in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - sentiment = document.analyze_sentiment() + sentiment = document.analyze_sentiment().sentiment print('Score: {}'.format(sentiment.score)) print('Magnitude: {}'.format(sentiment.magnitude)) @@ -50,7 +50,7 @@ def sentiment_file(gcs_uri): # Detects sentiment in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - sentiment = document.analyze_sentiment() + sentiment = document.analyze_sentiment().sentiment print('Score: {}'.format(sentiment.score)) print('Magnitude: {}'.format(sentiment.magnitude)) @@ -65,15 +65,16 @@ def entities_text(text): # Detects entities in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - entities = document.analyze_entities() + entities = document.analyze_entities().entities for entity in entities: print('=' * 20) print('{:<16}: {}'.format('name', entity.name)) print('{:<16}: {}'.format('type', entity.entity_type)) - print('{:<16}: {}'.format('wikipedia_url', entity.wikipedia_url)) print('{:<16}: {}'.format('metadata', entity.metadata)) print('{:<16}: {}'.format('salience', entity.salience)) + print('{:<16}: {}'.format('wikipedia_url', + entity.metadata.get('wikipedia_url', '-'))) def entities_file(gcs_uri): @@ -85,15 +86,16 @@ def entities_file(gcs_uri): # Detects sentiment in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - entities = document.analyze_entities() + entities = document.analyze_entities().entities for entity in entities: print('=' * 20) print('{:<16}: {}'.format('name', entity.name)) print('{:<16}: {}'.format('type', entity.entity_type)) - print('{:<16}: {}'.format('wikipedia_url', entity.wikipedia_url)) print('{:<16}: {}'.format('metadata', entity.metadata)) print('{:<16}: {}'.format('salience', entity.salience)) + print('{:<16}: {}'.format('wikipedia_url', + entity.metadata.get('wikipedia_url', '-'))) def syntax_text(text): @@ -105,7 +107,7 @@ def syntax_text(text): # Detects syntax in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - tokens = document.analyze_syntax() + tokens = document.analyze_syntax().tokens for token in tokens: print('{}: {}'.format(token.part_of_speech, token.text_content)) @@ -120,7 +122,7 @@ def syntax_file(gcs_uri): # Detects syntax in the document. You can also analyze HTML with: # document.doc_type == language.Document.HTML - tokens = document.analyze_syntax() + tokens = document.analyze_syntax().tokens for token in tokens: print('{}: {}'.format(token.part_of_speech, token.text_content))