mirror of https://github.com/balkian/SOJA.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.3 KiB
Java
133 lines
3.3 KiB
Java
package es.upm.dit.gsi.sojason;
|
|
|
|
import jason.asSyntax.Literal;
|
|
import jason.asSyntax.Term;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Collection;
|
|
import java.util.logging.Logger;
|
|
|
|
import es.upm.dit.gsi.jason.utils.CollectionUtils;
|
|
import es.upm.dit.gsi.sojason.services.nlu.NLUConnector;
|
|
import es.upm.dit.gsi.sojason.services.socketio.SocketIOConnector;
|
|
import es.upm.dit.gsi.sojason.services.travel.RenfeScrapper;
|
|
|
|
/**
|
|
*
|
|
*
|
|
* Project: Web40
|
|
* Package: es.upm.dit.gsi.qa
|
|
* Class: Web40Model
|
|
*
|
|
* @author Miguel Coronado (miguelcb@dit.upm.es)
|
|
* @version Feb 29, 2012
|
|
*
|
|
*/
|
|
public class Web40Model extends SOModel{
|
|
|
|
/** */
|
|
public final static String NLU_SERVICE_URL = "http://46.4.52.82:3333/nlu";
|
|
public final static String SOCKET_SERVICE_URL = "http://localhost:3000";
|
|
|
|
/** */
|
|
private NLUConnector nluConnector;
|
|
/** */
|
|
private RenfeScrapper renfeScrapper;
|
|
/** */
|
|
private Logger logger = Logger.getLogger("Web40SOJason." + Web40Model.class.getName());
|
|
private SocketIOConnector socketConnector;
|
|
|
|
/** Constructor
|
|
* @throws IOException */
|
|
public Web40Model () throws IOException {
|
|
super();
|
|
this.nluConnector = new NLUConnector(NLU_SERVICE_URL);
|
|
this.renfeScrapper = new RenfeScrapper();
|
|
this.socketConnector = new SocketIOConnector(SOCKET_SERVICE_URL);
|
|
}
|
|
|
|
/**
|
|
* This calls the NLU service
|
|
*
|
|
* Internally this modifies the model so it reports the agent
|
|
*
|
|
* @param agName the name of the agent that will be reported with the
|
|
* results of the call.
|
|
* @param terms The parameters
|
|
* @return
|
|
*/
|
|
public boolean sendNlu (String agName, Collection<Term> params) {
|
|
|
|
logger.info("Entering sendNLU...");
|
|
try{
|
|
String[] strParams = CollectionUtils.toStringArray(params);
|
|
Collection<Literal> serviceData = nluConnector.call(strParams);
|
|
if(serviceData == null){
|
|
logger.info("Could not complete action sendNLU: no service data found");
|
|
return false;
|
|
}
|
|
|
|
// put data into mailbox
|
|
this.setDataInbox(agName, serviceData);
|
|
}
|
|
catch (Exception e){
|
|
logger.info("Could not complete action sendNLU:" + e.getMessage());
|
|
return false;
|
|
}
|
|
|
|
logger.info("NLU call completed successfully");
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param agName
|
|
* @param terms
|
|
* @return
|
|
*/
|
|
public boolean findTravel (String agName, Collection<Term> params) {
|
|
|
|
try{
|
|
String[] strParams = CollectionUtils.toStringArray(params);
|
|
Collection<Literal> serviceData = renfeScrapper.call(strParams);
|
|
if(serviceData == null){ return false; }
|
|
|
|
// put data into mailbox
|
|
this.setDataInbox(agName, serviceData);
|
|
}
|
|
catch (Exception e){ return false; }
|
|
return true;
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param agName
|
|
* @param terms
|
|
* @return
|
|
*/
|
|
public boolean sendSocket (String agName, Collection<Term> params) {
|
|
|
|
logger.info("Entering sendSocket...");
|
|
try{
|
|
String[] strParams = CollectionUtils.toStringArray(params);
|
|
boolean serviceData = socketConnector.call(this,agName,strParams);
|
|
if(serviceData == false){
|
|
logger.info("Could not complete action socketIO: false!");
|
|
return false;
|
|
}
|
|
|
|
// put data into mailbox
|
|
// this.setDataInbox(agName, serviceData);
|
|
}
|
|
catch (Exception e){
|
|
logger.info("Could not complete action SocketIO (error):" + e.getCause() + "_"+e.getCause()+"_"+e.getMessage());
|
|
return false;
|
|
}
|
|
|
|
logger.info("SocketConnector call completed successfully");
|
|
return true;
|
|
}
|
|
|
|
}
|