30
30
import six
31
31
32
32
33
- # [START def_sentiment_text ]
33
+ # [START language_sentiment_text ]
34
34
def sentiment_text (text ):
35
35
"""Detects sentiment in the text."""
36
36
client = language .LanguageServiceClient ()
@@ -39,45 +39,45 @@ def sentiment_text(text):
39
39
text = text .decode ('utf-8' )
40
40
41
41
# Instantiates a plain text document.
42
- # [START migration_document_text ]
43
- # [START migration_analyze_sentiment ]
42
+ # [START language_python_migration_document_text ]
43
+ # [START language_python_migration_sentiment_text ]
44
44
document = types .Document (
45
45
content = text ,
46
46
type = enums .Document .Type .PLAIN_TEXT )
47
- # [END migration_document_text ]
47
+ # [END language_python_migration_document_text ]
48
48
49
49
# Detects sentiment in the document. You can also analyze HTML with:
50
50
# document.type == enums.Document.Type.HTML
51
51
sentiment = client .analyze_sentiment (document ).document_sentiment
52
52
53
53
print ('Score: {}' .format (sentiment .score ))
54
54
print ('Magnitude: {}' .format (sentiment .magnitude ))
55
- # [END migration_analyze_sentiment ]
56
- # [END def_sentiment_text ]
55
+ # [END language_python_migration_sentiment_text ]
56
+ # [END language_sentiment_text ]
57
57
58
58
59
- # [START def_sentiment_file ]
59
+ # [START language_sentiment_gcs ]
60
60
def sentiment_file (gcs_uri ):
61
61
"""Detects sentiment in the file located in Google Cloud Storage."""
62
62
client = language .LanguageServiceClient ()
63
63
64
64
# Instantiates a plain text document.
65
- # [START migration_document_gcs_uri ]
65
+ # [START language_python_migration_document_gcs ]
66
66
document = types .Document (
67
67
gcs_content_uri = gcs_uri ,
68
68
type = enums .Document .Type .PLAIN_TEXT )
69
- # [END migration_document_gcs_uri ]
69
+ # [END language_python_migration_document_gcs ]
70
70
71
71
# Detects sentiment in the document. You can also analyze HTML with:
72
72
# document.type == enums.Document.Type.HTML
73
73
sentiment = client .analyze_sentiment (document ).document_sentiment
74
74
75
75
print ('Score: {}' .format (sentiment .score ))
76
76
print ('Magnitude: {}' .format (sentiment .magnitude ))
77
- # [END def_sentiment_file ]
77
+ # [END language_sentiment_gcs ]
78
78
79
79
80
- # [START def_entities_text ]
80
+ # [START language_entities_text ]
81
81
def entities_text (text ):
82
82
"""Detects entities in the text."""
83
83
client = language .LanguageServiceClient ()
@@ -86,7 +86,7 @@ def entities_text(text):
86
86
text = text .decode ('utf-8' )
87
87
88
88
# Instantiates a plain text document.
89
- # [START migration_analyze_entities ]
89
+ # [START language_python_migration_entities_text ]
90
90
document = types .Document (
91
91
content = text ,
92
92
type = enums .Document .Type .PLAIN_TEXT )
@@ -107,11 +107,11 @@ def entities_text(text):
107
107
print (u'{:<16}: {}' .format ('salience' , entity .salience ))
108
108
print (u'{:<16}: {}' .format ('wikipedia_url' ,
109
109
entity .metadata .get ('wikipedia_url' , '-' )))
110
- # [END migration_analyze_entities ]
111
- # [END def_entities_text ]
110
+ # [END language_python_migration_entities_text ]
111
+ # [END language_entities_text ]
112
112
113
113
114
- # [START def_entities_file ]
114
+ # [START language_entities_gcs ]
115
115
def entities_file (gcs_uri ):
116
116
"""Detects entities in the file located in Google Cloud Storage."""
117
117
client = language .LanguageServiceClient ()
@@ -137,10 +137,10 @@ def entities_file(gcs_uri):
137
137
print (u'{:<16}: {}' .format ('salience' , entity .salience ))
138
138
print (u'{:<16}: {}' .format ('wikipedia_url' ,
139
139
entity .metadata .get ('wikipedia_url' , '-' )))
140
- # [END def_entities_file ]
140
+ # [END language_entities_gcs ]
141
141
142
142
143
- # [START def_syntax_text ]
143
+ # [START language_syntax_text ]
144
144
def syntax_text (text ):
145
145
"""Detects syntax in the text."""
146
146
client = language .LanguageServiceClient ()
@@ -149,7 +149,7 @@ def syntax_text(text):
149
149
text = text .decode ('utf-8' )
150
150
151
151
# Instantiates a plain text document.
152
- # [START migration_analyze_syntax ]
152
+ # [START language_python_migration_syntax_text ]
153
153
document = types .Document (
154
154
content = text ,
155
155
type = enums .Document .Type .PLAIN_TEXT )
@@ -165,11 +165,11 @@ def syntax_text(text):
165
165
for token in tokens :
166
166
print (u'{}: {}' .format (pos_tag [token .part_of_speech .tag ],
167
167
token .text .content ))
168
- # [END migration_analyze_syntax ]
169
- # [END def_syntax_text ]
168
+ # [END language_python_migration_syntax_text ]
169
+ # [END language_syntax_text ]
170
170
171
171
172
- # [START def_syntax_file ]
172
+ # [START language_syntax_gcs ]
173
173
def syntax_file (gcs_uri ):
174
174
"""Detects syntax in the file located in Google Cloud Storage."""
175
175
client = language .LanguageServiceClient ()
@@ -190,10 +190,10 @@ def syntax_file(gcs_uri):
190
190
for token in tokens :
191
191
print (u'{}: {}' .format (pos_tag [token .part_of_speech .tag ],
192
192
token .text .content ))
193
- # [END def_syntax_file ]
193
+ # [END language_syntax_gcs ]
194
194
195
195
196
- # [START def_entity_sentiment_text ]
196
+ # [START language_entity_sentiment_text ]
197
197
def entity_sentiment_text (text ):
198
198
"""Detects entity sentiment in the provided text."""
199
199
client = language .LanguageServiceClient ()
@@ -223,9 +223,10 @@ def entity_sentiment_text(text):
223
223
print (u' Type : {}' .format (mention .type ))
224
224
print (u'Salience: {}' .format (entity .salience ))
225
225
print (u'Sentiment: {}\n ' .format (entity .sentiment ))
226
- # [END def_entity_sentiment_text ]
226
+ # [END language_entity_sentiment_text ]
227
227
228
228
229
+ # [START language_entity_sentiment_gcs]
229
230
def entity_sentiment_file (gcs_uri ):
230
231
"""Detects entity sentiment in a Google Cloud Storage file."""
231
232
client = language .LanguageServiceClient ()
@@ -251,9 +252,10 @@ def entity_sentiment_file(gcs_uri):
251
252
print (u' Type : {}' .format (mention .type ))
252
253
print (u'Salience: {}' .format (entity .salience ))
253
254
print (u'Sentiment: {}\n ' .format (entity .sentiment ))
255
+ # [END language_entity_sentiment_gcs]
254
256
255
257
256
- # [START def_classify_text ]
258
+ # [START language_classify_text ]
257
259
def classify_text (text ):
258
260
"""Classifies content categories of the provided text."""
259
261
client = language .LanguageServiceClient ()
@@ -271,10 +273,10 @@ def classify_text(text):
271
273
print (u'=' * 20 )
272
274
print (u'{:<16}: {}' .format ('name' , category .name ))
273
275
print (u'{:<16}: {}' .format ('confidence' , category .confidence ))
274
- # [END def_classify_text ]
276
+ # [END language_classify_text ]
275
277
276
278
277
- # [START def_classify_file ]
279
+ # [START language_classify_gcs ]
278
280
def classify_file (gcs_uri ):
279
281
"""Classifies content categories of the text in a Google Cloud Storage
280
282
file.
@@ -291,7 +293,7 @@ def classify_file(gcs_uri):
291
293
print (u'=' * 20 )
292
294
print (u'{:<16}: {}' .format ('name' , category .name ))
293
295
print (u'{:<16}: {}' .format ('confidence' , category .confidence ))
294
- # [END def_classify_file ]
296
+ # [END language_classify_gcs ]
295
297
296
298
297
299
if __name__ == '__main__' :
0 commit comments