""" A client program that accesses to the Acromine REST service. Copyright (c) 2009, Naoaki Okazaki. This program issues a query (shortform "HMM") to the Acromine service, and prints the object returned from the service. """ import urllib import json if __name__ == '__main__': # This is necessary only for running this program through CGI. print('Content-Type: text/plain') print('') # Query. shortform = 'HMM' longform = '' # Access the service through HTTP GET. params = urllib.urlencode({'sf': shortform, 'lf': longform}) f = urllib.urlopen( 'http://www.nactem.ac.uk/software/acromine_key/dictionary.py', params ) # Convert the JSON response to the Python object. ret = json.loads(f.read()) # Output the object. for sf in ret: print('sf: %s' % sf[u'sf']) for lf in sf[u'lfs']: print( ' lf: %(lf)s, freq: %(freq)d, since: %(since)d' % lf) for var in lf[u'vars']: print(' lf: %(lf)s, freq: %(freq)d, since: %(since)d' % var)