22
22
"""
23
23
24
24
import argparse
25
+ import sys
25
26
26
27
from google .cloud import language
27
28
from google .cloud .gapic .language .v1beta2 import enums
@@ -53,7 +54,7 @@ def sentiment_file(gcs_uri):
53
54
language_client = language .Client (api_version = 'v1beta2' )
54
55
55
56
# Instantiates a plain text document.
56
- document = language_client .document_from_url (gcs_uri )
57
+ document = language_client .document_from_gcs_url (gcs_uri )
57
58
58
59
# Detects sentiment in the document. You can also analyze HTML with:
59
60
# document.doc_type == language.Document.HTML
@@ -92,7 +93,7 @@ def entities_file(gcs_uri):
92
93
language_client = language .Client (api_version = 'v1beta2' )
93
94
94
95
# Instantiates a plain text document.
95
- document = language_client .document_from_url (gcs_uri )
96
+ document = language_client .document_from_gcs_url (gcs_uri )
96
97
97
98
# Detects sentiment in the document. You can also analyze HTML with:
98
99
# document.doc_type == language.Document.HTML
@@ -131,7 +132,7 @@ def syntax_file(gcs_uri):
131
132
language_client = language .Client (api_version = 'v1beta2' )
132
133
133
134
# Instantiates a plain text document.
134
- document = language_client .document_from_url (gcs_uri )
135
+ document = language_client .document_from_gcs_url (gcs_uri )
135
136
136
137
# Detects syntax in the document. You can also analyze HTML with:
137
138
# document.doc_type == language.Document.HTML
@@ -152,8 +153,12 @@ def entity_sentiment_text(text):
152
153
document .content = text .encode ('utf-8' )
153
154
document .type = enums .Document .Type .PLAIN_TEXT
154
155
156
+ encoding = enums .EncodingType .UTF32
157
+ if sys .maxunicode == 65535 :
158
+ encoding = enums .EncodingType .UTF16
159
+
155
160
result = language_client .analyze_entity_sentiment (
156
- document , enums . EncodingType . UTF8 )
161
+ document , encoding )
157
162
158
163
for entity in result .entities :
159
164
print ('Mentions: ' )
@@ -176,8 +181,12 @@ def entity_sentiment_file(gcs_uri):
176
181
document .gcs_content_uri = gcs_uri
177
182
document .type = enums .Document .Type .PLAIN_TEXT
178
183
184
+ encoding = enums .EncodingType .UTF32
185
+ if sys .maxunicode == 65535 :
186
+ encoding = enums .EncodingType .UTF16
187
+
179
188
result = language_client .analyze_entity_sentiment (
180
- document , enums . EncodingType . UTF8 )
189
+ document , encoding )
181
190
182
191
for entity in result .entities :
183
192
print (u'Name: "{}"' .format (entity .name ))
0 commit comments