-
Notifications
You must be signed in to change notification settings - Fork 6.6k
NL v1beta2 #908
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
Merged
NL v1beta2 #908
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db02f92
Reorganizes samples, adds new snippet, and demonstrates switching API…
gguuss 412655c
Corrects beta version in link
gguuss 5d85477
Copyright dates on new files
gguuss 703af83
Removes README with nav, changes all snippets to use v1beta2 in beta …
gguuss ec866d7
Fixes v1beta2 test on GCS sentiment.
gguuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Natural Language Samples for Cloud Client | ||
|
||
These samples demonstrate how to access the Google Cloud Natural Language API | ||
using the Google Cloud Client library. The samples are organized by API | ||
version: | ||
|
||
* [v1](v1) | ||
* [v1beta2](v1beta2) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
.. This file is automatically generated. Do not edit this file directly. | ||
|
||
Google Cloud Natural Language API Python Samples | ||
=============================================================================== | ||
|
||
This directory contains samples for Google Cloud Natural Language API. The `Google Cloud Natural Language API`_ provides natural language understanding technologies to developers, including sentiment analysis, entity recognition, and syntax analysis. This API is part of the larger Cloud Machine Learning API. | ||
|
||
|
||
|
||
|
||
.. _Google Cloud Natural Language API: https://cloud.google.com/natural-language/docs/ | ||
|
||
Setup | ||
------------------------------------------------------------------------------- | ||
|
||
|
||
Authentication | ||
++++++++++++++ | ||
|
||
Authentication is typically done through `Application Default Credentials`_, | ||
which means you do not have to change the code to authenticate as long as | ||
your environment has credentials. You have a few options for setting up | ||
authentication: | ||
|
||
#. When running locally, use the `Google Cloud SDK`_ | ||
|
||
.. code-block:: bash | ||
|
||
gcloud beta auth application-default login | ||
|
||
|
||
#. When running on App Engine or Compute Engine, credentials are already | ||
set-up. However, you may need to configure your Compute Engine instance | ||
with `additional scopes`_. | ||
|
||
#. You can create a `Service Account key file`_. This file can be used to | ||
authenticate to Google Cloud Platform services from any environment. To use | ||
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to | ||
the path to the key file, for example: | ||
|
||
.. code-block:: bash | ||
|
||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json | ||
|
||
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow | ||
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using | ||
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount | ||
|
||
Install Dependencies | ||
++++++++++++++++++++ | ||
|
||
#. Install `pip`_ and `virtualenv`_ if you do not already have them. | ||
|
||
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. | ||
|
||
.. code-block:: bash | ||
|
||
$ virtualenv env | ||
$ source env/bin/activate | ||
|
||
#. Install the dependencies needed to run the samples. | ||
|
||
.. code-block:: bash | ||
|
||
$ pip install -r requirements.txt | ||
|
||
.. _pip: https://pip.pypa.io/ | ||
.. _virtualenv: https://virtualenv.pypa.io/ | ||
|
||
Samples | ||
------------------------------------------------------------------------------- | ||
|
||
Quickstart | ||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
|
||
|
||
To run this sample: | ||
|
||
.. code-block:: bash | ||
|
||
$ python quickstart.py | ||
|
||
|
||
Snippets | ||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
|
||
|
||
To run this sample: | ||
|
||
.. code-block:: bash | ||
|
||
$ python snippets.py | ||
|
||
usage: snippets.py [-h] | ||
{sentiment-entities-text,sentiment-entities-file,sentiment-text,sentiment-file,entities-text,entities-file,syntax-text,syntax-file} | ||
... | ||
|
||
This application demonstrates how to perform basic operations with the | ||
Google Cloud Natural Language API | ||
|
||
For more information, the documentation at | ||
https://cloud.google.com/natural-language/docs. | ||
|
||
positional arguments: | ||
{sentiment-entities-text,sentiment-entities-file,sentiment-text,sentiment-file,entities-text,entities-file,syntax-text,syntax-file} | ||
sentiment-entities-text | ||
Detects entity sentiment in the provided text. | ||
sentiment-entities-file | ||
Detects entity sentiment in a Google Cloud Storage | ||
file. | ||
sentiment-text Detects sentiment in the text. | ||
sentiment-file Detects sentiment in the file located in Google Cloud | ||
Storage. | ||
entities-text Detects entities in the text. | ||
entities-file Detects entities in the file located in Google Cloud | ||
Storage. | ||
syntax-text Detects syntax in the text. | ||
syntax-file Detects syntax in the file located in Google Cloud | ||
Storage. | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
|
||
|
||
|
||
|
||
The client library | ||
------------------------------------------------------------------------------- | ||
|
||
This sample uses the `Google Cloud Client Library for Python`_. | ||
You can read the documentation for more details on API usage and use GitHub | ||
to `browse the source`_ and `report issues`_. | ||
|
||
.. Google Cloud Client Library for Python: | ||
https://googlecloudplatform.github.io/google-cloud-python/ | ||
.. browse the source: | ||
https://github.com/GoogleCloudPlatform/google-cloud-python | ||
.. report issues: | ||
https://github.com/GoogleCloudPlatform/google-cloud-python/issues | ||
|
||
|
||
.. _Google Cloud SDK: https://cloud.google.com/sdk/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file is used to generate README.rst | ||
|
||
product: | ||
name: Google Cloud Natural Language API | ||
short_name: Cloud Natural Language API | ||
url: https://cloud.google.com/natural-language/docs/ | ||
description: > | ||
The `Google Cloud Natural Language API`_ provides natural language | ||
understanding technologies to developers, including sentiment analysis, | ||
entity recognition, and syntax analysis. This API is part of the larger | ||
Cloud Machine Learning API. | ||
|
||
setup: | ||
- auth | ||
- install_deps | ||
|
||
samples: | ||
- name: Quickstart | ||
file: quickstart.py | ||
- name: Snippets | ||
file: snippets.py | ||
show_help: true | ||
|
||
cloud_client_library: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2017 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def run_quickstart(): | ||
# [START language_quickstart] | ||
# Imports the Google Cloud client library | ||
from google.cloud import language | ||
|
||
# Instantiates a client with they v1beta2 version | ||
language_client = language.Client(api_version='v1beta2') | ||
|
||
# The text to analyze | ||
text = 'Hallo Welt!' | ||
document = language_client.document_from_text(text, language='DE') | ||
|
||
# Detects the sentiment of the text | ||
sentiment = document.analyze_sentiment().sentiment | ||
|
||
print('Text: {}'.format(text)) | ||
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude)) | ||
# [END language_quickstart] | ||
|
||
|
||
if __name__ == '__main__': | ||
run_quickstart() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2017 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import quickstart | ||
|
||
|
||
def test_quickstart(capsys): | ||
quickstart.run_quickstart() | ||
out, _ = capsys.readouterr() | ||
assert 'Sentiment' in out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gapic-google-cloud-language-v1beta2==0.15.3 | ||
google-cloud-language==0.24.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
President Obama is speaking at the White House. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can really just omit this. :)