|
1 | 1 | import alchemyapi |
| 2 | +import json |
2 | 3 |
|
3 | 4 | demo_text = 'Yesterday dumb Bob destroyed my fancy iPhone in beautiful Denver, Colorado. I guess I will have to head over to the Apple Store and buy a new one.' |
4 | 5 | demo_url = 'http://blog.programmableweb.com/2011/09/16/new-api-billionaire-text-extractor-alchemy/' |
|
41 | 42 | print 'Processing text: ', demo_text |
42 | 43 | print '' |
43 | 44 |
|
44 | | -response = alchemyapi.entities('text',demo_text) |
| 45 | +response = alchemyapi.entities('text',demo_text, { 'sentiment':1 }) |
45 | 46 |
|
46 | 47 | if response['status'] == 'OK': |
47 | 48 | print '## Response Object ##' |
48 | | - print response |
| 49 | + print json.dumps(response, indent=4) |
49 | 50 |
|
50 | 51 |
|
51 | 52 | print '' |
|
54 | 55 | print 'text: ', entity['text'] |
55 | 56 | print 'type: ', entity['type'] |
56 | 57 | print 'relevance: ', entity['relevance'] |
| 58 | + print 'sentiment: ', entity['sentiment']['type'] + ' (' + entity['sentiment']['score'] + ')' |
57 | 59 | print '' |
58 | 60 | else: |
59 | 61 | print 'Error in entity extraction call: ', response['statusInfo'] |
|
76 | 78 |
|
77 | 79 | if response['status'] == 'OK': |
78 | 80 | print '## Response Object ##' |
79 | | - print response |
| 81 | + print json.dumps(response, indent=4) |
80 | 82 |
|
81 | 83 | print '' |
82 | 84 | print '## Document Sentiment ##' |
|
103 | 105 |
|
104 | 106 | if response['status'] == 'OK': |
105 | 107 | print '## Response Object ##' |
106 | | - print response |
| 108 | + print json.dumps(response, indent=4) |
107 | 109 |
|
108 | 110 |
|
109 | 111 | print '' |
110 | 112 | print '## Keywords ##' |
111 | 113 | for keyword in response['keywords']: |
112 | 114 | print 'text: ', keyword['text'] |
113 | 115 | print 'relevance: ', keyword['relevance'] |
| 116 | + print 'sentiment: ', keyword['sentiment']['type'] + ' (' + keyword['sentiment']['score'] + ')' |
114 | 117 | print '' |
115 | 118 | else: |
116 | 119 | print 'Error in keyword extaction call: ', response['statusInfo'] |
|
133 | 136 |
|
134 | 137 | if response['status'] == 'OK': |
135 | 138 | print '## Object ##' |
136 | | - print response |
| 139 | + print json.dumps(response, indent=4) |
137 | 140 |
|
138 | 141 |
|
139 | 142 | print '' |
|
163 | 166 |
|
164 | 167 | if response['status'] == 'OK': |
165 | 168 | print "## Object ##" |
166 | | - print response |
| 169 | + print json.dumps(response, indent=4) |
167 | 170 |
|
168 | 171 |
|
169 | 172 | print '' |
|
200 | 203 |
|
201 | 204 | if response['status'] == 'OK': |
202 | 205 | print '## Response Object ##' |
203 | | - print response |
| 206 | + print json.dumps(response, indent=4) |
204 | 207 |
|
205 | 208 |
|
206 | 209 | print '' |
|
229 | 232 |
|
230 | 233 | if response['status'] == 'OK': |
231 | 234 | print '## Response Object ##' |
232 | | - print response |
| 235 | + print json.dumps(response, indent=4) |
233 | 236 |
|
234 | 237 |
|
235 | 238 | print '' |
|
259 | 262 |
|
260 | 263 | if response['status'] == 'OK': |
261 | 264 | print '## Response Object ##' |
262 | | - print response |
| 265 | + print json.dumps(response, indent=4) |
263 | 266 |
|
264 | 267 | print '' |
265 | 268 | print '## Author ##' |
|
286 | 289 |
|
287 | 290 | if response['status'] == 'OK': |
288 | 291 | print '## Response Object ##' |
289 | | - print response |
| 292 | + print json.dumps(response, indent=4) |
290 | 293 |
|
291 | 294 | print '' |
292 | 295 | print '## Feeds ##' |
|
0 commit comments