A first glance over Wolfram|Alpha's Webservice API

A few days ago Wolfram|Alpha announced the release of their Webservice API to allow the usage of their computational knowledge engine on user’s applications. The API allows clients to submit free-form queries which return information in a variety of formats.

As you might know, Wolfram|Alpha is not a search engine, but an answer engine that answers free-form queries and computational requests by computing answers using structured data. This contrasts from traditional search engines that return as an answer a list of documents or web pages that might or not contain the answer the user is looking for. Wolfram|Alpha also is capable of processing and answering natural language queries (as it’s predecessor START) such as What is the second largest southamerican country by area?

In order to be able to use the API you must first apply for an Application ID, which is a string that identifies an application that uses the API, and it must be supplied in all calls to the API. There is no free of charge API availability as of today: Wolfram|Alpha offers three different licensing plans each having different pricing and request limits.

The request, apart from the query text, can be configured with a rich variety of options that are out of scope of this post entry. These options allow users to control timeouts for the queries, to control which result components (pods) will be processed and also to specify which ones should be to be retrieved asynchronously. The API request can be geo-localized as users can feed the engine with a location description such as “Buenos Aires, Argentina”, a latitude-longitude pair (-34.61,-58.37) or an IP address if you wish to propagate the IP of the user interacting with your application to the engine.

The REST-style API provides structured XML output formatted as image, text, audio or styled HTML. These output formats are known as Visual Representations. The main information unit in the response is the pod, which is corresponds to a result category and contains one or more subpods which is the unit that contains the actual information. A simplified xml response looks like:

<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true' error='false' numpods='5'
    datatypes='DNAString' timedout='' timing='0.914' parsetiming='0.167'>
 <pod title='Input interpretation' scanner='Identity' position='100' error='false' numsubpods='1'>
  <subpod title=''>
   <plaintext>GATTACACCAGGATAAC (genome sequence)</plaintext>
... pods deleted for brevity ...

Several language bindings for the API are available and others are being developed. The python binding is composed by a WolframAlphaEngine object that allows creating a WolframAlphaQuery which can be processed by the engine to obtain a WolframAlphaQueryResult. This result object is composed by Pod objects that can be iterated to get the desired information. Some examples of the python binding in action are included in the API distribution:

import wap

appid = 'XXXX' # Use your app id
waeo = wap.WolframAlphaEngine(appid)
waeq = wap.WolframAlphaQuery('who are you?', appid)
waeq.ScanTimeout = '3.0'
waeq.Async = False
waeq.ToURL() # After configuring the waeq must call ToURL()

result = waeo.PerformQuery(waeq.Query) # result is in xml format
waeqr = wap.WolframAlphaQueryResult(result)

for pod in waeqr.Pods():
  waep = wap.Pod(pod)
  print '\n%s: (%d subpods)' % (waep.Title(), waep.NumSubpods())

After a quick overview the API looks very promising for commercial applications that can take advantage of Wolfram|Alpha’s advanced computation capabilities. Nevertheless it would be great to see what would happen if guys at Wolfram provide free-of-cost access for free software applications.

Tags: , ,

Leave a Reply

Get Adobe Flash player