Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add initial Sentiment Analysis Tutorial files for Cloud NL API #522

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
merged 2 commits into from
Sep 14, 2016

Conversation

manshreck
Copy link

Change includes tutorial code, test code, and test review files

Change includes tutorial code, test code, and test review files
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 14, 2016
@manshreck manshreck merged commit 908fefb into GoogleCloudPlatform:master Sep 14, 2016
@theacodes
Copy link
Contributor

Hey, whoa, please don't merge without review! I'm going to revert this - please open another PR.

@@ -0,0 +1 @@
/Library/Frameworks/Python.framework/Versions/2.7/Python
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the gcloud dir from the checkin?

@@ -0,0 +1,4 @@
What was Hollywood thinking with this movie! I hated,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename the sentiment dir to resources, for consistency with the other samples

@@ -0,0 +1 @@
SSByZWFsbHkgd2FudGVkIHRvIGxvdmUgJ0JsYWRlcnVubmVyJyBidXQgdWx0aW1hdGVseSBJIGNvdWxkbid0IGdldApteXNlbGYgdG8gYXBwcmVjaWF0ZSBpdCBmdWxseS4gSG93ZXZlciwgeW91IG1heSBsaWtlIGl0IGlmIHlvdSdyZSBpbnRvCnNjaWVuY2UgZmljdGlvbiwgZXNwZWNpYWxseSBpZiB5b3UncmUgaW50ZXJlc3RlZCBpbiB0aGUgcGhpbG9zb3BoaWNhbApleHBsb3JhdGlvbiBvZiB3aGF0IGl0IG1lYW5zIHRvIGJlIGh1bWFuIG9yIG1hY2hpbmUuIFNvbWUgb2YgdGhlI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gbW92aWUgbWF5CmJlIHdvcnRoIHRoZSBtb25leS4KCg==
Copy link
Contributor

@jerjou jerjou Sep 14, 2016

Choose a reason for hiding this comment

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

I think this file isn't necessary?

http = httplib2.Http()
credentials.authorize(http)

service = discovery.build('language', 'v1beta1', http=http)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just do:

credentials = GoogleCredentials.get_application_default()
service = discovery.build('language', 'v1beta1', credentials=credentials)

The python client lib will take care of adding the right scope, and authorizing the http object.

polarity = response['documentSentiment']['polarity']
magnitude = response['documentSentiment']['magnitude']
except KeyError:
print("The response did not contain the expected fields.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just let the KeyError propagate up. Error handling doesn't really provide much educational value IMO..



if __name__ == '__main__':
parser = argparse.ArgumentParser()
Copy link
Contributor

@jerjou jerjou Sep 14, 2016

Choose a reason for hiding this comment

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

Add a module-level docstring and set that as the description. See http://go/python-sample-guide#argparse-section

except KeyError:
print("The response did not contain the expected fields.")
print('Sentiment: polarity of %s with magnitude of %s'
% (polarity, magnitude))
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer using the 'string {}'.format(arg) syntax

polarity = response['documentSentiment']['polarity']
magnitude = response['documentSentiment']['magnitude']
except KeyError:
print("The response did not contain the expected fields.")
Copy link
Contributor

Choose a reason for hiding this comment

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

style: prefer single quotes over double quotes

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.