@@ -35,7 +35,7 @@ def sentiment_text(text):
35
35
36
36
# Detects sentiment in the document. You can also analyze HTML with:
37
37
# document.doc_type == language.Document.HTML
38
- sentiment = document .analyze_sentiment ()
38
+ sentiment = document .analyze_sentiment (). sentiment
39
39
40
40
print ('Score: {}' .format (sentiment .score ))
41
41
print ('Magnitude: {}' .format (sentiment .magnitude ))
@@ -50,7 +50,7 @@ def sentiment_file(gcs_uri):
50
50
51
51
# Detects sentiment in the document. You can also analyze HTML with:
52
52
# document.doc_type == language.Document.HTML
53
- sentiment = document .analyze_sentiment ()
53
+ sentiment = document .analyze_sentiment (). sentiment
54
54
55
55
print ('Score: {}' .format (sentiment .score ))
56
56
print ('Magnitude: {}' .format (sentiment .magnitude ))
@@ -65,15 +65,16 @@ def entities_text(text):
65
65
66
66
# Detects entities in the document. You can also analyze HTML with:
67
67
# document.doc_type == language.Document.HTML
68
- entities = document .analyze_entities ()
68
+ entities = document .analyze_entities (). entities
69
69
70
70
for entity in entities :
71
71
print ('=' * 20 )
72
72
print ('{:<16}: {}' .format ('name' , entity .name ))
73
73
print ('{:<16}: {}' .format ('type' , entity .entity_type ))
74
- print ('{:<16}: {}' .format ('wikipedia_url' , entity .wikipedia_url ))
75
74
print ('{:<16}: {}' .format ('metadata' , entity .metadata ))
76
75
print ('{:<16}: {}' .format ('salience' , entity .salience ))
76
+ print ('{:<16}: {}' .format ('wikipedia_url' ,
77
+ entity .metadata .get ('wikipedia_url' , '-' )))
77
78
78
79
79
80
def entities_file (gcs_uri ):
@@ -85,15 +86,16 @@ def entities_file(gcs_uri):
85
86
86
87
# Detects sentiment in the document. You can also analyze HTML with:
87
88
# document.doc_type == language.Document.HTML
88
- entities = document .analyze_entities ()
89
+ entities = document .analyze_entities (). entities
89
90
90
91
for entity in entities :
91
92
print ('=' * 20 )
92
93
print ('{:<16}: {}' .format ('name' , entity .name ))
93
94
print ('{:<16}: {}' .format ('type' , entity .entity_type ))
94
- print ('{:<16}: {}' .format ('wikipedia_url' , entity .wikipedia_url ))
95
95
print ('{:<16}: {}' .format ('metadata' , entity .metadata ))
96
96
print ('{:<16}: {}' .format ('salience' , entity .salience ))
97
+ print ('{:<16}: {}' .format ('wikipedia_url' ,
98
+ entity .metadata .get ('wikipedia_url' , '-' )))
97
99
98
100
99
101
def syntax_text (text ):
@@ -105,7 +107,7 @@ def syntax_text(text):
105
107
106
108
# Detects syntax in the document. You can also analyze HTML with:
107
109
# document.doc_type == language.Document.HTML
108
- tokens = document .analyze_syntax ()
110
+ tokens = document .analyze_syntax (). tokens
109
111
110
112
for token in tokens :
111
113
print ('{}: {}' .format (token .part_of_speech , token .text_content ))
@@ -120,7 +122,7 @@ def syntax_file(gcs_uri):
120
122
121
123
# Detects syntax in the document. You can also analyze HTML with:
122
124
# document.doc_type == language.Document.HTML
123
- tokens = document .analyze_syntax ()
125
+ tokens = document .analyze_syntax (). tokens
124
126
125
127
for token in tokens :
126
128
print ('{}: {}' .format (token .part_of_speech , token .text_content ))
0 commit comments