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

Natural Language GAPIC client library #1018

Merged
merged 16 commits into from
Jul 28, 2017
Merged
Prev Previous commit
Next Next commit
move pos_tag to local variable
  • Loading branch information
dizcology committed Jul 20, 2017
commit 9dba7ccabfd0ed023f883f0d1166d818ed571f86
16 changes: 10 additions & 6 deletions language/cloud-client/v1/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
from google.cloud.language import types
import six

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
POS_TAG = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')


# [START def_sentiment_text]
def sentiment_text(text):
Expand Down Expand Up @@ -153,8 +149,12 @@ def syntax_text(text):
# document.type == enums.Document.Type.HTML
tokens = client.analyze_syntax(document).tokens

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')

for token in tokens:
print(u'{}: {}'.format(POS_TAG[token.part_of_speech.tag],
print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag],
token.text.content))
# [END migration_analyze_syntax]
# [END def_syntax_text]
Expand All @@ -174,8 +174,12 @@ def syntax_file(gcs_uri):
# document.type == enums.Document.Type.HTML
tokens = client.analyze_syntax(document).tokens

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')

for token in tokens:
print(u'{}: {}'.format(POS_TAG[token.part_of_speech.tag],
print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag],
token.text.content))
# [END def_syntax_file]

Expand Down
16 changes: 10 additions & 6 deletions language/cloud-client/v1beta2/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
from google.cloud.language_v1beta2 import types
import six

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
POS_TAG = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')


def sentiment_text(text):
"""Detects sentiment in the text."""
Expand Down Expand Up @@ -136,8 +132,12 @@ def syntax_text(text):
# document.type == enums.Document.Type.HTML
tokens = client.analyze_syntax(document).tokens

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')

for token in tokens:
print(u'{}: {}'.format(POS_TAG[token.part_of_speech.tag],
print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag],
token.text.content))


Expand All @@ -154,8 +154,12 @@ def syntax_file(gcs_uri):
# document.type == enums.Document.Type.HTML
tokens = client.analyze_syntax(document).tokens

# part-of-speech tags from google.cloud.language.enums.PartOfSpeech.Tag
pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')

for token in tokens:
print(u'{}: {}'.format(POS_TAG[token.part_of_speech.tag],
print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag],
token.text.content))


Expand Down