Skip to content
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

Merged
merged 12 commits into from
Dec 4, 2018
Merged

Moved the imports and region tags inside the functions #1891

merged 12 commits into from
Dec 4, 2018

Conversation

happyhuman
Copy link
Contributor

Based on the new standard, the imports and the region tags should be placed inside the function.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 3, 2018
@happyhuman
Copy link
Contributor Author

happyhuman commented Dec 3, 2018

@jmdobry @dizcology @alixhami @nnegrey can you please review this PR?

"""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!'
Copy link
Contributor

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).

Copy link
Contributor Author

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?

Copy link
Contributor

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'

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

"""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'
Copy link
Contributor

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.

"""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!'
Copy link
Contributor

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.

import six
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
"""Detects entities in the text."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

"""Detects sentiment in the text."""
Copy link
Contributor

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.

"""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'
Copy link
Contributor

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.

"""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!'
Copy link
Contributor

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.

"""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'
Copy link
Contributor

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.

"""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!'
Copy link
Contributor

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.

Copy link
Contributor

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.

"""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'
Copy link
Contributor

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.

happyhuman and others added 3 commits December 4, 2018 13:42
- 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.
Copy link
Contributor

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 .

Copy link
Contributor

@alixhami alixhami left a 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.

from google.cloud.language import enums
from google.cloud.language import types

text = 'Android is a mobile operating system developed by Google, ' + \
Copy link
Contributor

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 \.

Copy link
Contributor Author

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. :)

@happyhuman happyhuman merged commit ce4e7c7 into GoogleCloudPlatform:master Dec 4, 2018
busunkim96 pushed a commit to busunkim96/python-language that referenced this pull request May 20, 2020
…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
hkdevandla pushed a commit to hkdevandla/python-language that referenced this pull request Sep 26, 2020
…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
busunkim96 pushed a commit to googleapis/python-language that referenced this pull request Sep 29, 2020
…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
m-strzelczyk pushed a commit that referenced this pull request Nov 18, 2022
* 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
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Jul 6, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants