Example

Example

# Description: Natural Language Interface API usage example.
# Copyright: (C) 2015 EffectiveSoft Ltd. All Rights Reserved.
# Technical support: technical-support@effective-soft.com
# This example requires LWP and JSON libraries.


use JSON;
use LWP::UserAgent;
require HTTP::Request;


# sample user query
my $query = "How to increase an integration density in semiconductor memory device?";

# returned data from Intellexer API
my $results = "";

# create connection to the Natural Language Interface API service
my $ua = LWP::UserAgent->new or die "Cannot create connection!";
# set the URL for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
my $api_url = "http://api.intellexer.com/convertQueryToBool?apikey=YourAPIKey";
my $req = HTTP::Request->new(POST => $api_url);
$req->header('content-type' => 'application/octet-stream');
$req->content($query);
# perform the request
my $resp = $ua->request($req);
# error checking
if ($resp->is_success) 
{
	$results = $resp->decoded_content;
	print "User query in the Boolean form: \n", $results;
}
else 
{
	print "HTTP POST error code: ", $resp->code, "\t", "HTTP POST error message: ", $resp->message, "\n";
}

Output

User query in the Boolean form: 
"increase OR increasing integration density semiconductor memory device"