Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'refs/heads/master' of

git@github.com:phyrex1an/PathPal.git
  • Loading branch information...
commit 23209569d66606ec145cdb2deb676467e90a9e3c 2 parents b735d0b + 5affa6a
Mattis Jeppsson mattis authored
BIN  res/raw/locator.pgf
View
Binary file not shown
49 src/org/pathpal/DirectionsForm.java
View
@@ -1,8 +1,12 @@
package org.pathpal;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
+import org.grammaticalframework.UnknownLanguageException;
+import org.grammaticalframework.Linearizer.LinearizerException;
+import org.pathpal.translator.Fun;
import org.pathpal.translator.FunApp;
import com.amelie.driving.DrivingDirections.Mode;
@@ -38,6 +42,16 @@ public Mode realMode() {
}
}
+ public class FunStrings {
+ public Fun f;
+ public List<String> l;
+
+ public FunStrings(Fun f, List<String> l) {
+ this.f = f;
+ this.l = l;
+ }
+ }
+
// A waypoint is a point along the travel path as entered by the user
// for example "closest pet store", "Ullevi" or "200m a head"
@@ -51,7 +65,7 @@ public Mode realMode() {
// A question direction towards the user with the intent to resolve some
// ambiguous data
public interface Question {
- public String concreteQuestion();
+ public FunStrings concreteQuestion();
public boolean answerQuestion(FunApp answer);
}
@@ -97,16 +111,27 @@ public boolean answerQuestion(FunApp answer) {
return false;
}
- public String concreteQuestion() {
- String question = "Do you want to go to ";
- String places = "";
- for (AddressPlace place : this.waypoints) {
- if (!places.equals("")) {
- places = places + ", ";
- }
- places = places + place.description;
+ public FunStrings concreteQuestion() {
+ FunApp fa;
+ LinkedList<Fun> args = new LinkedList<Fun>();
+ switch (this.waypoints.size()) {
+ case 1:
+ fa = new FunApp("DString1", args);
+ break;
+ case 2:
+ fa = new FunApp("DString2", args);
+ break;
+ case 3:
+ fa = new FunApp("DString3", args);
+ break;
+ default:
+ throw new RuntimeException("Not enough DStringS");
+ }
+ List<String> sargs = new ArrayList<String>();
+ for (AddressPlace arg : this.waypoints) {
+ sargs.add(arg.description);
}
- return question + places + "?";
+ return new FunStrings(fa, sargs);
}
}
@@ -166,8 +191,8 @@ public boolean answerQuestion(FunApp answer) {
return true;
}
- public String concreteQuestion() {
- return "Do you want to walk or go by car?";
+ public FunStrings concreteQuestion() {
+ return new FunStrings(new FunApp("WalkOrCar", new LinkedList<Fun>()), new LinkedList<String>());
}
}
66 src/org/pathpal/GMapsActivity.java
View
@@ -6,6 +6,8 @@
import java.util.List;
import org.grammaticalframework.UnknownLanguageException;
+import org.grammaticalframework.Linearizer.LinearizerException;
+import org.pathpal.DirectionsForm.FunStrings;
import org.pathpal.DirectionsForm.Leg;
import org.pathpal.DirectionsForm.Question;
import org.pathpal.DirectionsForm.Waypoint;
@@ -16,6 +18,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Resources.NotFoundException;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -217,17 +220,16 @@ private void updatePath(){
}
/**
- * Checks if the directionForm till has some unanswered question.
+ * Checks if the directionForm still has some unanswered question.
* If so, show a dialog where the user can answer a question
*/
public void questionHandler(){
// if there are questions then take care of them
if(directionForm.questions().size()>0){
- System.out.println("QUESTIONS: " + directionForm.questions().size());
activeQuestion = directionForm.questions().get(0); // select a question as active
removeDialog(QUESTION_ID); // clean up the dialog first
showDialog(QUESTION_ID); // then show the dialog
- }
+ }
}
@Override
@@ -242,38 +244,28 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Get your current location and create a new SearchApi with your current location
AddressPlace l = new AddressPlace(myLocationOverlay.getGeoPoint(), "You are here");
-
+ api = new SearchApi(new Geocoder(getApplicationContext()), l);
+ api.geocoder = new Geocoder(getApplicationContext());
// create a new directionForm if needed
if(directionForm == null){
- api = new SearchApi(new Geocoder(getApplicationContext()), l);
- api.geocoder = new Geocoder(getApplicationContext());
directionForm = new DirectionsForm(api);
- } else {
- api.startLocation = l;
}
-
// The TranslatorApi update the directionForm
// the inputstring nlp is passed to the TranslatorApi
try {
- boolean work = TranslatorApi.translateString(nlp, directionForm, getResources().openRawResource(R.raw.locator));
- if(!work){
- System.out.println("ERROR: Could not parse");
- }
+ TranslatorApi.translateString(nlp, directionForm, getResources().openRawResource(R.raw.locator));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (UnknownLanguageException e1) {
e1.printStackTrace();
- }
-
-
- // Test data to use as long as the TranslatorApi is not working properly
- // directionForm.startAt("ullevi");
- // directionForm.travelTo("gamla ullevi");
- // directionForm.travelTo("brunnsparken");
+ } catch (NullPointerException e){
+ showDialog(UNKOWN_PARSE_STRING_ID);
+ return;
+ }
// do all the overlay drawings on the map
updatePath();
@@ -287,6 +279,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
final int NO_PATH_ID = 0;
final int QUESTION_ID = 1;
final int GPS_NOT_LOADED_ID = 2;
+ final int UNKOWN_PARSE_STRING_ID = 3;
@Override
protected Dialog onCreateDialog(int id) {
@@ -316,7 +309,27 @@ else if(id == QUESTION_ID){
// TODO : Be able to know which leg/waypoint you are updating!
alert.setTitle("Need more information!");
- alert.setMessage(activeQuestion.concreteQuestion());
+ String question = "";
+ FunStrings p = activeQuestion.concreteQuestion();
+ try {
+ question = TranslatorApi.makeTranslation(p.f, p.l, getResources().openRawResource(R.raw.questions));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (LinearizerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnknownLanguageException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ alert.setMessage(question);
// Set an EditText view to get user input
final EditText input = new EditText(this);
@@ -329,8 +342,8 @@ public void onClick(DialogInterface dialog, int whichButton) {
FunApp abstractAnswer = (FunApp) TranslatorApi.parseString(value, getResources().openRawResource(R.raw.locator));
if(abstractAnswer != null){
activeQuestion.answerQuestion(abstractAnswer);
- updatePath();
}
+ updatePath();
}catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
@@ -349,6 +362,15 @@ public void onClick(DialogInterface dialog, int whichButton) {
}
});
return(alert.create());
+ }else if(id == UNKOWN_PARSE_STRING_ID){
+ AlertDialog.Builder build = new AlertDialog.Builder(this);
+ build.setMessage("I do not understand what you are saying. Please try something other..");
+ build.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+ return (build.create());
}
return d;
}
19 src/org/pathpal/TranslatorApi.java
View
@@ -23,23 +23,24 @@ public static boolean translateString(String inputString, DirectionsForm form, I
form.startAt(((FunString) f.getArgs().get(0)).getString());
form.travelTo(((FunString) f.getArgs().get(1)).getString());
} else if (f.getIdent().equals("GoTo")) {
- form.travelTo(((FunString) f.getArgs().get(0)).getString());
+ form.travelTo(((FunString) f.getArgs().get(1)).getString());
} else if (f.getIdent().equals("GoByCarTo")) {
- form.travelTo(((FunString) f.getArgs().get(0)).getString());
+ form.travelTo(((FunString) f.getArgs().get(1)).getString());
form.byCar();
} else if (f.getIdent().equals("GoByCarFromTo")) {
- form.startAt(((FunString) f.getArgs().get(0)).getString());
- form.travelTo(((FunString) f.getArgs().get(1)).getString());
+ form.startAt(((FunString) f.getArgs().get(1)).getString());
+ form.travelTo(((FunString) f.getArgs().get(2)).getString());
form.byCar();
} else if (f.getIdent().equals("GoFromToVia")){
- form.startAt(((FunString) f.getArgs().get(0)).getString());
+ form.startAt(((FunString) f.getArgs().get(1)).getString());
+ form.travelTo(((FunString) f.getArgs().get(3)).getString());
+ form.startAt(((FunString) f.getArgs().get(3)).getString());
form.travelTo(((FunString) f.getArgs().get(2)).getString());
- form.startAt(((FunString) f.getArgs().get(2)).getString());
- form.travelTo(((FunString) f.getArgs().get(1)).getString());
} else if (f.getIdent().equals("GoToVia")){
- form.startAt(((FunString) f.getArgs().get(1)).getString());
- form.travelTo(((FunString) f.getArgs().get(0)).getString());
+ form.travelTo(((FunString) f.getArgs().get(2)).getString());
+ form.startAt(((FunString) f.getArgs().get(2)).getString());
+ form.travelTo(((FunString) f.getArgs().get(1)).getString());
} else if (f.getIdent().equals("WalkOrTrans")){
if (((FunApp)f.getArgs().get(0)).getIdent().equals("Walking")){
form.byFoot();
17 src/org/pathpal/grammar/Locator.gf
View
@@ -7,19 +7,22 @@ abstract Locator = {
Answer;
TransItem;
WalkItem;
+ NeedWant;
fun
- GoTo : Dummy -> Phrase ;
- GoByCarTo : Dummy -> Phrase ;
- GoByCarFromTo : Dummy -> Dummy -> Phrase ;
- GoToVia : Dummy -> Dummy -> Phrase;
- GoFromToVia : Dummy -> Dummy -> Dummy -> Phrase;
- WalkTo : Dummy -> Phrase;
+ GoTo : NeedWant -> Dummy -> Phrase ;
+ GoByCarTo : NeedWant -> Dummy -> Phrase ;
+ GoByCarFromTo : NeedWant -> Dummy -> Dummy -> Phrase ;
+ GoToVia : NeedWant -> Dummy -> Dummy -> Phrase;
+ GoFromToVia : NeedWant -> Dummy -> Dummy -> Dummy -> Phrase;
+ WalkTo : NeedWant -> Dummy -> Phrase;
DString : Dummy ;
- GoFromTo : Dummy -> Dummy -> Phrase;
+ GoFromTo : NeedWant -> Dummy -> Dummy -> Phrase;
FindStore : StoreType -> Phrase ;
WalkOrTrans : Answer -> Phrase;
Walking : WalkItem -> Answer;
Transportation : TransItem -> Answer;
+ Need: NeedWant;
+ Want: NeedWant;
Walk,Walk2,Foot : WalkItem;
Car,Vehicle : TransItem;
TBy: TransItem -> TransItem;
BIN  src/org/pathpal/grammar/Locator.gfo
View
Binary file not shown
BIN  src/org/pathpal/grammar/Locator.pgf
View
Binary file not shown
23 src/org/pathpal/grammar/LocatorEng.gf
View
@@ -1,17 +1,23 @@
+-- TODO
+-- need/want
+-- before i go to göteborg i want to go to abc
concrete LocatorEng of Locator = {
lincat
- Phrase,StoreType,Answer,Dummy,TransItem,WalkItem= {s : Str} ;
+ Phrase,StoreType,Answer,Dummy,TransItem,WalkItem,NeedWant= {s : Str} ;
lin
- GoTo it = {s = "I need to go to" ++ it.s} ;
- GoByCarTo it = {s = "I want to go by car to" ++ it.s} ;
- GoByCarFromTo i i' = {s = "I want to go by car from" ++ i.s ++ "to" ++ i'.s} ;
+ GoTo nw it = {s = "I" ++ nw.s ++ "to go to" ++ it.s} ;
+ GoByCarTo nw it = {s = "I" ++ nw.s ++ "to go by car to" ++ it.s} ;
+ GoByCarFromTo nw i i' = {s = "I" ++ nw.s ++ "to go by car from" ++ i.s ++ "to" ++ i'.s} ;
- GoToVia i i' = {s = "I want to go to" ++ i.s ++ "via" ++ i'.s} ;
- GoFromToVia i i' i'' = {s = "I want to go from" ++ i.s ++ "to" ++ i'.s ++ "via" ++ i''.s} ;
+ GoToVia nw i i' = {s = "I" ++ nw.s ++ "to go to" ++ i.s ++ "via" ++ i'.s} ;
+ GoFromToVia nw i i' i'' = {s = "I" ++ nw.s ++ "to go from" ++ i.s ++ "to" ++ i'.s ++ "via" ++ i''.s} ;
- WalkTo it = {s = "I want to walk to" ++ it.s} ;
+ WalkTo nw it = {s = "I" ++ nw.s ++ "to walk to" ++ it.s} ;
- GoFromTo it it' = {s = "I need to go from" ++ it.s ++ "to" ++ it'.s} ;
+ GoFromTo nw it it' = {s = "I" ++ nw.s ++ "to go from" ++ it.s ++ "to" ++ it'.s} ;
+
+ Need = {s = "need"};
+ Want = {s = "want"};
FindStore it = {s = "Where is the nearest" ++ it.s ++ "store"} ;
DString = {s = "dummy"} ;
@@ -22,6 +28,7 @@ concrete LocatorEng of Locator = {
Transportation i = {s = i.s} ;
+
Walk = {s ="Walk"};
Walk2 = {s ="Walking"};
Foot = {s = "By Foot"} ;
BIN  src/org/pathpal/grammar/LocatorEng.gfo
View
Binary file not shown
5 src/org/pathpal/test/translateStringTest.java
View
@@ -33,6 +33,11 @@ public void testTranslateString() throws FileNotFoundException, IOException, Unk
assertTrue(form.startAt.equals("Lixon"));
st = new FileInputStream("res/raw/locator.pgf") ;
+ assertTrue(TranslatorApi.translateString("I need to go from Dixon to Trixon via Lixon",form,st));
+ assertTrue(form.travelTo.equals("Trixon"));
+ assertTrue(form.startAt.equals("Lixon"));
+
+ st = new FileInputStream("res/raw/locator.pgf") ;
assertTrue(TranslatorApi.translateString("By Car",form,st));
assertTrue(form.byCar);
Please sign in to comment.
Something went wrong with that request. Please try again.