Permalink
Browse files

Can now only give travel method

  • Loading branch information...
1 parent 0e42679 commit a73a7852064c2326f9f11ba03a3ae580f229a9ee @phyrex1an committed May 22, 2011
View
Binary file not shown.
@@ -284,11 +284,12 @@ public FunStrings concreteQuestion() {
}
public class Leg {
- Leg(Waypoint destination) {
+ Leg(Waypoint destination, TravelMethod method) {
this.destination.waypoint = destination;
+ this.method = method;
}
private WaypointInfo destination = new WaypointInfo(null);
- private TravelMethod method = TravelMethod.UNKNOWN;
+ private TravelMethod method;
public Waypoint destination() {
return destination.waypoint;
@@ -312,6 +313,7 @@ public void method(TravelMethod method) {
}
}
+ private TravelMethod defaultMethod = TravelMethod.UNKNOWN;
private WaypointInfo startAt = new WaypointInfo(null);
private List<Leg> travelPath;
private SearchApi api;
@@ -322,6 +324,7 @@ public DirectionsForm(SearchApi api) {
}
public void reset() {
+ this.defaultMethod = TravelMethod.UNKNOWN;
this.startAt.waypoint = new CurrentLocation();
this.travelPath = new ArrayList<Leg>();
}
@@ -367,7 +370,10 @@ public DirectionsForm startAt(String address) {
}
private void byMethod(TravelMethod method) {
- travelPath.get(travelPath.size()-1).method = method;
+ this.defaultMethod = method;
+ if (travelPath.size() > 0) {
+ travelPath.get(travelPath.size()-1).method = method;
+ }
}
public void byCar() {
@@ -379,7 +385,7 @@ public void byFoot() {
}
public DirectionsForm travelTo(Waypoint destination) {
- this.travelPath.add(new Leg(destination));
+ this.travelPath.add(new Leg(destination, this.defaultMethod));
return this;
}
@@ -395,11 +401,50 @@ public DirectionsForm andBackHere() {
return new ArrayList<Leg>(travelPath);
}
+
+ private class GoToQuestion implements Question {
+ private DirectionsForm form;
+
+ GoToQuestion(DirectionsForm form) {
+ this.form = form;
+ }
+ public boolean answerQuestion(FunApp answer) {
+ return TranslatorApi.fromJPGFTree(form, answer);
+ }
+
+ public FunStrings concreteQuestion() {
+ String how;
+ String with = null;
+ List<FunApp> what = new ArrayList<FunApp>();
+ switch (this.form.defaultMethod) {
+ case DRIVE:
+ with = "Car";
+ // no break
+ case WALK:
+ with = (with == null) ? "Walk" : with ;
+ how = "WhereToGoBy";
+ what.add(new FunApp(with, Collections.EMPTY_LIST));
+ break;
+ case UNKNOWN:
+ how = "WhereToGo";
+ break;
+ default:
+ throw new RuntimeException("Exhaustive switch wasn't exhaustive.");
+ }
+ System.out.println(new FunApp(how, what).toString());
+ return new FunStrings(new FunApp(how, what), Collections.EMPTY_LIST);
+ }
+ }
+
public List<Question> questions() {
List<Question> questions = new ArrayList<Question>();
questions.addAll(this.startAt.questions(this));
- for (Leg l : this.travelPath) {
- questions.addAll(l.questions(this));
+ if (this.travelPath.size() == 0) {
+ questions.add(new GoToQuestion(this));
+ } else {
+ for (Leg l : this.travelPath) {
+ questions.addAll(l.questions(this));
+ }
}
return questions;
}
@@ -21,6 +21,10 @@ public static boolean translateString(String inputString, DirectionsForm form, I
return false;
}
FunApp f = (FunApp) parseString(inputString.toLowerCase(), pgffile);
+ return fromJPGFTree(form, f);
+ }
+
+ public static boolean fromJPGFTree(DirectionsForm form, FunApp f) {
if (f == null) {
return false;
} else if(f.getIdent().equals("INeedWantTo")){
@@ -1,7 +1,7 @@
abstract Questions = {
flags startcat = Question ;
cat
- Question; DummyString ;
+ Question; DummyString; TravelMethod ;
fun
AskGoTo : DummyString -> Question ;
@@ -11,4 +11,8 @@ abstract Questions = {
WalkOrCar : Question ;
WalkOrCarTo : DummyString -> Question ;
UnrecognizedWaypoint : DummyString -> Question ;
+ WhereToGo : Question ;
+ WhereToGoBy : TravelMethod -> Question ;
+ Car : TravelMethod ;
+ Walk : TravelMethod ;
}
Binary file not shown.
Binary file not shown.
@@ -8,5 +8,9 @@ concrete QuestionsEng of Questions = {
DString3 = {s = "dummy, dummy or dummy"} ;
WalkOrCar = {s = "Do you want to walk or go by car ?"} ;
WalkOrCarTo d = {s = "Do you want to walk or go by car to" ++ d.s ++ "?"} ;
- UnrecognizedWaypoint d = {s = "Didnt recognize " ++ d.s ++ ", where do you want to go?"} ;
+ UnrecognizedWaypoint d = {s = "Didnt recognize " ++ d.s ++ ", where do you want to go?"} ;
+ WhereToGo = {s = "Where do you want to go?" } ;
+ WhereToGoBy d = {s = "Where do you want to " ++ d.s ++ "?"} ;
+ Car = {s = "drive"} ;
+ Walk = {s = "walk"} ;
}
Binary file not shown.
@@ -9,4 +9,8 @@ concrete QuestionsSwe of Questions = {
WalkOrCar = {s = "Vill du gå eller åka bil ?"} ;
WalkOrCarTo d = {s = "Vill du gå eller åka bil till" ++ d.s ++ "?"} ;
UnrecognizedWaypoint d = {s = "Känner inte igen " ++ d.s ++ ", vart vill du åka?"} ;
+ WhereToGo = {s = "Vart vill du åka?" } ;
+ WhereToGoBy d = {s = "Vart vill du " ++ d.s ++ "?"} ;
+ Car = {s = "köra"} ;
+ Walk = {s = ""} ;
}

0 comments on commit a73a785

Please sign in to comment.