-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathexample.php
309 lines (243 loc) · 11.1 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
$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.';
$demo_url = 'http://blog.programmableweb.com/2011/09/16/new-api-billionaire-text-extractor-alchemy/';
$demo_html = '<html><head><title>Python Demo | AlchemyAPI</title></head><body><h1>Did you know that AlchemyAPI works on HTML?</h1><p>Well, you do now.</p></body></html>';
echo PHP_EOL;
echo PHP_EOL;
echo ' , ', PHP_EOL;
echo ' .I7777~ ', PHP_EOL;
echo ' .I7777777 ', PHP_EOL;
echo ' +. 77777777 ', PHP_EOL;
echo ' =???, I7777777= ', PHP_EOL;
echo '=?????? 7777777? ,:::===? ', PHP_EOL;
echo '=???????. 777777777777777777~ .77: ?? :7 =$, :$$$$$$+ =$? ', PHP_EOL;
echo ' ????????: .777777777777777777 II77 ?? :7 $$7 :$? 7$7 =$? ', PHP_EOL;
echo ' .???????= +7777777777777777 .7 =7: ?? :7777+ :7:I777? ?777I= 77~777? ,777I I7 77 +$?$: :$? $$ =$? ', PHP_EOL;
echo ' ???????+ ~777???+===::: :7+ ~7 ?? .77 +7 :7?. II 7~ ,I7 77+ I77 ~7 ?7 =7: .$, =$ :$? ,$$? =$? ', PHP_EOL;
echo ' ,???????~ 77 7: ?? ?I. 7 :7 :7 ~7 7 77 =7: 7 7 7~ 7$ $= :$$$$$$~ =$? ', PHP_EOL;
echo ' .??????? ,???I77777777777~ :77777777~ ?? 7: :7 :7 777777777:77 =7 7 +7 ~7 $$$$$$$$I :$? =$? ', PHP_EOL;
echo ' .??????? ,7777777777777777 7= 77 ?? I+ 7 :7 :7 ?? 7,77 =7 7 7~ 7, =$7 $$, :$? =$? ', PHP_EOL;
echo ' .???????. I77777777777777777 +7 ,7??? 77 I7 :7 :7 7~ .?7 77 =7 7 ,77I $+ 7$ :$? =$? ', PHP_EOL;
echo ' ,???????= :77777777777777777~ 7= ~7?? ~I77777 :7 :7 ,777777. 77 =7 7 77, +$ .$::$? =$? ', PHP_EOL;
echo ',??????? :7777777 77 ', PHP_EOL;
echo ' =????? ,7777777 77= ', PHP_EOL;
echo ' +?+ 7777777? ', PHP_EOL;
echo ' + ~7777777 ', PHP_EOL;
echo ' I777777 ', PHP_EOL;
echo ' :~ ', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Entity Extraction Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->entities('text',$demo_text, array('sentiment'=>1));
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Entities ##', PHP_EOL;
foreach ($response['entities'] as $entity) {
echo 'text: ', $entity['text'], PHP_EOL;
echo 'type: ', $entity['type'], PHP_EOL;
echo 'relevance: ', $entity['relevance'], PHP_EOL;
echo 'sentiment: ', $entity['sentiment']['type'], ' (' . $entity['sentiment']['score'] . ')', PHP_EOL;
echo PHP_EOL;
}
} else {
echo 'Error in the entity extraction call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Sentiment Analysis Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing HTML: ', $demo_html, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->sentiment('html',$demo_html, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Document Sentiment ##', PHP_EOL;
echo 'type: ', $response['docSentiment']['type'], PHP_EOL;
echo 'score: ', $response['docSentiment']['score'], PHP_EOL;
} else {
echo 'Error in the sentiment analysis call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Keyword Extraction Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->keywords('text',$demo_text, array('sentiment'=>1));
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Keywords ##', PHP_EOL;
foreach ($response['keywords'] as $keyword) {
echo 'text: ', $keyword['text'], PHP_EOL;
echo 'relevance: ', $keyword['relevance'], PHP_EOL;
echo 'sentiment: ', $keyword['sentiment']['type'], ' (' . $keyword['sentiment']['score'] . ')', PHP_EOL;
echo PHP_EOL;
}
} else {
echo 'Error in the keyword extraction call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Concept Tagging Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->concepts('text',$demo_text, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Concepts ##', PHP_EOL;
foreach ($response['concepts'] as $concept) {
echo 'text: ', $concept['text'], PHP_EOL;
echo 'relevance: ', $concept['relevance'], PHP_EOL;
echo PHP_EOL;
}
} else {
echo 'Error in the concept tagging call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Relation Extraction Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->relations('text',$demo_text, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Relations ##', PHP_EOL;
foreach ($response['relations'] as $relation) {
if (array_key_exists('subject', $relation)) {
echo 'Subject: ', $relation['subject']['text'], PHP_EOL;
}
if (array_key_exists('action', $relation)) {
echo 'Action: ', $relation['action']['text'], PHP_EOL;
}
if (array_key_exists('object', $relation)) {
echo 'Object: ', $relation['object']['text'], PHP_EOL;
}
echo PHP_EOL;
}
} else {
echo 'Error in the relation extraction call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Text Categorization Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->category('text',$demo_text, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Category ##', PHP_EOL;
echo 'text: ', $response['category'], PHP_EOL;
echo 'score: ', $response['score'], PHP_EOL;
} else {
echo 'Error in the text categorization call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Language Detection Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->language('text',$demo_text, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Language ##', PHP_EOL;
echo 'language: ', $response['language'], PHP_EOL;
echo 'iso-639-1: ', $response['iso-639-1'], PHP_EOL;
echo 'native speakers: ', $response['native-speakers'], PHP_EOL;
} else {
echo 'Error in the language detection call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Author Extraction Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing url: ', $demo_url, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->author('url',$demo_url, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Author ##', PHP_EOL;
echo 'author: ', $response['author'], PHP_EOL;
} else {
echo 'Error in the author extraction call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '# Feed Dection Example #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing url: ', $demo_url, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->feeds('url',$demo_url, null);
if ($response['status'] == 'OK') {
echo '## Response Object ##', PHP_EOL;
echo print_r($response);
echo PHP_EOL;
echo '## Feeds ##', PHP_EOL;
foreach ($response['feeds'] as $feed) {
echo 'feed: ', $feed['feed'], PHP_EOL;
}
} else {
echo 'Error in the feed detection call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
?>