Example

Example

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

import json
import urllib
import urllib2


# set the URL for GET request, specify the url for information extraction and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
api_url = "http://api.intellexer.com/parse?apikey=YourAPIKey&url=http://www.infoplease.com/biography/var/barackobama.html&useCache=false"

# print response results
def print_response(response):
	print "Document structure: ",  response.get('structure')
	topics = response.get('topics')
	print "Document topics: "
	for topic in topics:
		print "\t", topic
	print "Document language: ", response.get('lang')
	print "Document plain text:\n", response.get('text').encode('utf-8')

# create request to the Preformator API service
def request_api(url):
	req = urllib2.Request(url, None)
	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)
except urllib2.HTTPError as error:
	print 'HTTP error - %s' % error.read()

Output

Document structure:  NewsArticle
Document topics: 
	Social.politics
Document language:  English
Document plain text:
  InfoPlease
World  World
U.S.  U.S.
People  People
History & Gov't  History & Gov't
Science & Health  Science & Health
Calendar & Holidays  Calendar & Holidays
Business  Business
     |   Share  |  Cite
Barack Obama
U.S. President
Born:  4 August 1961
Birthplace:  Honolulu, Hawaii
Best known as:  President of the United States, 2009-present
Name at birth: Barack Hussein Obama II
Barack Obama is the 44th president of the United States and the first African-American president in American history. Barack Obama has spoken often of his multicultural background: his father was from Kenya, his mother from Kansas, and they met at the University of Hawaii. After his parents divorced and his father returned to Africa, Obama stayed with his mother and was raised in Indonesia and Hawaii. He earned an undergraduate degree from Columbia University in 1983 and a law degree from Harvard in 1991. He then joined the Chicago law firm of Miner, Barnhill & Galland, which specialized in civil rights legislation. He also taught constitutional law for 12 years at the University of Chicago. Barack Obama was elected to the Illinois Senate in 1996, and then to the U.S. Senate in 2004, beating Republican candidate Alan Keyes .
Barack Obama shot to national fame after delivering a stirring keynote speech in support of John Kerry  at the 2004 Democratic national convention. Obama ran for president in 2008, defeating a Democratic primary field that included New York Sen. Hillary Clinton , the former First Lady. He named Delaware senator Joe Biden  to be his running mate at the Democratic Convention that August, and they defeated Republican nominees John McCain  and Sarah Palin  in the November general election. They took office on 20 January 2009. Barack Obama published the personal memoir Dreams from My Father  in 1995, and published a second book, The Audacity of Hope , in 2006. The title of the latter book was also the title of his 2004 keynote speech, and both books won Grammys for best spoken word album. Obama was awarded the Nobel  Peace Prize in 2009, for "his extraordinary efforts to strengthen international diplomacy and cooperation between peoples." He ran successfully for re-election in 2012, defeating Republican candidate Mitt Romney  on November 6, 2012.
Extra credit:
Barack Obama married the former Michelle Robinson  in 1992. They have two daughters: Malia  (b. 1998) and Sasha  (b. 2001)… Barack Obama's father, also named Barack Obama, was black; his mother, Ann Dunham, was white. Obama's grandmother, Madelyn Dunham (nicknamed "Toot"), died the day before Obama was elected in 2008… Obama attended Occidental College in Los Angeles before completing his undergraduate degree at Columbia… Obama's Senate website described him as "the first African American president of the Harvard Law Review" and "the third African American since Reconstruction to be elected to the U.S. Senate." The previous African-American senators elected by popular vote were Edward Brooke (1967-79, from Massachusetts) and Carol Moseley-Braun  (1993-99, from Illinois). Two other African-Americans were chosen by state senates to become U.S. Senators: Hiram Revels (1870-71, from Mississippi) and Blanche Bruce  (1875-81, also from Mississippi)… His 2008 Grammy for The Audacity of Hope  beat books by two former presidents: Bill Clinton 's Giving: How Each of Us Can Change the World  and Jimmy Carter 's Sunday Mornings in Plains: Bringing Peace to a Changing World .
Copyright © 1998-2016 by Who2?, LLC. All rights reserved.
Popular Areas
Infoplease Tools
Family Education Network
About Infoplease , Part of Family Education Network
Terms of Use *
Privacy **
*  Updated 10/2015 **  Updated 10/2015
� 2000-2016 Sandbox Networks, Inc., publishing as Infoplease