Skip to content

Commit 90916c0

Browse files
author
Steve Herschleb
committed
update comments
1 parent c9e3b04 commit 90916c0

1 file changed

Lines changed: 171 additions & 30 deletions

File tree

alchemyapi.py

Lines changed: 171 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ def setkey(key):
108108
Writes the API key to api_key.txt file. It will create the file if it doesn't exist.
109109
This function is intended to be called from the Python command line using: python -c 'import alchemyapi;alchemyapi.setkey("API_KEY");'
110110
If you don't have an API key yet, register for one at: http://www.alchemyapi.com/api/register.html
111+
112+
INPUT:
113+
key -> Your API key from AlchemyAPI. Should be 40 hex characters
114+
115+
OUTPUT:
116+
none
111117
"""
112118

113119
#write the key to the file
@@ -117,14 +123,22 @@ def setkey(key):
117123

118124

119125

120-
def sentiment(flavor, data, options={}):
126+
def sentiment(flavor, data, options={}):
121127
"""
122128
Calculates the sentiment for text, a URL or HTML.
123129
For an overview, please refer to: http://www.alchemyapi.com/products/features/sentiment-analysis/
124130
For the docs, please refer to: http://www.alchemyapi.com/api/sentiment-analysis/
125131
132+
INPUT:
133+
flavor -> which version of the call, i.e. text, url or html.
134+
data -> the data to analyze, either the text, the url or html code.
135+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
136+
126137
Available Options:
127-
showSourceText -> 0: disabled, 1: enabled
138+
showSourceText -> 0: disabled (default), 1: enabled
139+
140+
OUTPUT:
141+
The response, already converted from JSON to a Python object.
128142
"""
129143

130144
if API_KEY == '':
@@ -152,8 +166,17 @@ def sentiment_targeted(flavor, data, target, options={}):
152166
For an overview, please refer to: http://www.alchemyapi.com/products/features/sentiment-analysis/
153167
For the docs, please refer to: http://www.alchemyapi.com/api/sentiment-analysis/
154168
169+
INPUT:
170+
flavor -> which version of the call, i.e. text, url or html.
171+
data -> the data to analyze, either the text, the url or html code.
172+
target -> the word or phrase to run sentiment analysis on.
173+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
174+
155175
Available Options:
156176
showSourceText -> 0: disabled, 1: enabled
177+
178+
OUTPUT:
179+
The response, already converted from JSON to a Python object.
157180
"""
158181

159182
if API_KEY == '':
@@ -184,6 +207,17 @@ def author(flavor, data, options={}):
184207
Extracts the author from a URL or HTML.
185208
For an overview, please refer to: http://www.alchemyapi.com/products/features/author-extraction/
186209
For the docs, please refer to: http://www.alchemyapi.com/api/author-extraction/
210+
211+
INPUT:
212+
flavor -> which version of the call, i.e. text, url or html.
213+
data -> the data to analyze, either the text, the url or html code.
214+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
215+
216+
Availble Options:
217+
none
218+
219+
OUTPUT:
220+
The response, already converted from JSON to a Python object.
187221
"""
188222

189223
if API_KEY == '':
@@ -210,12 +244,20 @@ def keywords(flavor, data, options={}):
210244
Extracts the keywords from text, a URL or HTML.
211245
For an overview, please refer to: http://www.alchemyapi.com/products/features/keyword-extraction/
212246
For the docs, please refer to: http://www.alchemyapi.com/api/keyword-extraction/
247+
248+
INPUT:
249+
flavor -> which version of the call, i.e. text, url or html.
250+
data -> the data to analyze, either the text, the url or html code.
251+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
213252
214253
Available Options:
215-
keywordExtractMode
216-
sentiment
217-
showSourceText
218-
maxRetrieve
254+
keywordExtractMode -> normal (default), strict
255+
sentiment -> analyze sentiment for each keyword. 0: disabled (default), 1: enabled. Requires 1 additional API transaction if enabled.
256+
showSourceText -> 0: disabled (default), 1: enabled.
257+
maxRetrieve -> the max number of keywords returned (default: 50)
258+
259+
OUTPUT:
260+
The response, already converted from JSON to a Python object.
219261
"""
220262

221263
if API_KEY == '':
@@ -243,9 +285,12 @@ def concepts(flavor, data, options={}):
243285
For the docs, please refer to: http://www.alchemyapi.com/api/concept-tagging/
244286
245287
Available Options:
246-
maxRetrieve
247-
linkedData
248-
showSourceText
288+
maxRetrieve -> the maximum number of concepts to retrieve (default: 8)
289+
linkedData -> include linked data, 0: disabled, 1: enabled (default)
290+
showSourceText -> 0:disabled (default), 1: enabled
291+
292+
OUTPUT:
293+
The response, already converted from JSON to a Python object.
249294
"""
250295

251296
if API_KEY == '':
@@ -272,13 +317,22 @@ def entities(flavor, data, options={}):
272317
For an overview, please refer to: http://www.alchemyapi.com/products/features/entity-extraction/
273318
For the docs, please refer to: http://www.alchemyapi.com/api/entity-extraction/
274319
275-
disambiguate
276-
linkedData
277-
coreference
278-
quotations
279-
sentiment
280-
showSourceText
281-
maxRetrieve
320+
INPUT:
321+
flavor -> which version of the call, i.e. text, url or html.
322+
data -> the data to analyze, either the text, the url or html code.
323+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
324+
325+
Available Options:
326+
disambiguate -> disambiguate entities (i.e. Apple the company vs. apple the fruit). 0: disabled, 1: enabled (default)
327+
linkedData -> include linked data on disambiguated entities. 0: disabled, 1: enabled (default)
328+
coreference -> resolve coreferences (i.e. the pronouns that correspond to named entities). 0: disabled, 1: enabled (default)
329+
quotations -> extract quotations by entities. 0: disabled (default), 1: enabled.
330+
sentiment -> analyze sentiment for each entity. 0: disabled (default), 1: enabled. Requires 1 additional API transction if enabled.
331+
showSourceText -> 0: disabled (default), 1: enabled
332+
maxRetrieve -> the maximum number of entities to retrieve (default: 50)
333+
334+
OUTPUT:
335+
The response, already converted from JSON to a Python object.
282336
"""
283337

284338
if API_KEY == '':
@@ -305,8 +359,16 @@ def category(flavor, data, options={}):
305359
For an overview, please refer to: http://www.alchemyapi.com/products/features/text-categorization/
306360
For the docs, please refer to: http://www.alchemyapi.com/api/text-categorization/
307361
362+
INPUT:
363+
flavor -> which version of the call, i.e. text, url or html.
364+
data -> the data to analyze, either the text, the url or html code.
365+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
366+
308367
Available Options:
309-
showSourceText
368+
showSourceText -> 0: disabled (default), 1: enabled
369+
370+
OUTPUT:
371+
The response, already converted from JSON to a Python object.
310372
"""
311373

312374
if API_KEY == '':
@@ -333,17 +395,25 @@ def relations(flavor, data, options={}):
333395
For an overview, please refer to: http://www.alchemyapi.com/products/features/relation-extraction/
334396
For the docs, please refer to: http://www.alchemyapi.com/api/relation-extraction/
335397
398+
INPUT:
399+
flavor -> which version of the call, i.e. text, url or html.
400+
data -> the data to analyze, either the text, the url or html code.
401+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
402+
336403
Available Options:
337-
'&sentiment=0' +
338-
'&keywords=0' +
339-
'&entities=0' +
340-
'&requireEntities=0' +
341-
'&sentimentExcludeEntities=1' +
342-
'&disambiguate=1' +
343-
'&linkedData=1' +
344-
'&coreference=1' +
345-
'&showSourceText=0' +
346-
'&maxRetrieve=50')
404+
sentiment -> 0: disabled (default), 1: enabled. Requires one additional API transaction if enabled.
405+
keywords -> extract keywords from the subject and object. 0: disabled (default), 1: enabled. Requires one additional API transaction if enabled.
406+
entities -> extract entities from the subject and object. 0: disabled (default), 1: enabled. Requires one additional API transaction if enabled.
407+
requireEntities -> only extract relations that have entities. 0: disabled (default), 1: enabled.
408+
sentimentExcludeEntities -> exclude full entity name in sentiment analysis. 0: disabled, 1: enabled (default)
409+
disambiguate -> disambiguate entities (i.e. Apple the company vs. apple the fruit). 0: disabled, 1: enabled (default)
410+
linkedData -> include linked data with disambiguated entities. 0: disabled, 1: enabled (default).
411+
coreference -> resolve entity coreferences. 0: disabled, 1: enabled (default)
412+
showSourceText -> 0: disabled (default), 1: enabled.
413+
maxRetrieve -> the maximum number of relations to extract (default: 50, max: 100)
414+
415+
OUTPUT:
416+
The response, already converted from JSON to a Python object.
347417
"""
348418

349419
if API_KEY == '':
@@ -369,6 +439,17 @@ def language(flavor, data, options={}):
369439
Detects the language for text, a URL or HTML.
370440
For an overview, please refer to: http://www.alchemyapi.com/api/language-detection/
371441
For the docs, please refer to: http://www.alchemyapi.com/products/features/language-detection/
442+
443+
INPUT:
444+
flavor -> which version of the call, i.e. text, url or html.
445+
data -> the data to analyze, either the text, the url or html code.
446+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
447+
448+
Available Options:
449+
none
450+
451+
OUTPUT:
452+
The response, already converted from JSON to a Python object.
372453
"""
373454

374455
if API_KEY == '':
@@ -395,9 +476,17 @@ def text_clean(flavor, data, options={}):
395476
For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/
396477
For the docs, please refer to: http://www.alchemyapi.com/api/text-extraction/
397478
479+
INPUT:
480+
flavor -> which version of the call, i.e. text, url or html.
481+
data -> the data to analyze, either the text, the url or html code.
482+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
483+
398484
Available Options:
399-
'&useMetadata=1' +
400-
'&extractLinks=0')
485+
useMetadata -> utilize meta description data, 0: disabled, 1: enabled (default)
486+
extractLinks -> include links, 0: disabled (default), 1: enabled.
487+
488+
OUTPUT:
489+
The response, already converted from JSON to a Python object.
401490
"""
402491

403492
if API_KEY == '':
@@ -423,6 +512,17 @@ def text_raw(flavor, data, options={}):
423512
Extracts the raw text (includes ads, navigation, etc.) for a URL or HTML.
424513
For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/
425514
For the docs, please refer to: http://www.alchemyapi.com/api/text-extraction/
515+
516+
INPUT:
517+
flavor -> which version of the call, i.e. text, url or html.
518+
data -> the data to analyze, either the text, the url or html code.
519+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
520+
521+
Available Options:
522+
none
523+
524+
OUTPUT:
525+
The response, already converted from JSON to a Python object.
426526
"""
427527

428528
if API_KEY == '':
@@ -450,8 +550,16 @@ def text_title(flavor, data, options={}):
450550
For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/
451551
For the docs, please refer to: http://www.alchemyapi.com/api/text-extraction/
452552
553+
INPUT:
554+
flavor -> which version of the call, i.e. text, url or html.
555+
data -> the data to analyze, either the text, the url or html code.
556+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
557+
453558
Available Options:
454-
'&useMetadata=1')
559+
useMetadata -> utilize title info embedded in meta data, 0: disabled, 1: enabled (default)
560+
561+
OUTPUT:
562+
The response, already converted from JSON to a Python object.
455563
"""
456564

457565
if API_KEY == '':
@@ -478,6 +586,17 @@ def microformats(flavor, data, options={}):
478586
Parses the microformats for a URL or HTML.
479587
For an overview, please refer to: http://www.alchemyapi.com/products/features/microformats-parsing/
480588
For the docs, please refer to: http://www.alchemyapi.com/api/microformats-parsing/
589+
590+
INPUT:
591+
flavor -> which version of the call, i.e. url or html.
592+
data -> the data to analyze, either the the url or html code.
593+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
594+
595+
Available Options:
596+
none
597+
598+
OUTPUT:
599+
The response, already converted from JSON to a Python object.
481600
"""
482601

483602
if API_KEY == '':
@@ -504,6 +623,17 @@ def feeds(flavor, data, options={}):
504623
Detects the RSS/ATOM feeds for a URL or HTML.
505624
For an overview, please refer to: http://www.alchemyapi.com/products/features/feed-detection/
506625
For the docs, please refer to: http://www.alchemyapi.com/api/feed-detection/
626+
627+
INPUT:
628+
flavor -> which version of the call, i.e. url or html.
629+
data -> the data to analyze, either the the url or html code.
630+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
631+
632+
Available Options:
633+
none
634+
635+
OUTPUT:
636+
The response, already converted from JSON to a Python object.
507637
"""
508638

509639
if API_KEY == '':
@@ -526,6 +656,17 @@ def feeds(flavor, data, options={}):
526656

527657

528658
def analyze(url):
659+
"""
660+
HTTP Request wrapper that is called by the endpoint functions. This function is not intended to be called through an external interface.
661+
It makes the call, then converts the returned JSON string into a Python object.
662+
663+
INPUT:
664+
url -> the full URI encoded url
665+
666+
OUTPUT:
667+
The response, already converted from JSON to a Python object.
668+
"""
669+
529670
try:
530671
#build the request with uri encoding
531672
req = urllib2.Request(url)

0 commit comments

Comments
 (0)