diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..90b07e9 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +classes diff --git a/bin/build.xml b/bin/build.xml index 9a9fe68..bc9b82c 100644 --- a/bin/build.xml +++ b/bin/build.xml @@ -5,18 +5,18 @@ This file was generated by Jason 1.3.6a http://jason.sf.net - March 20, 2012 - 16:30:55 + March 22, 2012 - 19:46:25 --> - + - + @@ -73,10 +73,10 @@ - + + storepass="rbjhja" keypass="rbjhja" keystore="/media/Data/Programs/eclipse/./src/jasonKeystore" /> diff --git a/bin/classes/es/upm/dit/gsi/jason/utils/NotationUtils.class b/bin/classes/es/upm/dit/gsi/jason/utils/NotationUtils.class deleted file mode 100644 index 207ff1a..0000000 Binary files a/bin/classes/es/upm/dit/gsi/jason/utils/NotationUtils.class and /dev/null differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/SOEnvironment.class b/bin/classes/es/upm/dit/gsi/sojason/SOEnvironment.class deleted file mode 100644 index 06c7060..0000000 Binary files a/bin/classes/es/upm/dit/gsi/sojason/SOEnvironment.class and /dev/null differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/Web40Model.class b/bin/classes/es/upm/dit/gsi/sojason/Web40Model.class deleted file mode 100644 index be50755..0000000 Binary files a/bin/classes/es/upm/dit/gsi/sojason/Web40Model.class and /dev/null differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/beans/Journey.class b/bin/classes/es/upm/dit/gsi/sojason/beans/Journey.class deleted file mode 100644 index 9c712ab..0000000 Binary files a/bin/classes/es/upm/dit/gsi/sojason/beans/Journey.class and /dev/null differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/beans/NLUTravel.class b/bin/classes/es/upm/dit/gsi/sojason/beans/NLUTravel.class deleted file mode 100644 index a2ffa2e..0000000 Binary files a/bin/classes/es/upm/dit/gsi/sojason/beans/NLUTravel.class and /dev/null differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class b/bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class deleted file mode 100644 index 115401c..0000000 Binary files a/bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class and /dev/null differ diff --git a/bin/commonSenseAgent.asl b/bin/commonSenseAgent.asl new file mode 100644 index 0000000..9219e22 --- /dev/null +++ b/bin/commonSenseAgent.asl @@ -0,0 +1,8 @@ +// Agent userAgent in project Web40 + +/* Initial beliefs and rules */ + +/* Initial goals */ + + +/* Plans */ diff --git a/bin/classes/es/upm/dit/gsi/jason/utils/CollectionUtils.class b/bin/es/upm/dit/gsi/jason/utils/CollectionUtils.class similarity index 75% rename from bin/classes/es/upm/dit/gsi/jason/utils/CollectionUtils.class rename to bin/es/upm/dit/gsi/jason/utils/CollectionUtils.class index 7378c3d..4eb5287 100644 Binary files a/bin/classes/es/upm/dit/gsi/jason/utils/CollectionUtils.class and b/bin/es/upm/dit/gsi/jason/utils/CollectionUtils.class differ diff --git a/bin/es/upm/dit/gsi/jason/utils/NotationUtils.class b/bin/es/upm/dit/gsi/jason/utils/NotationUtils.class new file mode 100644 index 0000000..58f958d Binary files /dev/null and b/bin/es/upm/dit/gsi/jason/utils/NotationUtils.class differ diff --git a/bin/es/upm/dit/gsi/sojason/SOEnvironment.class b/bin/es/upm/dit/gsi/sojason/SOEnvironment.class new file mode 100644 index 0000000..8678978 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/SOEnvironment.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/SOModel.class b/bin/es/upm/dit/gsi/sojason/SOModel.class similarity index 63% rename from bin/classes/es/upm/dit/gsi/sojason/SOModel.class rename to bin/es/upm/dit/gsi/sojason/SOModel.class index 442a264..e827aea 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/SOModel.class and b/bin/es/upm/dit/gsi/sojason/SOModel.class differ diff --git a/bin/es/upm/dit/gsi/sojason/Web40Model.class b/bin/es/upm/dit/gsi/sojason/Web40Model.class new file mode 100644 index 0000000..59a9a02 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/Web40Model.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/beans/ErrorReport.class b/bin/es/upm/dit/gsi/sojason/beans/ErrorReport.class similarity index 80% rename from bin/classes/es/upm/dit/gsi/sojason/beans/ErrorReport.class rename to bin/es/upm/dit/gsi/sojason/beans/ErrorReport.class index 637208f..4ed5d5a 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/beans/ErrorReport.class and b/bin/es/upm/dit/gsi/sojason/beans/ErrorReport.class differ diff --git a/bin/es/upm/dit/gsi/sojason/beans/Journey.class b/bin/es/upm/dit/gsi/sojason/beans/Journey.class new file mode 100644 index 0000000..a540716 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/beans/Journey.class differ diff --git a/bin/es/upm/dit/gsi/sojason/beans/NLUTravel.class b/bin/es/upm/dit/gsi/sojason/beans/NLUTravel.class new file mode 100644 index 0000000..9149d98 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/beans/NLUTravel.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/beans/Perceptable.class b/bin/es/upm/dit/gsi/sojason/beans/Perceptable.class similarity index 73% rename from bin/classes/es/upm/dit/gsi/sojason/beans/Perceptable.class rename to bin/es/upm/dit/gsi/sojason/beans/Perceptable.class index 6a8207e..c0eefa8 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/beans/Perceptable.class and b/bin/es/upm/dit/gsi/sojason/beans/Perceptable.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/beans/TravelType.class b/bin/es/upm/dit/gsi/sojason/beans/TravelType.class similarity index 89% rename from bin/classes/es/upm/dit/gsi/sojason/beans/TravelType.class rename to bin/es/upm/dit/gsi/sojason/beans/TravelType.class index daef72a..95bc9f0 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/beans/TravelType.class and b/bin/es/upm/dit/gsi/sojason/beans/TravelType.class differ diff --git a/bin/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.class b/bin/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.class new file mode 100644 index 0000000..d3deb02 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/services/WebServiceConnector.class b/bin/es/upm/dit/gsi/sojason/services/WebServiceConnector.class similarity index 78% rename from bin/classes/es/upm/dit/gsi/sojason/services/WebServiceConnector.class rename to bin/es/upm/dit/gsi/sojason/services/WebServiceConnector.class index 17b618f..166b720 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/services/WebServiceConnector.class and b/bin/es/upm/dit/gsi/sojason/services/WebServiceConnector.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class b/bin/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class similarity index 81% rename from bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class rename to bin/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class index 641e13e..f5aad09 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class and b/bin/es/upm/dit/gsi/sojason/services/nlu/NLUConnector.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class b/bin/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class similarity index 97% rename from bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class rename to bin/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class index e527e36..9838e06 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class and b/bin/es/upm/dit/gsi/sojason/services/nlu/NLUModel.class differ diff --git a/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$1.class b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$1.class new file mode 100644 index 0000000..aefb245 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$1.class differ diff --git a/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$2.class b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$2.class new file mode 100644 index 0000000..56e5b5c Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector$2.class differ diff --git a/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.class b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.class new file mode 100644 index 0000000..e4077a0 Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.class differ diff --git a/bin/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class b/bin/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class new file mode 100644 index 0000000..4985d3f Binary files /dev/null and b/bin/es/upm/dit/gsi/sojason/services/travel/RenfeScrapper.class differ diff --git a/bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class b/bin/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class similarity index 58% rename from bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class rename to bin/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class index d2f0481..96a9b17 100644 Binary files a/bin/classes/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class and b/bin/es/upm/dit/gsi/sojason/services/travel/RenfeServiceConvenion.class differ diff --git a/bin/nluAgent.asl b/bin/nluAgent.asl new file mode 100644 index 0000000..f160774 --- /dev/null +++ b/bin/nluAgent.asl @@ -0,0 +1,40 @@ +// Agent nluAgent in project Web40SOJason + +/* Initial beliefs and rules */ + +/* Initial goals */ + +/* Plans */ + +@in_msg ++user_msg(Msg, Query) : true + <- sendNLU(Query, Msg); + -user_msg(Msg, Query). // clear the memory + + +/* Tell the user agent what the NLU system understood */ ++price(Terms, Price)[query(Query), domain(travel)] : true + <- .send(userAgent, tell, price(Terms, Price)[query(Query)], domain(travel)); + .print("Percibido: price ",Terms, " ", Price ). + ++date(Terms, Day, Month, Year)[query(Query), domain(travel)] : true + <- .send(userAgent, tell, date(Terms, Day, Month, Year)[query(Query), domain(travel)]); + .print("Percibido: date ",Terms, " ", Day, " ", Month, " ", Year). + ++time(Terms, Hours, Minutes)[query(Query), domain(travel)] : true + <- .send(userAgent, tell, time(Terms, Hours, Minutes)[query(Query), domain(travel)]); + .print("Percibido: time ",Terms, " ", Hours, " ", Minutes). + ++location(Terms, Place)[query(Query), domain(travel)] : true + <- .send(userAgent, tell, location(Terms, Place)[query(Query), domain(travel)]); + .print("Percibido: location ",Terms, " ", Place). + ++type(Terms)[query(Query), domain(travel)] : true + <- .send(userAgent, tell, type(Terms)[query(Query), domain(travel)]); + .print("Percibido: type ",Terms). + +@sendFindTravel ++done[query(Query), domain(Domain)] : true + <- .wait(1000); // wait until all other information is sent + .print("Percepcion completada"); + .send(userAgent, achieve, find(Domain, Query)). \ No newline at end of file diff --git a/bin/testAgent.asl b/bin/testAgent.asl new file mode 100644 index 0000000..0ca6e4f --- /dev/null +++ b/bin/testAgent.asl @@ -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!!!!!"). diff --git a/bin/travelAgent.asl b/bin/travelAgent.asl new file mode 100644 index 0000000..7a6b517 --- /dev/null +++ b/bin/travelAgent.asl @@ -0,0 +1,60 @@ +// Agent travelAgent in project Web40 + +/* Initial beliefs and rules */ +canFindTravel(Query) + :- location(from,_)[query(Query)] & + location(to,_)[query(Query)] & + date(departure,_,_,_)[query(Query)]. + +/* Initial goals */ +contact(userAgent). +my_service(travel). +my_service(train). + +/************** Plans *****************/ + +/* Introduce myself to the user agent */ +@introduce_myself ++my_service(Domain) + : contact(Agent) & .my_name(Me) + <- .send(Agent, tell, service(Me, Domain)). + +@introduction_rety ++my_service(Domain) : not contact(Agent) + <- -+my_service(Domain). + + +/* Find travel plans */ +@findTravel1 ++!find(travel, Query) : not canFindTravel(Query) & not delay(Query) + <- .print("Not enought data. Lets wait some time"); + .wait(3000); + +delay(Query); + !find(travel, Query). + +@findTravel2 ++!find(travel, Query) : not canFindTravel(Query) & delay(Query) + <- -delay(Query); + .print("Not enought data. Lets ask!"). + +@findTravel3 ++!find(travel, Query) : canFindTravel(Query) + <- ?location(to, To); + ?location(from, From); + ?date(departure, Day, Month, Year); + findTravel(From, To, Day, Month, Year); + .print("ok"). + +@findTravelFailureRety +-!find(travel, Query) : not error(Msg, Query)<- !findTravel(Query). + +@findTravelFailureError +-!find(travel, Query) : error(Msg, Query) + <- .print("Problema al encontrar viajes:", Msg); + !findTravel(Query). + + +/* log results */ +@log_the_journey ++journey(From, To, Departure, Arrival, Fares) : true + <- .print("Travel found: From ", From,"<", Departure, "> to ", To, "<", Arrival, "> for ", Fares). \ No newline at end of file diff --git a/bin/userAgent.asl b/bin/userAgent.asl new file mode 100644 index 0000000..ee6cc48 --- /dev/null +++ b/bin/userAgent.asl @@ -0,0 +1,56 @@ +// Agent userAgent in project Web40 + +/* Initial beliefs and rules */ +new_query(Query) :- .random(R) & Query = (1000*R)+1. + +!start. + +/* Initial goals */ + +/******* Plans ***************************/ + +/* Wait for service introduction (temporal plan, to erase) */ ++!start : true + <- .wait(1000); + +user_msg("I want to travel from Madrid to Cuenca in the morning that costs no more than 200€ and dinner in a romantic restaurant"). + + +/* Ask the nlu agent */ ++user_msg(Msg) : new_query(Query) + <- .send(nluAgent, tell, user_msg(Msg, Query) ). + +/* Log the received data */ ++price(Terms, Price)[query(Query), domain(Domain)] : true + <- .print("Percibido: price ",Terms, " ", Price ); + +data(price(Terms), Query, Domain). + ++date(Terms, Day, Month, Year)[query(Query), domain(Domain)] : true + <- .print("Percibido: date ",Terms, " ", Day, " ", Month, " ", Year); + +data(date(Terms, Day, Month, Year), Query, Domain). + ++time(Terms, Hours, Minutes)[query(Query), domain(Domain)] : true + <- .print("Percibido: time ",Terms, " ", Hours, " ", Minutes); + +data(time(Terms, Hours, Minutes), Query, Domain). + ++location(Terms, Place)[query(Query), domain(Domain)] : true + <- .print("Percibido: location ",Terms, " ", Place); + +data(location(Terms, Place), Query, Domain). + ++type(Terms)[query(Query), domain(Domain)] : true + <- .print("Percibido: type ",Terms). + +/* find travel */ +/*@find_travel ++!find(travel, Query) : true + <- .println("lets find travel ", Query); + .findall(Name, service(Name, travel), List); + .send(List, achieve, find(travel, Query)). +*/ + +@do_search ++!find(Domain, Query) : true + <- .print("Perform find ", Domain, " ", Query); + .findall(Name, service(Name, Domain), AgList); + .findall(Atom[query(Query)], data(Atom, Query, Domain), DataList); + .send(AgList, tell, DataList); + .send(AgList, achieve, find(Domain, Query)). \ No newline at end of file diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..e394c6b --- /dev/null +++ b/lib/README @@ -0,0 +1 @@ +socket.io-java-client : https://github.com/Gottox/socket.io-java-client \ No newline at end of file diff --git a/lib/UmlGraph.jar b/lib/UmlGraph.jar new file mode 100644 index 0000000..1e7a918 Binary files /dev/null and b/lib/UmlGraph.jar differ diff --git a/lib/ant-launcher.jar b/lib/ant-launcher.jar new file mode 100644 index 0000000..08ec632 Binary files /dev/null and b/lib/ant-launcher.jar differ diff --git a/lib/ant.jar b/lib/ant.jar new file mode 100644 index 0000000..85292f0 Binary files /dev/null and b/lib/ant.jar differ diff --git a/lib/c4jason.jar b/lib/c4jason.jar new file mode 100644 index 0000000..581eb11 Binary files /dev/null and b/lib/c4jason.jar differ diff --git a/lib/cartago.jar b/lib/cartago.jar new file mode 100644 index 0000000..e6cbac0 Binary files /dev/null and b/lib/cartago.jar differ diff --git a/lib/commons-beanutils-1.8.3.jar b/lib/commons-beanutils-1.8.3.jar new file mode 100644 index 0000000..218510b Binary files /dev/null and b/lib/commons-beanutils-1.8.3.jar differ diff --git a/lib/commons-codec-1.3.jar b/lib/commons-codec-1.3.jar new file mode 100644 index 0000000..957b675 Binary files /dev/null and b/lib/commons-codec-1.3.jar differ diff --git a/lib/commons-collections-3.2.1.jar b/lib/commons-collections-3.2.1.jar new file mode 100644 index 0000000..c35fa1f Binary files /dev/null and b/lib/commons-collections-3.2.1.jar differ diff --git a/lib/commons-lang-2.6.jar b/lib/commons-lang-2.6.jar new file mode 100644 index 0000000..98467d3 Binary files /dev/null and b/lib/commons-lang-2.6.jar differ diff --git a/lib/commons-logging-1.1.1.jar b/lib/commons-logging-1.1.1.jar new file mode 100644 index 0000000..8758a96 Binary files /dev/null and b/lib/commons-logging-1.1.1.jar differ diff --git a/lib/ezmorph-1.0.6.jar b/lib/ezmorph-1.0.6.jar new file mode 100644 index 0000000..30fad12 Binary files /dev/null and b/lib/ezmorph-1.0.6.jar differ diff --git a/lib/jade.jar b/lib/jade.jar new file mode 100644 index 0000000..7424e62 Binary files /dev/null and b/lib/jade.jar differ diff --git a/lib/jason.jar b/lib/jason.jar new file mode 100644 index 0000000..1aaa966 Binary files /dev/null and b/lib/jason.jar differ diff --git a/lib/javacc-LICENSE b/lib/javacc-LICENSE new file mode 100644 index 0000000..5e51a41 --- /dev/null +++ b/lib/javacc-LICENSE @@ -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. diff --git a/lib/javacc.jar b/lib/javacc.jar new file mode 100644 index 0000000..38f8426 Binary files /dev/null and b/lib/javacc.jar differ diff --git a/lib/jedit/BufferTabs.jar b/lib/jedit/BufferTabs.jar new file mode 100644 index 0000000..cd87b8c Binary files /dev/null and b/lib/jedit/BufferTabs.jar differ diff --git a/lib/jedit/ErrorList.jar b/lib/jedit/ErrorList.jar new file mode 100644 index 0000000..b84516d Binary files /dev/null and b/lib/jedit/ErrorList.jar differ diff --git a/lib/jedit/SideKick.jar b/lib/jedit/SideKick.jar new file mode 100644 index 0000000..0d36058 Binary files /dev/null and b/lib/jedit/SideKick.jar differ diff --git a/lib/jedit/jedit.jar b/lib/jedit/jedit.jar new file mode 100644 index 0000000..6d9dc7d Binary files /dev/null and b/lib/jedit/jedit.jar differ diff --git a/lib/json-org.jar b/lib/json-org.jar new file mode 100644 index 0000000..3e53d2e Binary files /dev/null and b/lib/json-org.jar differ diff --git a/lib/junit.jar b/lib/junit.jar new file mode 100644 index 0000000..674d71e Binary files /dev/null and b/lib/junit.jar differ diff --git a/lib/saci.jar b/lib/saci.jar new file mode 100644 index 0000000..7710dba Binary files /dev/null and b/lib/saci.jar differ diff --git a/lib/socketio.jar b/lib/socketio.jar new file mode 100644 index 0000000..cf6039a Binary files /dev/null and b/lib/socketio.jar differ diff --git a/lib/weberknecht-0.1.1.jar b/lib/weberknecht-0.1.1.jar new file mode 100644 index 0000000..ad94960 Binary files /dev/null and b/lib/weberknecht-0.1.1.jar differ diff --git a/src/asl/testAgent.asl b/src/asl/testAgent.asl new file mode 100644 index 0000000..0ca6e4f --- /dev/null +++ b/src/asl/testAgent.asl @@ -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!!!!!"). diff --git a/src/java/es/upm/dit/gsi/sojason/SOEnvironment.java b/src/java/es/upm/dit/gsi/sojason/SOEnvironment.java index 9ae340e..cb025fc 100644 --- a/src/java/es/upm/dit/gsi/sojason/SOEnvironment.java +++ b/src/java/es/upm/dit/gsi/sojason/SOEnvironment.java @@ -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 { diff --git a/src/java/es/upm/dit/gsi/sojason/Web40Model.java b/src/java/es/upm/dit/gsi/sojason/Web40Model.java index bcdcadc..1624a16 100644 --- a/src/java/es/upm/dit/gsi/sojason/Web40Model.java +++ b/src/java/es/upm/dit/gsi/sojason/Web40Model.java @@ -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); } /** @@ -95,4 +100,33 @@ public class Web40Model extends SOModel{ } + /** + * + * @param agName + * @param terms + * @return + */ + public boolean sendSocket (String agName, Collection 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; + } + } diff --git a/src/java/es/upm/dit/gsi/sojason/beans/Journey.java b/src/java/es/upm/dit/gsi/sojason/beans/Journey.java index 003bd86..e49fdcc 100644 --- a/src/java/es/upm/dit/gsi/sojason/beans/Journey.java +++ b/src/java/es/upm/dit/gsi/sojason/beans/Journey.java @@ -13,28 +13,28 @@ import es.upm.dit.gsi.jason.utils.NotationUtils; /** * @author miguel - * + * */ -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 fares; @@ -46,7 +46,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; @@ -60,7 +61,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; @@ -74,7 +76,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; @@ -88,7 +91,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; @@ -102,7 +106,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; @@ -116,15 +121,16 @@ public class Journey implements Perceptable{ } /** - * @param fares the fares to set + * @param fares + * the fares to set */ public void setFares(Map fares) { this.fares = fares; } - - /** Textual representation of the journey. Use for debuging purposes inly.*/ + + /** Textual representation of the journey. Use for debuging purposes inly. */ public String toString() { - + String toString = "From: "; toString = toString.concat(origin); toString = toString.concat(" ("); @@ -136,69 +142,72 @@ 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; } - + /** - * journey(madrid, ciudad_real, 10.15, 11.5, [fare(turista, 22.5), fare(preferente, 35)] - * journey(madrid, ciudad_real, time(10,15), time(11,5), [fare(turista, 22.5), fare(preferente, 35)] + * journey(madrid, ciudad_real, 10.15, 11.5, [fare(turista, 22.5), + * fare(preferente, 35)] journey(madrid, ciudad_real, time(10,15), + * time(11,5), [fare(turista, 22.5), fare(preferente, 35)] * * @return */ public List toPercepts() { - -// if (this.fares.size() == 0){ return null; } -// -// String percept = "journey("; -// percept = percept.concat(this.origin); -// percept = percept.concat(", "); -// percept = percept.concat(this.destination); -// percept = percept.concat(", "); -// percept = percept.concat(this.departureTime); -// percept = percept.concat(", "); -// percept = percept.concat(this.arrivalTime); -// -// percept = percept.concat(", ["); -// for(String fareName : fares.keySet()) { -// percept = percept.concat("fare("); -// percept = percept.concat(fareName); -// percept = percept.concat(", "); -// percept = percept.concat(fares.get(fareName)); -// percept = percept.concat("), "); -// } -// percept = percept.substring(0, percept.lastIndexOf(",")); -// percept = percept.concat("])"); -// -// LinkedList ret = new LinkedList(); -// ret.add(Literal.parseLiteral(percept)); -// -// return ret; - - if (this.fares.size() == 0){ return null; } - + + // if (this.fares.size() == 0){ return null; } + // + // String percept = "journey("; + // percept = percept.concat(this.origin); + // percept = percept.concat(", "); + // percept = percept.concat(this.destination); + // percept = percept.concat(", "); + // percept = percept.concat(this.departureTime); + // percept = percept.concat(", "); + // percept = percept.concat(this.arrivalTime); + // + // percept = percept.concat(", ["); + // for(String fareName : fares.keySet()) { + // percept = percept.concat("fare("); + // percept = percept.concat(fareName); + // percept = percept.concat(", "); + // percept = percept.concat(fares.get(fareName)); + // percept = percept.concat("), "); + // } + // percept = percept.substring(0, percept.lastIndexOf(",")); + // percept = percept.concat("])"); + // + // LinkedList ret = new LinkedList(); + // ret.add(Literal.parseLiteral(percept)); + // + // return ret; + + if (this.fares.size() == 0) { + return null; + } + String percept = "journey("; 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(", "); @@ -207,10 +216,10 @@ public class Journey implements Perceptable{ } percept = percept.substring(0, percept.lastIndexOf(",")); percept = percept.concat("])"); - + LinkedList ret = new LinkedList(); ret.add(Literal.parseLiteral(percept)); - + return ret; } diff --git a/src/java/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.java b/src/java/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.java new file mode 100644 index 0000000..c5eb7ed --- /dev/null +++ b/src/java/es/upm/dit/gsi/sojason/services/AsyncWebServiceConnector.java @@ -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 Dictionary + * 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 Literals 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 checkForErrors(String... params); + +} diff --git a/src/java/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.java b/src/java/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.java new file mode 100644 index 0000000..2f7f5ce --- /dev/null +++ b/src/java/es/upm/dit/gsi/sojason/services/socketio/SocketIOConnector.java @@ -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: + * + *
    + *
  • The first parameter is que query id. It is an alphanumeric string + * which normally will contain numbers, but other non-digit characters + * are permitted. No alphanumeric values are not allowed
  • + *
  • + *
+ * + */ + public boolean validateParams(String... params) { + if (params.length != 2){ + return false; + } + // TODO: check other things + return true; + } + +} diff --git a/testSocket.mas2j b/testSocket.mas2j new file mode 100644 index 0000000..9c89ece --- /dev/null +++ b/testSocket.mas2j @@ -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"; +} \ No newline at end of file