mirror of
https://github.com/balkian/SOJA.git
synced 2024-12-28 20:58:13 +00:00
merge fix
This commit is contained in:
parent
8a517c87a0
commit
9bc4304a4a
@ -5,7 +5,7 @@
|
|||||||
This file was generated by Jason 1.3.6a
|
This file was generated by Jason 1.3.6a
|
||||||
http://jason.sf.net
|
http://jason.sf.net
|
||||||
|
|
||||||
March 20, 2012 - 16:30:55
|
March 22, 2012 - 19:21:46
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project name ="web40sojason"
|
<project name ="web40sojason"
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -11,6 +11,8 @@ contact(userAgent).
|
|||||||
my_service(travel).
|
my_service(travel).
|
||||||
my_service(train).
|
my_service(train).
|
||||||
|
|
||||||
|
fare(turista).
|
||||||
|
|
||||||
/************** Plans *****************/
|
/************** Plans *****************/
|
||||||
|
|
||||||
/* Introduce myself to the user agent */
|
/* Introduce myself to the user agent */
|
||||||
@ -35,14 +37,14 @@ my_service(train).
|
|||||||
@findTravel2
|
@findTravel2
|
||||||
+!find(travel, Query) : not canFindTravel(Query) & delay(Query)
|
+!find(travel, Query) : not canFindTravel(Query) & delay(Query)
|
||||||
<- -delay(Query);
|
<- -delay(Query);
|
||||||
.print("Not enought data. Lets ask!").
|
.print("Not enought data. TODO:Lets ask!").
|
||||||
|
|
||||||
@findTravel3
|
@findTravel3
|
||||||
+!find(travel, Query) : canFindTravel(Query)
|
+!find(travel, Query) : canFindTravel(Query)
|
||||||
<- ?location(to, To);
|
<- ?location(to, To);
|
||||||
?location(from, From);
|
?location(from, From);
|
||||||
?date(departure, Day, Month, Year);
|
?date(departure, Day, Month, Year);
|
||||||
findTravel(From, To, Day, Month, Year);
|
findTravel(Query,From, To, Day, Month, Year);
|
||||||
.print("ok").
|
.print("ok").
|
||||||
|
|
||||||
@findTravelFailureRety
|
@findTravelFailureRety
|
||||||
@ -54,7 +56,22 @@ my_service(train).
|
|||||||
!findTravel(Query).
|
!findTravel(Query).
|
||||||
|
|
||||||
|
|
||||||
|
+journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query), source(percept)]
|
||||||
|
: fare(FName)
|
||||||
|
<- +journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query)]. //note it down
|
||||||
|
|
||||||
|
+journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query), source(percept)]
|
||||||
|
: ~fare(FName)
|
||||||
|
<- true. // skip this
|
||||||
|
|
||||||
|
+journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query), source(percept)]
|
||||||
|
: not fare(_) & not ~fare(FName) // no restrictions, so note them all down
|
||||||
|
<- +journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query)].
|
||||||
|
|
||||||
|
|
||||||
/* log results */
|
/* log results */
|
||||||
@log_the_journey
|
@log_the_journey
|
||||||
+journey(From, To, Departure, Arrival, Fares) : true
|
+journey(From, To, Departure, Arrival, fare(FName, FPrice))[query(Query), source(percept)]
|
||||||
<- .print("Travel found: From ", From,"<", Departure, "> to ", To, "<", Arrival, "> for ", Fares).
|
: true
|
||||||
|
<- .print("Discard travel : From ", From,"<", Departure, "> to ", To, "<", Arrival, "> for ", Fares).
|
||||||
|
|
@ -82,6 +82,7 @@ public class Web40Model extends SOModel{
|
|||||||
*/
|
*/
|
||||||
public boolean findTravel (String agName, Collection<Term> params) {
|
public boolean findTravel (String agName, Collection<Term> params) {
|
||||||
|
|
||||||
|
logger.info("Entering findTravel...");
|
||||||
try{
|
try{
|
||||||
String[] strParams = CollectionUtils.toStringArray(params);
|
String[] strParams = CollectionUtils.toStringArray(params);
|
||||||
Collection<Literal> serviceData = renfeScrapper.call(strParams);
|
Collection<Literal> serviceData = renfeScrapper.call(strParams);
|
||||||
@ -91,6 +92,7 @@ public class Web40Model extends SOModel{
|
|||||||
this.setDataInbox(agName, serviceData);
|
this.setDataInbox(agName, serviceData);
|
||||||
}
|
}
|
||||||
catch (Exception e){ return false; }
|
catch (Exception e){ return false; }
|
||||||
|
logger.info("Scraping completed successfully");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ package es.upm.dit.gsi.sojason.beans;
|
|||||||
|
|
||||||
import jason.asSyntax.Literal;
|
import jason.asSyntax.Literal;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -12,7 +13,13 @@ import java.util.Map;
|
|||||||
import es.upm.dit.gsi.jason.utils.NotationUtils;
|
import es.upm.dit.gsi.jason.utils.NotationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author miguel
|
*
|
||||||
|
* Project: SOJA
|
||||||
|
* Package: es.upm.dit.gsi.sojason.beans
|
||||||
|
* Class: Journey
|
||||||
|
*
|
||||||
|
* @author Miguel Coronado (miguelcb@dit.upm.es)
|
||||||
|
* @version Mar 22, 2012
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Journey implements Perceptable{
|
public class Journey implements Perceptable{
|
||||||
@ -38,6 +45,9 @@ public class Journey implements Perceptable{
|
|||||||
/** The fee map that contains the different available fee */
|
/** The fee map that contains the different available fee */
|
||||||
private Map<String, String> fares;
|
private Map<String, String> fares;
|
||||||
|
|
||||||
|
/** The query id. It is an annotation, it is not mandatory */
|
||||||
|
private String queryid = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the departureTime
|
* @return the departureTime
|
||||||
*/
|
*/
|
||||||
@ -122,6 +132,20 @@ public class Journey implements Perceptable{
|
|||||||
this.fares = fares;
|
this.fares = fares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the queryid
|
||||||
|
*/
|
||||||
|
public String getQueryid() {
|
||||||
|
return queryid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param queryid the queryid to set
|
||||||
|
*/
|
||||||
|
public void setQueryid(String queryid) {
|
||||||
|
this.queryid = queryid;
|
||||||
|
}
|
||||||
|
|
||||||
/** Textual representation of the journey. Use for debuging purposes inly.*/
|
/** Textual representation of the journey. Use for debuging purposes inly.*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
@ -144,41 +168,42 @@ public class Journey implements Perceptable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* journey(madrid, ciudad_real, 10.15, 11.5, [fare(turista, 22.5), fare(preferente, 35)]
|
* <p>Generates a beliefs representation of the </code>Journey</code>.
|
||||||
* journey(madrid, ciudad_real, time(10,15), time(11,5), [fare(turista, 22.5), fare(preferente, 35)]
|
* In the current implementation of {@link #toPercepts()}, the journey
|
||||||
|
* is represented by several beliefs, all of them with the same value
|
||||||
|
* in the from, to, departure and arrival time fields, but different
|
||||||
|
* fares. The exact representation is presented below:</p>
|
||||||
*
|
*
|
||||||
* @return
|
* <ul>
|
||||||
|
* <li>journey(madrid, ciudad_real, time(10,15), time(11,5), fare(turista, 22.5))</li>
|
||||||
|
* <li>journey(madrid, ciudad_real, time(10,15), time(11,5), fare(preferente, 35))</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Notice that in the current implementation the <code>Duration</code>
|
||||||
|
* attribute is skiped.</p>
|
||||||
|
*
|
||||||
|
* @return The list with the percepts or an empty list if no fare is given
|
||||||
*/
|
*/
|
||||||
public List<Literal> toPercepts() {
|
public List<Literal> toPercepts() {
|
||||||
|
if (this.fares.size() == 0){ return new LinkedList<Literal>(); }
|
||||||
|
return unfoldPercepts();
|
||||||
|
//return foldPercepts();
|
||||||
|
}
|
||||||
|
|
||||||
// if (this.fares.size() == 0){ return null; }
|
/**
|
||||||
//
|
* <p>Generates a beliefs representation of the </code>Journey</code>.
|
||||||
// String percept = "journey(";
|
* The journey is represented by a single belief, that contains all the
|
||||||
// percept = percept.concat(this.origin);
|
* fares as an array. The exact representation is presented below</p>
|
||||||
// percept = percept.concat(", ");
|
*
|
||||||
// percept = percept.concat(this.destination);
|
* <ul>
|
||||||
// percept = percept.concat(", ");
|
* <li>journey(madrid, ciudad_real, time(10,15), time(11,5), [fare(turista, 22.5), fare(preferente, 35)])</li>
|
||||||
// percept = percept.concat(this.departureTime);
|
* </ul>
|
||||||
// percept = percept.concat(", ");
|
*
|
||||||
// percept = percept.concat(this.arrivalTime);
|
* @return List with literals that represent the journey. With a folded
|
||||||
//
|
* percept only one percept will be included in the list.
|
||||||
// percept = percept.concat(", [");
|
*/
|
||||||
// for(String fareName : fares.keySet()) {
|
@SuppressWarnings("unused")
|
||||||
// percept = percept.concat("fare(");
|
private List<Literal> foldPercepts() {
|
||||||
// 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<Literal> ret = new LinkedList<Literal>();
|
|
||||||
// ret.add(Literal.parseLiteral(percept));
|
|
||||||
//
|
|
||||||
// return ret;
|
|
||||||
|
|
||||||
if (this.fares.size() == 0){ return null; }
|
|
||||||
|
|
||||||
String percept = "journey(";
|
String percept = "journey(";
|
||||||
percept = percept.concat(NotationUtils.compact(this.origin));
|
percept = percept.concat(NotationUtils.compact(this.origin));
|
||||||
@ -208,10 +233,98 @@ public class Journey implements Perceptable{
|
|||||||
percept = percept.substring(0, percept.lastIndexOf(","));
|
percept = percept.substring(0, percept.lastIndexOf(","));
|
||||||
percept = percept.concat("])");
|
percept = percept.concat("])");
|
||||||
|
|
||||||
|
// queryid annotation
|
||||||
|
percept = percept.concat("[query(");
|
||||||
|
percept = percept.concat(this.getQueryid());
|
||||||
|
percept = percept.concat(")]");
|
||||||
|
|
||||||
|
|
||||||
LinkedList<Literal> ret = new LinkedList<Literal>();
|
LinkedList<Literal> ret = new LinkedList<Literal>();
|
||||||
ret.add(Literal.parseLiteral(percept));
|
ret.add(Literal.parseLiteral(percept));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Generates a beliefs representation of the </code>Journey</code>.
|
||||||
|
* The journey is represented by several beliefs, all of them with the
|
||||||
|
* same value in the from, to, departure and arrival time fields, but
|
||||||
|
* different fares. The exact representation is presented below:</p>
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>journey(madrid, ciudad_real, time(10,15), time(11,5), fare(turista, 22.5))</li>
|
||||||
|
* <li>journey(madrid, ciudad_real, time(10,15), time(11,5), fare(preferente, 35))</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* TODO: when it is unfloded, it might be usefull if it includes, as
|
||||||
|
* annotation, an id that represents the journey, to easily join the
|
||||||
|
* literals.
|
||||||
|
*
|
||||||
|
* @return List with literals that represent the journey. All of the
|
||||||
|
* literals will have the same, from, to, departure and arrival
|
||||||
|
* time value, but different fares.
|
||||||
|
*/
|
||||||
|
private List<Literal> unfoldPercepts() {
|
||||||
|
|
||||||
|
LinkedList<Literal> ret = new LinkedList<Literal>();// returning list
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
String perceptFare = percept.concat("fare(");
|
||||||
|
perceptFare = perceptFare.concat(NotationUtils.compact(fareName));
|
||||||
|
perceptFare = perceptFare.concat(", ");
|
||||||
|
perceptFare = perceptFare.concat(fares.get(fareName));
|
||||||
|
perceptFare = perceptFare.concat(") ");
|
||||||
|
perceptFare = perceptFare.concat(")"); // close journey
|
||||||
|
|
||||||
|
// queryid annotation
|
||||||
|
perceptFare = perceptFare.concat("[query(");
|
||||||
|
perceptFare = perceptFare.concat(this.getQueryid());
|
||||||
|
perceptFare = perceptFare.concat(")]");
|
||||||
|
|
||||||
|
ret.add(Literal.parseLiteral(perceptFare));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Try toPercepts method */
|
||||||
|
public static void main(String[]args) {
|
||||||
|
Journey j = new Journey();
|
||||||
|
j.setArrivalTime("10.00");
|
||||||
|
j.setDepartureTime("8:50");
|
||||||
|
j.setDestination("ciudad real");
|
||||||
|
j.setDuration("");
|
||||||
|
j.setOrigin("madrid");
|
||||||
|
j.setQueryid("123456");
|
||||||
|
|
||||||
|
Map<String, String> fares = new HashMap<String, String>();
|
||||||
|
fares.put("turista", "22.5");
|
||||||
|
fares.put("preferente", "38.5");
|
||||||
|
fares.put("turista niño", "16.0");
|
||||||
|
fares.put("preferente niño", "28.5");
|
||||||
|
j.setFares(fares);
|
||||||
|
|
||||||
|
System.out.println(j.toPercepts());
|
||||||
|
// System.out.println(j.foldPercepts());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_DATES_NODENAME;
|
|||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_DATES_RETURN_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_DATES_RETURN_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_DOMAINS_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_DOMAINS_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_FROM_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_FROM_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TO_NODENAME;
|
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_LOCATIONS_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_LOCATIONS_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_MAX_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_MAX_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_MIN_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_MIN_NODENAME;
|
||||||
@ -15,6 +14,7 @@ import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_PRICE_NODENAME;
|
|||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_DEPART_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_DEPART_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_RETURN_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TIME_RETURN_NODENAME;
|
||||||
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TO_NODENAME;
|
||||||
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TRAVEL_NODENAME;
|
import static es.upm.dit.gsi.sojason.services.nlu.NLUModel.JSON_TRAVEL_NODENAME;
|
||||||
import jason.asSyntax.Literal;
|
import jason.asSyntax.Literal;
|
||||||
|
|
||||||
@ -32,7 +32,6 @@ import org.codehaus.jackson.JsonNode;
|
|||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
|
||||||
import es.upm.dit.gsi.jason.utils.NotationUtils;
|
import es.upm.dit.gsi.jason.utils.NotationUtils;
|
||||||
import es.upm.dit.gsi.sojason.Web40Model;
|
|
||||||
import es.upm.dit.gsi.sojason.beans.NLUTravel;
|
import es.upm.dit.gsi.sojason.beans.NLUTravel;
|
||||||
import es.upm.dit.gsi.sojason.services.WebServiceConnector;
|
import es.upm.dit.gsi.sojason.services.WebServiceConnector;
|
||||||
|
|
||||||
|
@ -46,15 +46,30 @@ public class RenfeScrapper implements WebServiceConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
List<Perceptable> schedule = getSchedule ( params[0].toString(),
|
String queryid = params[0].toString();
|
||||||
params[1].toString(),
|
List<Perceptable> schedule = getSchedule ( params[1].toString(),
|
||||||
params[2].toString(),
|
params[2].toString(),
|
||||||
params[3].toString(),
|
params[3].toString(),
|
||||||
params[4].toString());
|
params[4].toString(),
|
||||||
|
params[5].toString());
|
||||||
|
|
||||||
|
System.out.println(">>>" + schedule);
|
||||||
// prepare response
|
// prepare response
|
||||||
Collection<Literal> res = new LinkedList<Literal>();
|
Collection<Literal> res = new LinkedList<Literal>();
|
||||||
for (Perceptable travel : schedule){
|
for (Perceptable travel : schedule){
|
||||||
|
System.out.println(">>>" + travel);
|
||||||
|
if(travel instanceof Journey){
|
||||||
|
((Journey)travel).setQueryid(queryid); // add the query id
|
||||||
|
}
|
||||||
|
System.out.println(">>>" + travel.toPercepts());
|
||||||
|
|
||||||
|
|
||||||
|
List<Literal> list = travel.toPercepts();
|
||||||
|
for(Literal l : list){
|
||||||
|
System.out.println("Anota" + l.getAnnots());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
res.addAll(travel.toPercepts());
|
res.addAll(travel.toPercepts());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -67,7 +82,7 @@ public class RenfeScrapper implements WebServiceConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateParams(String... params) {
|
public boolean validateParams(String... params) {
|
||||||
if(params.length != 5){
|
if(params.length != 6){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user