-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved the imports and region tags inside the functions #1891
Conversation
@jmdobry @dizcology @alixhami @nnegrey can you please review this PR? |
language/cloud-client/v1/snippets.py
Outdated
"""Detects sentiment in the text.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# text = 'Your text to analyze, e.g. Hello, world!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to remove the parameter and have the actual text defined here. This will reduce confusion for the user. Only have commented out variables when absolutely necessary (ex. a project ID).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the function takes no input parameters as text, and we uncomment text to something like this:
text = 'Hello World'
Yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct on the 'Hello World' example. For the gcs_uri parameter, upload the sample file to the cloud-samples-data storage bucket, and then update to where you uploaded it. For example: gcs_uri = 'gs://cloud-samples-data/language/your-sample-file.txt'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we finalize that new sample rubric yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This page the example page alix? https://cloud.google.com/natural-language/docs/quickstart-client-libraries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not officially finalized because we're still waiting on UX testing for the script vs. function formatting. I believe eliminating the use of commented out variables when possible was non-controversial, though.
I don't think that link is the "official" example page, though those look like good samples to me.
language/cloud-client/v1/snippets.py
Outdated
"""Detects sentiment in the file located in Google Cloud Storage.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# gcs_uri = 'The gcs uri to your file, e.g. gs://my_bucket/my_file' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This URI could be defined here if you put the file in our sample data GCS bucket - gs://cloud-samples-data. This way the user has an easily accessible test file and the snippet tests don't have to upload a file every time. Let me know if you don't have permissions to that project and I'll add you.
language/cloud-client/v1/snippets.py
Outdated
"""Detects entities in the text.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# text = 'Your text to analyze, e.g. Hello, world!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please replace with the actual text.
language/cloud-client/v1/snippets.py
Outdated
import six | ||
from google.cloud import language | ||
from google.cloud.language import enums | ||
from google.cloud.language import types | ||
"""Detects entities in the text.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
language/cloud-client/v1/snippets.py
Outdated
from google.cloud import language | ||
from google.cloud.language import enums | ||
from google.cloud.language import types | ||
|
||
"""Detects sentiment in the text.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. It doesn't make sense to have a docstring if the user doesn't know it's a function.
language/cloud-client/v1/snippets.py
Outdated
"""Detects syntax in the file located in Google Cloud Storage.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# gcs_uri = 'The gcs uri to your file, e.g. gs://my_bucket/my_file' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please upload the file to the sample file bucket.
language/cloud-client/v1/snippets.py
Outdated
"""Detects entity sentiment in the provided text.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# text = 'Your text to analyze, e.g. Hello, world!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please hardcode the text.
language/cloud-client/v1/snippets.py
Outdated
"""Detects entity sentiment in a Google Cloud Storage file.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# gcs_uri = 'The gcs uri to your file, e.g. gs://my_bucket/my_file' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please upload the file to the sample bucket.
language/cloud-client/v1/snippets.py
Outdated
"""Classifies content categories of the provided text.""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# text = 'Your text to analyze, e.g. Hello, world!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please hardcode the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be longer than 20 tokens or the api call will fail.
language/cloud-client/v1/snippets.py
Outdated
"""Classifies content categories of the text in a Google Cloud Storage | ||
file. | ||
""" | ||
client = language.LanguageServiceClient() | ||
|
||
# TODO(developer): Uncomment the following line to run this code. | ||
# gcs_uri = 'The gcs uri to your file, e.g. gs://my_bucket/my_file' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Please upload the file to the sample bucket.
- Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly
@@ -1,6 +1,6 @@ | |||
#!/usr/bin/env python | |||
|
|||
# Copyright 2016 Google, Inc. | |||
# Copyright 2018 Google, LLC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future, I've been told we only need to update this for new files.
It's just LLC
no .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the files to the public bucket! Now they'll be easily accessible for users and other language samples. Just one last python comment.
language/cloud-client/v1/snippets.py
Outdated
from google.cloud.language import enums | ||
from google.cloud.language import types | ||
|
||
text = 'Android is a mobile operating system developed by Google, ' + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The +
signs are not necessary here. The string will continue because of the \
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting. I did not know this little trick. Thanks. :)
…gleCloudPlatform/python-docs-samples#1891) * Moved the imports and region tags inside the functions * Removed the unnecessary imports * Added the missing import (six) to the functions * Removed the extra whitespaces * Changes based on Alix's comments. - Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly * Remove extra whitespace * Removed extra whitespaces * Removed unused import * Removed the extra + signs
…gleCloudPlatform/python-docs-samples#1891) * Moved the imports and region tags inside the functions * Removed the unnecessary imports * Added the missing import (six) to the functions * Removed the extra whitespaces * Changes based on Alix's comments. - Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly * Remove extra whitespace * Removed extra whitespaces * Removed unused import * Removed the extra + signs
…gleCloudPlatform/python-docs-samples#1891) * Moved the imports and region tags inside the functions * Removed the unnecessary imports * Added the missing import (six) to the functions * Removed the extra whitespaces * Changes based on Alix's comments. - Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly * Remove extra whitespace * Removed extra whitespaces * Removed unused import * Removed the extra + signs
* Moved the imports and region tags inside the functions * Removed the unnecessary imports * Added the missing import (six) to the functions * Removed the extra whitespaces * Changes based on Alix's comments. - Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly * Remove extra whitespace * Removed extra whitespaces * Removed unused import * Removed the extra + signs
…gleCloudPlatform/python-docs-samples#1891) * Moved the imports and region tags inside the functions * Removed the unnecessary imports * Added the missing import (six) to the functions * Removed the extra whitespaces * Changes based on Alix's comments. - Sample files no longer have input arguments - Input texts and uri's are hard coded - unit tests are modified accordingly * Remove extra whitespace * Removed extra whitespaces * Removed unused import * Removed the extra + signs
Based on the new standard, the imports and the region tags should be placed inside the function.