diff --git a/alchemyapi.py b/alchemyapi.py index 34ded5b..b01cfde 100644 --- a/alchemyapi.py +++ b/alchemyapi.py @@ -125,7 +125,7 @@ class AlchemyAPI: ENDPOINTS['imagetagging']['image'] = '/image/ImageGetRankedImageKeywords' ENDPOINTS['facetagging'] = {} ENDPOINTS['facetagging']['url'] = '/url/URLGetRankedImageFaceTags' - ENDPOINTS['facetagging']['image'] = '/image/ImageGetRankedImageFaceTags' + ENDPOINTS['facetagging']['image'] = '/image/ImageGetRankedImageFaceTags' ENDPOINTS['taxonomy'] = {} ENDPOINTS['taxonomy']['url'] = '/url/URLGetRankedTaxonomy' ENDPOINTS['taxonomy']['html'] = '/html/HTMLGetRankedTaxonomy' @@ -136,8 +136,8 @@ class AlchemyAPI: s = requests.Session() - def __init__(self): - """ + def __init__(self, key): + """ Initializes the SDK so it can send requests to AlchemyAPI for analysis. It loads the API key from api_key.txt and configures the endpoints. """ @@ -145,8 +145,8 @@ def __init__(self): import sys try: # Open the key file and read the key - f = open("api_key.txt", "r") - key = f.read().strip() + #f = open("api_key.txt", "r") + #key = f.read().strip() if key == '': # The key file should't be blank @@ -182,7 +182,7 @@ def __init__(self): def entities(self, flavor, data, options={}): """ Extracts the entities for text, a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/products/features/entity-extraction/ + For an overview, please refer to: http://www.alchemyapi.com/products/features/entity-extraction/ For the docs, please refer to: http://www.alchemyapi.com/api/entity-extraction/ INPUT: @@ -192,15 +192,15 @@ def entities(self, flavor, data, options={}): Available Options: disambiguate -> disambiguate entities (i.e. Apple the company vs. apple the fruit). 0: disabled, 1: enabled (default) - linkedData -> include linked data on disambiguated entities. 0: disabled, 1: enabled (default) + linkedData -> include linked data on disambiguated entities. 0: disabled, 1: enabled (default) coreference -> resolve coreferences (i.e. the pronouns that correspond to named entities). 0: disabled, 1: enabled (default) quotations -> extract quotations by entities. 0: disabled (default), 1: enabled. sentiment -> analyze sentiment for each entity. 0: disabled (default), 1: enabled. Requires 1 additional API transction if enabled. - showSourceText -> 0: disabled (default), 1: enabled + showSourceText -> 0: disabled (default), 1: enabled maxRetrieve -> the maximum number of entities to retrieve (default: 50) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -229,7 +229,7 @@ def keywords(self, flavor, data, options={}): maxRetrieve -> the max number of keywords returned (default: 50) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -244,7 +244,7 @@ def concepts(self, flavor, data, options={}): """ Tags the concepts for text, a URL or HTML. For an overview, please refer to: http://www.alchemyapi.com/products/features/concept-tagging/ - For the docs, please refer to: http://www.alchemyapi.com/api/concept-tagging/ + For the docs, please refer to: http://www.alchemyapi.com/api/concept-tagging/ Available Options: maxRetrieve -> the maximum number of concepts to retrieve (default: 8) @@ -252,7 +252,7 @@ def concepts(self, flavor, data, options={}): showSourceText -> 0:disabled (default), 1: enabled OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -278,7 +278,7 @@ def sentiment(self, flavor, data, options={}): showSourceText -> 0: disabled (default), 1: enabled OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -305,7 +305,7 @@ def sentiment_targeted(self, flavor, data, target, options={}): showSourceText -> 0: disabled, 1: enabled OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure the target is valid @@ -337,7 +337,7 @@ def text(self, flavor, data, options={}): extractLinks -> include links, 0: disabled (default), 1: enabled. OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -351,7 +351,7 @@ def text(self, flavor, data, options={}): def text_raw(self, flavor, data, options={}): """ Extracts the raw text (includes ads, navigation, etc.) for a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/ + For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/ For the docs, please refer to: http://www.alchemyapi.com/api/text-extraction/ INPUT: @@ -363,7 +363,7 @@ def text_raw(self, flavor, data, options={}): none OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -389,7 +389,7 @@ def author(self, flavor, data, options={}): none OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -403,7 +403,7 @@ def author(self, flavor, data, options={}): def language(self, flavor, data, options={}): """ Detects the language for text, a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/api/language-detection/ + For an overview, please refer to: http://www.alchemyapi.com/api/language-detection/ For the docs, please refer to: http://www.alchemyapi.com/products/features/language-detection/ INPUT: @@ -415,7 +415,7 @@ def language(self, flavor, data, options={}): none OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -429,7 +429,7 @@ def language(self, flavor, data, options={}): def title(self, flavor, data, options={}): """ Extracts the title for a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/ + For an overview, please refer to: http://www.alchemyapi.com/products/features/text-extraction/ For the docs, please refer to: http://www.alchemyapi.com/api/text-extraction/ INPUT: @@ -438,10 +438,10 @@ def title(self, flavor, data, options={}): options -> various parameters that can be used to adjust how the API works, see below for more info on the available options. Available Options: - useMetadata -> utilize title info embedded in meta data, 0: disabled, 1: enabled (default) + useMetadata -> utilize title info embedded in meta data, 0: disabled, 1: enabled (default) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -455,7 +455,7 @@ def title(self, flavor, data, options={}): def relations(self, flavor, data, options={}): """ Extracts the relations for text, a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/products/features/relation-extraction/ + For an overview, please refer to: http://www.alchemyapi.com/products/features/relation-extraction/ For the docs, please refer to: http://www.alchemyapi.com/api/relation-extraction/ INPUT: @@ -471,12 +471,12 @@ def relations(self, flavor, data, options={}): sentimentExcludeEntities -> exclude full entity name in sentiment analysis. 0: disabled, 1: enabled (default) disambiguate -> disambiguate entities (i.e. Apple the company vs. apple the fruit). 0: disabled, 1: enabled (default) linkedData -> include linked data with disambiguated entities. 0: disabled, 1: enabled (default). - coreference -> resolve entity coreferences. 0: disabled, 1: enabled (default) + coreference -> resolve entity coreferences. 0: disabled, 1: enabled (default) showSourceText -> 0: disabled (default), 1: enabled. maxRetrieve -> the maximum number of relations to extract (default: 50, max: 100) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -502,7 +502,7 @@ def category(self, flavor, data, options={}): showSourceText -> 0: disabled (default), 1: enabled OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -517,7 +517,7 @@ def category(self, flavor, data, options={}): def feeds(self, flavor, data, options={}): """ Detects the RSS/ATOM feeds for a URL or HTML. - For an overview, please refer to: http://www.alchemyapi.com/products/features/feed-detection/ + For an overview, please refer to: http://www.alchemyapi.com/products/features/feed-detection/ For the docs, please refer to: http://www.alchemyapi.com/api/feed-detection/ INPUT: @@ -529,7 +529,7 @@ def feeds(self, flavor, data, options={}): none OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -555,7 +555,7 @@ def microformats(self, flavor, data, options={}): none OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Make sure this request supports this flavor @@ -573,15 +573,15 @@ def imageExtraction(self, flavor, data, options={}): INPUT: flavor -> which version of the call (url only currently). data -> URL to analyze - options -> various parameters that can be used to adjust how the API works, + options -> various parameters that can be used to adjust how the API works, see below for more info on the available options. Available Options: - extractMode -> + extractMode -> trust-metadata : (less CPU intensive, less accurate) always-infer : (more CPU intensive, more accurate) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ if flavor not in AlchemyAPI.ENDPOINTS['image']: return {'status': 'ERROR', 'statusInfo': 'image extraction for ' + flavor + ' not available'} @@ -599,26 +599,26 @@ def taxonomy(self, flavor, data, options={}): Available Options: - showSourceText -> + showSourceText -> include the original 'source text' the taxonomy categories were extracted from within the API response Possible values: 1 - enabled - 0 - disabled (default) + 0 - disabled (default) sourceText -> where to obtain the text that will be processed by this API call. AlchemyAPI supports multiple modes of text extraction: - web page cleaning (removes ads, navigation links, etc.), raw text extraction - (processes all web page text, including ads / nav links), visual constraint queries, and XPath queries. + web page cleaning (removes ads, navigation links, etc.), raw text extraction + (processes all web page text, including ads / nav links), visual constraint queries, and XPath queries. Possible values: cleaned_or_raw : cleaning enabled, fallback to raw when cleaning produces no text (default) cleaned : operate on 'cleaned' web page text (web page cleaning enabled) raw : operate on raw web page text (web page cleaning disabled) - cquery : operate on the results of a visual constraints query + cquery : operate on the results of a visual constraints query Note: The 'cquery' http argument must also be set to a valid visual constraints query. - xpath : operate on the results of an XPath query + xpath : operate on the results of an XPath query Note: The 'xpath' http argument must also be set to a valid XPath query. cquery -> @@ -631,7 +631,7 @@ def taxonomy(self, flavor, data, options={}): rel-tag output base http url (must be uri-argument encoded) OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ if flavor not in AlchemyAPI.ENDPOINTS['taxonomy']: @@ -649,11 +649,11 @@ def combined(self, flavor, data, options={}): options -> various parameters that can be used to adjust how the API works, see below for more info on the available options. Available Options: - extract -> + extract -> Possible values: page-image, entity, keyword, title, author, taxonomy, concept default : entity, keyword, taxonomy, concept - disambiguate -> + disambiguate -> disambiguate detected entities Possible values: 1 : enabled (default) @@ -671,7 +671,7 @@ def combined(self, flavor, data, options={}): 1 : enabled (default) 0 : disabled - quotations -> + quotations -> enable quotations extraction Possible values: 1 : enabled @@ -683,7 +683,7 @@ def combined(self, flavor, data, options={}): 1 : enabled 0 : disabled (default) - showSourceText -> + showSourceText -> include the original 'source text' the entities were extracted from within the API response Possible values: 1 : enabled @@ -693,12 +693,12 @@ def combined(self, flavor, data, options={}): maximum number of named entities to extract default : 50 - baseUrl -> + baseUrl -> rel-tag output base http url OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ if flavor not in AlchemyAPI.ENDPOINTS['combined']: return {'status': 'ERROR', 'statusInfo': 'combined for ' + flavor + ' not available'} @@ -743,14 +743,14 @@ def faceTagging(self, flavor, data, options={}): def __analyze(self, endpoint, params, post_data=bytearray()): """ - HTTP Request wrapper that is called by the endpoint functions. This function is not intended to be called through an external interface. - It makes the call, then converts the returned JSON string into a Python object. + HTTP Request wrapper that is called by the endpoint functions. This function is not intended to be called through an external interface. + It makes the call, then converts the returned JSON string into a Python object. INPUT: url -> the full URI encoded url OUTPUT: - The response, already converted from JSON to a Python object. + The response, already converted from JSON to a Python object. """ # Add the API Key and set the output mode to JSON diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b9f9f09 --- /dev/null +++ b/setup.py @@ -0,0 +1,8 @@ +from distutils.core import setup + +setup(name='AlchemyAPI', + version='1.1', + description='AlchemyAPI Python bindings', + author='AlchemyAPI', + url='https://github.com/AlchemyAPI/alchemyapi_python', + py_modules=['alchemyapi'])