Example
# -*- coding: utf-8 -*-
"""
Description: Natural Language Interface 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 user query
sample_query = "How to increase an integration density in semiconductor memory device?";
# set the URL for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
api_url = "http://api.intellexer.com/convertQueryToBool?apikey=YourAPIKey"
# print response results
def print_response(response):
print "User query in the Boolean form: \n", response;
# create request to the Natural Language Interface API service
def request_api(url, query):
header = { 'Content-Type' : "application/octet-stream" }
req = urllib2.Request(url, query, 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_query)
except urllib2.HTTPError as error:
print 'HTTP error - %s' % error.read()
Output
User query in the Boolean form:
increase OR increasing integration density semiconductor memory device