import requests
import json


def annotateText(text, token, content_type = 'text/plain'):
	"""
	Given the text to be analyzed and a previous generated access token this method returns the result of a Watson API call to `annotate_text`.
	This method forms the core of this library's functionality.
	This method accepts one optional parameter: `content_type`. This defaults to `text/plain`, which expects plaintext input.
	`text/html` is the alternative option.
	NOTE: This is a raw method that returns the raw, unprocessed result of an API call. All processing afterwards is handled by `backend.py`.
	"""
	base_url='https://gateway.watsonplatform.net/concept-insights/api/v2/graphs/wikipedia/en-20120601/annotate_text'
	headers = {'X-Watson-Authorization-Token': token, 'Content-Type': content_type, 'Accept': 'application/json'}
	dat = text.encode(encoding='UTF-8', errors='ignore')
	r = requests.post(base_url, headers=headers, data=dat)
	return json.loads(r.text)