1
0
mirror of https://github.com/balkian/SOJA.git synced 2024-12-27 20:28:12 +00:00

merginr error fix

This commit is contained in:
Miguel Coronado 2012-03-22 20:05:10 +01:00
commit e14c614e14
48 changed files with 302 additions and 131 deletions

View File

@ -1,107 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
This file was generated by Jason 1.3.6a
http://jason.sf.net
March 22, 2012 - 19:21:46
-->
<project name ="web40sojason"
basedir=".."
default="run">
<property name="mas2j.project.file" value="Web40SOJason.mas2j"/>
<property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
<property name="build.dir" value="${basedir}/bin/classes" />
<property name="jasonJar" value="/home/miguel/trabajo/Jason-1.3.6a/lib/jason.jar"/>
<path id="project.classpath">
<pathelement location="${basedir}"/>
<pathelement location="${build.dir}"/>
<pathelement location="${jasonJar}"/>
<fileset dir="${basedir}/lib" > <include name="*.jar" /> </fileset>
</path>
<!-- tasks the user can override in his/her c-build.xml script -->
<target name="user-init">
</target>
<target name="user-end">
</target>
<target name="init">
<mkdir dir="${build.dir}" />
<antcall target="user-init" />
</target>
<target name="compile" depends="init">
<condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
<available file="${basedir}/src/java" />
</condition>
<javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" includeantruntime="false" >
<classpath refid="project.classpath"/>
</javac>
</target>
<target name="jar" depends="compile">
<delete file="${ant.project.name}.jar" />
<copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
<copy file="${mas2j.project.file}" tofile="default.mas2j" />
<jar update="yes" jarfile="${ant.project.name}.jar" >
<fileset dir="${basedir}">
<include name="**/*.asl" />
<include name="**/*.mas2j" />
</fileset>
<fileset dir="${build.dir}">
<include name="**/*.class" />
</fileset>
</jar>
<delete file="default.mas2j" />
</target>
<target name="jnlp" depends="jar" >
<mkdir dir="${basedir}/${ant.project.name}-jws"/>
<java classname="jason.infra.centralised.CreateJNLP"
failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
<classpath refid="project.classpath"/>
<arg line="${ant.project.name} ${mas2j.project.file}"/>
</java>
<copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
<fileset dir="${basedir}" includes="${ant.project.name}.jar" />
<fileset dir="/home/miguel/trabajo/Jason-1.3.6a/src/images" includes="Jason-GMoreau-Icon.jpg" />
</copy>
<signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
storepass="rbjhja" keypass="rbjhja" keystore="/home/miguel/trabajo/Jason-1.3.6a/src/jasonKeystore" />
<echo message="**" />
<echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
<echo message="** Update the codebase (in the second line of the .jnlp file)" />
<echo message="** with the URL where you will upload the application." />
<echo message="**" />
</target>
<target name="run" depends="compile" >
<echo message="Running project ${ant.project.name}" />
<java classname="jason.infra.centralised.RunCentralisedMAS"
failonerror="true" fork="yes" dir="${basedir}" >
<classpath refid="project.classpath"/>
<arg line="${mas2j.project.file} ${debug} "/>
<!-- jvmarg line="-Xmx500M -Xss8M"/ -->
</java>
<antcall target="user-end" />
</target>
<target name="clean" >
<delete failonerror="no" includeEmptyDirs="true" verbose="true">
<fileset dir="${basedir}" includes="**/*.class"/>
</delete>
</target>
</project>

1
lib/README Normal file
View File

@ -0,0 +1 @@
socket.io-java-client : https://github.com/Gottox/socket.io-java-client

BIN
lib/UmlGraph.jar Normal file

Binary file not shown.

BIN
lib/ant-launcher.jar Normal file

Binary file not shown.

BIN
lib/ant.jar Normal file

Binary file not shown.

BIN
lib/c4jason.jar Normal file

Binary file not shown.

BIN
lib/cartago.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/commons-codec-1.3.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/commons-lang-2.6.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/ezmorph-1.0.6.jar Normal file

Binary file not shown.

BIN
lib/jade.jar Normal file

Binary file not shown.

BIN
lib/jason.jar Normal file

Binary file not shown.

18
lib/javacc-LICENSE Normal file
View File

@ -0,0 +1,18 @@
Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
-Redistribution of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-Redistribution in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Sun Microsystems, Inc. or the names of contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.

BIN
lib/javacc.jar Normal file

Binary file not shown.

BIN
lib/jedit/BufferTabs.jar Normal file

Binary file not shown.

BIN
lib/jedit/ErrorList.jar Normal file

Binary file not shown.

BIN
lib/jedit/SideKick.jar Normal file

Binary file not shown.

BIN
lib/jedit/jedit.jar Normal file

Binary file not shown.

BIN
lib/json-org.jar Normal file

Binary file not shown.

BIN
lib/junit.jar Normal file

Binary file not shown.

BIN
lib/saci.jar Normal file

Binary file not shown.

BIN
lib/socketio.jar Normal file

Binary file not shown.

BIN
lib/weberknecht-0.1.1.jar Normal file

Binary file not shown.

12
src/asl/testAgent.asl Normal file
View File

@ -0,0 +1,12 @@
// Agent testAgent in project Web40 - For socket.io
!start.
/* Wait for service introduction (temporal plan, to erase) */
+!start : true
<- +have(started);
.print("Hola");
.wait(1000);
sendSocket("test","hola").
+success(yes): true
<- .print("Succes!!!!!").

View File

@ -57,7 +57,11 @@ public class SOEnvironment extends Environment {
result = this.model.sendNlu(agName, terms);
}
else if (functor.equals("findTravel")) {
result = this.model.findTravel(agName, terms);
this.model.findTravel(agName, terms);
return true;
}
else if (functor.equals("sendSocket")) {
result = this.model.sendSocket(agName, terms);
return true;
}
else {

View File

@ -9,6 +9,7 @@ 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;
/**
@ -26,12 +27,15 @@ 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 */
@ -39,6 +43,7 @@ public class Web40Model extends SOModel{
super();
this.nluConnector = new NLUConnector(NLU_SERVICE_URL);
this.renfeScrapper = new RenfeScrapper();
this.socketConnector = new SocketIOConnector(SOCKET_SERVICE_URL);
}
/**
@ -97,4 +102,33 @@ public class Web40Model extends SOModel{
}
/**
*
* @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;
}
}

View File

@ -22,26 +22,26 @@ import es.upm.dit.gsi.jason.utils.NotationUtils;
* @version Mar 22, 2012
*
*/
public class Journey implements Perceptable{
public class Journey implements Perceptable {
/** The departure time of the journey */
private String departureTime;
/** The arrival time of the journey */
private String arrivalTime;
/**
* The duration of the journey. This is not simply the difference of the
/**
* The duration of the journey. This is not simply the difference of the
* departure and arrival time because of timezone considerations.
*/
private String duration;
/** The origin */
private String origin;
/** The destination */
private String destination;
/** The fee map that contains the different available fee */
private Map<String, String> fares;
@ -56,7 +56,8 @@ public class Journey implements Perceptable{
}
/**
* @param departureTime the departureTime to set
* @param departureTime
* the departureTime to set
*/
public void setDepartureTime(String departureTime) {
this.departureTime = departureTime;
@ -70,7 +71,8 @@ public class Journey implements Perceptable{
}
/**
* @param arrivalTime the arrivalTime to set
* @param arrivalTime
* the arrivalTime to set
*/
public void setArrivalTime(String arrivalTime) {
this.arrivalTime = arrivalTime;
@ -84,7 +86,8 @@ public class Journey implements Perceptable{
}
/**
* @param duration the duration to set
* @param duration
* the duration to set
*/
public void setDuration(String duration) {
this.duration = duration;
@ -98,7 +101,8 @@ public class Journey implements Perceptable{
}
/**
* @param oringin the oringin to set
* @param oringin
* the oringin to set
*/
public void setOrigin(String origin) {
this.origin = origin;
@ -112,7 +116,8 @@ public class Journey implements Perceptable{
}
/**
* @param destination the destination to set
* @param destination
* the destination to set
*/
public void setDestination(String destination) {
this.destination = destination;
@ -126,7 +131,8 @@ public class Journey implements Perceptable{
}
/**
* @param fares the fares to set
* @param fares
* the fares to set
*/
public void setFares(Map<String, String> fares) {
this.fares = fares;
@ -146,9 +152,9 @@ public class Journey implements Perceptable{
this.queryid = queryid;
}
/** Textual representation of the journey. Use for debuging purposes inly.*/
/** Textual representation of the journey. Use for debuging purposes only. */
public String toString() {
String toString = "From: ";
toString = toString.concat(origin);
toString = toString.concat(" (");
@ -160,13 +166,13 @@ public class Journey implements Perceptable{
toString = toString.concat(") in ");
toString = toString.concat(duration);
toString = toString.concat(" for ");
if(fares != null)
if (fares != null)
toString = toString.concat(fares.toString());
else
toString += null;
return toString;
}
/**
* <p>Generates a beliefs representation of the </code>Journey</code>.
* In the current implementation of {@link #toPercepts()}, the journey
@ -209,21 +215,21 @@ public class Journey implements Perceptable{
percept = percept.concat(NotationUtils.compact(this.origin));
percept = percept.concat(", ");
percept = percept.concat(NotationUtils.compact(this.destination));
percept = percept.concat(", time(");
String digits[] = this.departureTime.split("[\\x2E\\x3A]"); // [.:]
percept = percept.concat(digits[0]);
percept = percept.concat(", ");
percept = percept.concat(digits[1]);
percept = percept.concat("), time(");
digits = this.arrivalTime.split("[\\x2E\\x3A]"); // [.:]
percept = percept.concat(digits[0]);
percept = percept.concat(", ");
percept = percept.concat(digits[1]);
percept = percept.concat("), [");
for(String fareName : fares.keySet()) {
for (String fareName : fares.keySet()) {
percept = percept.concat("fare(");
percept = percept.concat(NotationUtils.compact(fareName));
percept = percept.concat(", ");
@ -238,10 +244,9 @@ public class Journey implements Perceptable{
percept = percept.concat(this.getQueryid());
percept = percept.concat(")]");
LinkedList<Literal> ret = new LinkedList<Literal>();
ret.add(Literal.parseLiteral(percept));
return ret;
}

View File

@ -0,0 +1,57 @@
/**
*
*/
package es.upm.dit.gsi.sojason.services;
import es.upm.dit.gsi.sojason.SOModel;
/**
* This interface defines a standard way to connect to a web service in
* the definition of an external action in Jason.
*
* Project: Web40SOJason
* Package: es.upm.dit.gsi.sojason.services
* Class: WebServiceConnector
*
* @author Miguel Coronado (miguelcb@dit.upm.es)
* @version Feb 27, 2012
*
*/
public interface AsyncWebServiceConnector {
/**
* This calls the service including in the request the parameters given.
* The URL of the service, the method to use and any other particularity
* of the transaction to connect to the service must be determined in the
* implementation of the method.
*
* @param params The list of parameters to include in the service
* request. Due to this is not a <code>Dictionary</code>
* the order of the parameters it is important and will be
* determined by the implementation of the extendee
* classes.
* @return Whether the call was successful or not.
*/
public boolean call(SOModel model, String agname, String... params);
/**
* This validates the set of parameters provided. Typically, this method
* should use some regex exprsesions to check whether a parameter is valid
* or not, due to the nature of the parameter cannot be checked because of
* the type of the parameters has been unified to String.
*
* @param params The list of parameters to validate
*/
public boolean validateParams(String... params);
/**
* This generates a set of error <code>Literal</code>s that describes the
* errors committed when trying to call the given service with the set of
* parameters given.
*
* @param params The list of parameters
*/
// public Set<Literal> checkForErrors(String... params);
}

View File

@ -0,0 +1,131 @@
package es.upm.dit.gsi.sojason.services.socketio;
import io.socket.IOAcknowledge;
import io.socket.IOCallback;
import io.socket.SocketIO;
import io.socket.SocketIOException;
import jason.asSyntax.Literal;
import java.net.MalformedURLException;
import java.util.logging.Logger;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import es.upm.dit.gsi.sojason.SOModel;
import es.upm.dit.gsi.sojason.services.AsyncWebServiceConnector;
/**
* Project: Web40SOJason
* Package: es.upm.dit.gsi.sojason.services.nlu
* Class: NLUConnector
*
* @author Miguel Coronado (miguelcb@dit.upm.es)
* @version Feb 27, 2012
*
*/
public class SocketIOConnector implements AsyncWebServiceConnector{
/** The url of the service */
private String serviceUrl;
/** */
private Logger logger = Logger.getLogger("Web40SOJason." + SocketIOConnector.class.getName());
private static SocketIO socket;
static IOCallback callback = new IOCallback() {
public void onMessage(JSONObject json, IOAcknowledge ack) {
System.out.println("Message:" + json.toString());
}
@Override
public void onMessage(String data, IOAcknowledge ack) {
System.out.println("Message:" + data);
}
@Override
public void onError(SocketIOException socketIOException) {
System.out.println("Error");
socketIOException.printStackTrace();
}
@Override
public void onDisconnect() {
}
@Override
public void onConnect() {
}
@Override
public void on(String event, IOAcknowledge ack, Object... args) {
}
@Override
public void onMessage(org.json.JSONObject arg0, IOAcknowledge arg1) {
// TODO Auto-generated method stub
}
};
//TODO Remove try-catch
/** Constructor */
public SocketIOConnector(String serviceUrl) {
this.serviceUrl = serviceUrl;
try {
socket = new SocketIO();
socket.connect(serviceUrl, callback);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/**
*
*/
public boolean call(final SOModel model, final String agName, String... params) {
logger.info("Calling SocketIOConnector with"+params[0]);
try {
socket.emit("test", new IOAcknowledge() {
@Override
public void ack(Object... args) {
logger.info("Package ack'ed");
Literal lit = Literal.parseLiteral("success(yes)");
model.setDataInbox(agName, lit);
logger.info("DataInbox set");
}
}, new JSONObject().put("Hello", "Planeta"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/**
* This validates the parameters received. The
* {@link SocketIOConnector#call(String...)} method expects to receive two
* parameters of the nature and characteristics described below:
*
* <ul>
* <li>The first parameter is que query id. It is an alphanumeric string
* which normally will contain numbers, but other non-digit characters
* are permitted. <b>No alphanumeric values are not allowed</b></li>
* <li></li>
* </ul>
*
*/
public boolean validateParams(String... params) {
if (params.length != 2){
return false;
}
// TODO: check other things
return true;
}
}

16
testSocket.mas2j Normal file
View File

@ -0,0 +1,16 @@
/*
Jason Project
-- create on March 19, 2012
*/
MAS web40sojason {
infrastructure: Centralised
environment: es.upm.dit.gsi.sojason.SOEnvironment
agents:
testAgent;
aslSourcePath: "src/asl";
}