This repository was archived by the owner on Sep 5, 2023. It is now read-only.
File tree 1 file changed +5
-8
lines changed
samples/snippets/classify_text
1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change 27
27
import json
28
28
import os
29
29
30
- from google .cloud import language_v1beta2
31
- from google .cloud .language_v1beta2 import enums
32
- from google .cloud .language_v1beta2 import types
33
-
30
+ from google .cloud import language
34
31
import numpy
35
32
import six
36
33
# [END classify_text_tutorial_import]
40
37
def classify (text , verbose = True ):
41
38
"""Classify the input text into categories. """
42
39
43
- language_client = language_v1beta2 .LanguageServiceClient ()
40
+ language_client = language .LanguageServiceClient ()
44
41
45
- document = types .Document (
42
+ document = language . types .Document (
46
43
content = text ,
47
- type = enums .Document .Type .PLAIN_TEXT )
44
+ type = language . enums .Document .Type .PLAIN_TEXT )
48
45
response = language_client .classify_text (document )
49
46
categories = response .categories
50
47
@@ -90,7 +87,7 @@ def index(path, index_file):
90
87
print ('Failed to process {}' .format (file_path ))
91
88
92
89
with io .open (index_file , 'w' , encoding = 'utf-8' ) as f :
93
- f .write (json .dumps (result ))
90
+ f .write (json .dumps (result , ensure_ascii = False ))
94
91
95
92
print ('Texts indexed in file: {}' .format (index_file ))
96
93
return result
You can’t perform that action at this time.
0 commit comments