Example

Example

"""
Description: SpellChecker API usage example.
Copyright: (C) 2016 EffectiveSoft Ltd. All Rights Reserved.
Technical support: technical-support@effective-soft.com
"""

import json
import urllib
import urllib2

# sample text
sample_text = "EuropeanUnion leaders need to be bolder in how they tackle the eurozone crisis, reduce budget deficets and encourage growt, Prime Minister David Cameron said today."

# set the URL with parameters for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
api_url = "http://api.intellexer.com/checkTextSpelling?apikey=YourAPIKey&language=ENGLISH&errorTune=2&errorBound=3&minProbabilityTune=2&minProbabilityWeight=30"

# print response results
def print_response(response):
	# print source and processed sentences
	src_sentences = response.get('sourceSentences')
	proc_sentences = response.get('processedSentences')
	size = len(src_sentences)
	for i in range(0, size):
		print "Source:\t", src_sentences[i]
		print "Corrected:\t", proc_sentences[i]
	# print list of corrections
	print "\nList of corrections:"
	corrections = response.get('corrections')
	for corr in corrections:
		print "\t", corr.get('v')[0].get('t')

# create request to the SpellChecker API service
def request_api(url, text):
	header = { 'Content-Type' : "application/octet-stream" }
	req = urllib2.Request(url, text, header)
	conn = urllib2.urlopen(req)
	try:
		json_response = json.loads(conn.read())
	finally:
		conn.close()
	print_response(json_response)

# perform the request
try:
	request_api(api_url, sample_text)
except urllib2.HTTPError as error:
	print 'HTTP error - %s' % error.read()

Output

Source:	EuropeanUnion leaders need to be bolder in how they tackle the eurozone crisis , reduce budget deficets and encourage growt , Prime Minister David Cameron said today . 
Corrected:	European Union leaders need to be bolder in how they tackle the eurozone crisis, reduce budget deficits and encourage growth, Prime Minister David Cameron said today.

List of corrections:
	European Union
	deficits
	growth