/* ** Copyright [2012] [Megam Systems] ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ package org.megam.deccanplato.provider.maluuba.handler; import static org.megam.deccanplato.provider.Constants.*; import static org.megam.deccanplato.provider.maluuba.Constants.*; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.message.BasicNameValuePair; import org.megam.deccanplato.http.TransportMachinery; import org.megam.deccanplato.http.TransportResponse; import org.megam.deccanplato.http.TransportTools; import org.megam.deccanplato.provider.BusinessActivity; import org.megam.deccanplato.provider.core.BusinessActivityInfo; /** * @author pandiyaraja * * This class deals with the interpreter endpoint api call. this interpreter * class method provides some interpretation information about a text in standard form. * The key pieces of information provided are Category, Action and Entities. * category denotes the type of business function and action denotes action of business function * and entities denotes message of the given text. * */ public class InterpretEndpointImpl implements BusinessActivity{ private Map<String, String> args = new HashMap<String, String>(); private BusinessActivityInfo bizInfo; /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#setArguments(org.megam.deccanplato.provider.core.BusinessActivityInfo, java.util.Map) */ @Override public void setArguments(BusinessActivityInfo tempBizInfo, Map<String, String> tempArgs) { this.bizInfo=tempBizInfo; this.args=tempArgs; } /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#run() */ @Override public Map<String, String> run() { Map<String, String> outMap = new HashMap<String, String>(); final String NORMALIZE_URL="http://napi.maluuba.com/v0/interpret?"+PHRASE+"="+args.get(PHRASE)+"&"+APIKEY+"="+args.get(APIKEY); TransportTools tst = new TransportTools(NORMALIZE_URL, null, null); String responseBody = null; TransportResponse response = null; try { response = TransportMachinery.get(tst); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } responseBody = response.entityToString(); outMap.put(OUTPUT, responseBody); return outMap; } /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#name() */ @Override public String name() { // TODO Auto-generated method stub return "interpret"; } }