GermanDeliQuery.java
Go to the documentation of this file.
00001 package edu.tum.cs.ias.knowrob.mod_dialog.queries;
00002 
00003 import java.util.HashMap;
00004 import java.util.Vector;
00005 import java.util.regex.Matcher;
00006 import java.util.regex.Pattern;
00007 
00008 import de.tum.in.fipm.kipm.gui.visualisation.applets.CommunicationVisApplet;
00009 import edu.tum.cs.ias.knowrob.json_prolog.PrologValue;
00010 import edu.tum.cs.ias.knowrob.mod_dialog.DialogModule;
00011 
00012 
00013 
00014 public class GermanDeliQuery extends SimpleTopLevelQuery {
00015         
00016         public GermanDeliQuery(DialogModule mod) {
00017                 super(mod);
00018         }
00019 
00020         @Override
00021         public String match(String q) {
00022 
00023                 Matcher matcher = Pattern.compile("^(([R|r]osie)?[,]* would you make us some pancakes\\?)").matcher(q);
00024                 if(matcher.find()) {
00025                         
00026                         // visualize communication
00027                         String shortquery = "rdf_triple(knowrob:forCommand, A, 'make pancakes').\n";
00028                 CommunicationVisApplet.visualizeCommunication(shortquery, null, "rosie.png", "wikihow.png");
00029 
00030                         dialog_module.setVoice("dfki-prudence");
00031                         
00032                         String res = "A = 'http://ias.cs.tum.edu/kb/knowrob.owl#MakePancakesUsingPancakeMix'.\n";
00033                         
00034                         dialog_module.ehow_window.setVisible( true );
00035                         
00036                         // remember plan identifier
00037                         this.dialog_module.setCurrentObject("knowrob:'MakePancakesUsingPancakeMix'");
00038                         
00039                         // visualize communication
00040                 CommunicationVisApplet.visualizeCommunication(null, res, "rosie.png", "wikihow.png");
00041 
00042                         return "Sure, let me look up instructions on the web.";
00043                 }
00044                 
00045 
00046                 matcher = Pattern.compile("^([W|w]hat is this\\?)").matcher(q);
00047                 if(matcher.find()) {
00048                         
00049                         
00050                         dialog_module.setVoice("dfki-prudence");
00051                         
00052                         
00053                         String query = "latest_perception_of_type('http://ias.cs.tum.edu/kb/germandeli.owl#GermanDeliObject', A), " +
00054                                         "rdf_has(A, knowrob:objectActedOn, Obj), rdf_has(Obj, rdf:type, ObjT)";
00055                 CommunicationVisApplet.visualizeCommunication(query, null, "", "rosie.png");
00056                 
00057                 HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00058 
00059 
00060                 String obj = ""; 
00061                 String type = "";
00062                         
00063                 if(qres==null)
00064                         return null;
00065                 
00066                 if(qres.containsKey("Obj") && qres.containsKey("ObjT")) {
00067                         obj = qres.get("Obj").toString(); obj=obj.substring(1, obj.length()-1);
00068 
00069                                 this.dialog_module.setCurrentObject(obj);
00070                         type = qres.get("ObjT").toString(); type=type.substring(1, type.length()-1);
00071                 } else {
00072                         return null;
00073                 } 
00074 
00075                 
00076                         if(obj.contains("#")) {
00077                                 obj=DialogModule.removeSingleQuotes(obj).split("#")[1];
00078                         }
00079                         if(type.contains("#")) {
00080                                 type=DialogModule.removeSingleQuotes(type).split("#")[1];
00081                         }
00082                                                 
00083 
00084                         String res = "It is a "+type+".\n";
00085                         
00086                         
00087                 CommunicationVisApplet.visualizeCommunication(null, "Obj="+obj+", ObjT="+type, "", "rosie.png");
00088 
00089                         return res;
00090                 }
00091                 
00092                 
00093                 
00094                 
00095                 matcher = Pattern.compile("^([W|w]hat do you need for that\\?)").matcher(q);
00096                 if(matcher.find()) {
00097                         
00098                         q=this.dialog_module.getCurrentObject();
00099                         
00100                         // visualize communication
00101                         
00102                         String obj = "Mondamin_Pfannkuchen_Teig_Mix_200g_Pancake_Mix";
00103                         String query = "owl_direct_subclass_of('http://ias.cs.tum.edu/kb/germandeli.owl#"+obj+"', R)," +
00104                                         "owl_has(R, owl:onProperty, germandeli:productID)," +
00105                                         "owl_has(R, owl:hasValue, literal(type(xsd:string, ID)))";
00106                         String printquery = "owl_direct_subclass_of(http://ias.cs.tum.edu/kb/germandeli.owl#"+obj+", R), \n" +
00107                         "owl_has(R, owl:onProperty, germandeli:productID), \n" +
00108                         "owl_has(R, owl:hasValue, literal(type(xsd:string, ID))).";
00109                 CommunicationVisApplet.visualizeCommunication(printquery, null, null, "rosie.png");
00110                 
00111                         dialog_module.setVoice("dfki-prudence");
00112                         
00113                 String id = "";
00114                 HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00115                 if(qres.containsKey("ID")) {
00116                         id = qres.get("ID").toString(); id=id.substring(1, id.length()-1);
00117                 }
00118 
00119                         dialog_module.showImageInNewWindow("/work/germandeli/images/"+id+".jpg");
00120 
00121                         String res = "I need some pancake mix like this one I found on the German Deli website.\n";
00122                         
00123                         // remember object
00124                         this.dialog_module.setCurrentObject("knowrob:'PancakeMix'");
00125                         
00126                         // visualize communication
00127                 CommunicationVisApplet.visualizeCommunication(null, res, "", "rosie.png");
00128 
00129                         return res;
00130                 }
00131                 
00132                 
00133                 
00134                 matcher = Pattern.compile("^([C|c]an you recognize it\\?)").matcher(q);
00135                 if(matcher.find()) {
00136                         
00137                         q=this.dialog_module.getCurrentObject();
00138                         
00139                         // visualize communication
00140                         
00141                         String obj = "Mondamin_Pfannkuchen_Teig_Mix_200g_Pancake_Mix";
00142                         String query = "owl_direct_subclass_of('http://ias.cs.tum.edu/kb/germandeli.owl#"+obj+"', R)," +
00143                         "owl_has(R, owl:onProperty, germandeli:productID)," +
00144                         "owl_has(R, owl:hasValue, literal(type(xsd:string, ID)))";
00145                         String printquery = "owl_direct_subclass_of(http://ias.cs.tum.edu/kb/germandeli.owl#"+obj+", R), \n" +
00146                         "owl_has(R, owl:onProperty, germandeli:productID), \n" +
00147                         "owl_has(R, owl:hasValue, literal(type(xsd:string, ID))).";
00148                 CommunicationVisApplet.visualizeCommunication(printquery, null, null, "rosie.png");
00149 
00150                         dialog_module.setVoice("dfki-prudence");
00151                         
00152                 String id = "";
00153                 HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00154                 if(qres.containsKey("ID")) {
00155                         id = qres.get("ID").toString(); id=id.substring(1, id.length()-1);
00156                 }
00157                         dialog_module.showImageInNewWindow("/work/germandeli/images_with_keypoints/"+id+".jpg");
00158                         
00159                         
00160                         String res = "Yes, using SIFT features.\n"; 
00161                         CommunicationVisApplet.visualizeCommunication(null, res, "", "rosie.png");
00162                         
00163                         return res;
00164                 }
00165                 
00166                 
00167                 
00168                 matcher = Pattern.compile("^([W|w]here would you search for it\\?)").matcher(q);
00169                 if(matcher.find()) {
00170                         
00171                         q=this.dialog_module.getCurrentObject();
00172                         dialog_module.setVoice("dfki-prudence");
00173                         
00174                         
00175                         String query = "storagePlaceForBecause(StLoc, knowrob:'PancakeMix', Why), highlight_object(StLoc, _)";
00176                 CommunicationVisApplet.visualizeCommunication(query, null, "", "rosie.png");
00177                 
00178                 HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00179 
00180 
00181                 String loc = ""; 
00182                 String why = "";
00183                         
00184                 if(qres.containsKey("StLoc") && qres.containsKey("Why")) {
00185                                 loc = qres.get("StLoc").toString(); loc=loc.substring(1, loc.length()-1);
00186                                 why = qres.get("Why").toString(); why=why.substring(1, why.length()-1);
00187                 } else {
00188                         return null;
00189                 } 
00190 
00191                 
00192                         if(loc.contains("#")) {
00193                                 loc=DialogModule.removeSingleQuotes(loc).split("#")[1];
00194                         }
00195                         if(why.contains("#")) {
00196                                 why=DialogModule.removeSingleQuotes(why).split("#")[1];
00197                         }
00198                                                 
00199 
00200                         String res = "In "+loc+", because it is "+why+".\n";
00201                         
00202                 CommunicationVisApplet.visualizeCommunication(null, "StLoc="+loc+", Why="+why, "", "rosie.png");
00203 
00204                         return res;
00205                 }
00206                 
00207                 
00208                 
00209                 matcher = Pattern.compile("^([C|c]an you get the pancake mix from the fridge\\?)").matcher(q);
00210                 if(matcher.find()) {
00211                         
00212 
00213                 String query = "returnMissingCapsForAction(srdl_action:'GetObjectFromRefrigerator',  rosie:'TUM_Rosie_RobotInstance1', Missing)";
00214 
00215                         // visualize communication
00216                 CommunicationVisApplet.visualizeCommunication(query, null, "", "rosie.png");
00217                 dialog_module.setVoice("dfki-prudence");
00218                 
00219                 
00220                         HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00221 
00222                         String res = "No.\n";
00223                         if(qres==null) {
00224                                 return "Yes.\n";
00225                         } else {
00226                                 
00227                                 if(qres!=null && qres.containsKey("Missing")&&qres.get("Missing").get(0).islist()) {
00228                                         
00229                                         
00230                                         // visualize communication
00231                                 CommunicationVisApplet.visualizeCommunication(null,"Missing = "+qres.get("Missing").get(0).toString(), "", "rosie.png");
00232 
00233                                         
00234                                         Vector<PrologValue> caps = (Vector<PrologValue>)qres.get("Missing").get(0).getValue();
00235 
00236                                         res = "No, because I am missing the capabilities for ";
00237                                         for(int i=0;i<caps.size();i++) {
00238                                         
00239                                                 if(caps.get(i)==null)
00240                                                         continue;
00241                                                 
00242                                                 String cap=caps.get(i).toString();
00243                                                 if(cap.contains("#")) {
00244                                                         cap=DialogModule.removeSingleQuotes(cap).split("#")[1];
00245                                                 }
00246                                                 res+=cap;
00247                                                 
00248                                                 if(i==caps.size()-2) {
00249                                                         res+=", and ";
00250                                                 } else if (i==caps.size()-1) {
00251                                                         res+=".\n";
00252                                                 } else { 
00253                                                         res+=" ";
00254                                                 }
00255                                         }
00256                                         
00257                                 }
00258                         }
00259                         
00260                         return res;
00261                 }
00262                 
00263 
00264                 matcher = Pattern.compile("^([J|j]ames show me a location that can be reached by rosie)").matcher(q);
00265                 if(matcher.find()) {
00266                         
00267                         q=this.dialog_module.getCurrentObject();
00268                         dialog_module.setVoice("dfki-prudence");
00269                         
00270                         
00271                         // visualize communication
00272                         String query = "(visualize-location-designator ((on table) (name kitchen-island) (in reach)) ?_)";
00273                 CommunicationVisApplet.visualizeCommunication(query, null, "", "pr2.jpg");
00274 
00275                 DialogModule.executeLispPrologQuery(query);
00276                 
00277                         
00278                         String res = "This is the distribution.\n"; 
00279                         CommunicationVisApplet.visualizeCommunication(null, res, "", "pr2.jpg");
00280 
00281                         return res;
00282                 }
00283 
00284                 
00285                 matcher = Pattern.compile("^([J|j]ames[,]* can you get the pancake mix from the fridge\\?)").matcher(q);
00286                 if(matcher.find()) {
00287                         
00288                 
00289                 // if query fails no capabilities are missing, therefore 'Yes'
00290                 String query = "returnMissingCapsForAction(srdl_action:'GetObjectFromRefrigerator',  pr2:'PR2_Instance1', Missing)";
00291 
00292                         // visualize communication
00293                 CommunicationVisApplet.visualizeCommunication(query, null, "", "pr2.jpg");
00294                 dialog_module.setVoice("dfki-obadiah");
00295 
00296                 
00297                         HashMap<String, Vector<PrologValue>> qres = DialogModule.executeJSONPrologQuery(query);
00298 
00299                         String res = "No.\n";
00300                         if(qres==null) {
00301                                 CommunicationVisApplet.visualizeCommunication(null,"Missing=[]", "", "pr2.jpg");
00302                                 return "Yes.\n";                        
00303                         }
00304                 
00305                         // visualize communication
00306                 CommunicationVisApplet.visualizeCommunication(null, "No.", "", "pr2.jpg");
00307 
00308                         return res;
00309                 }
00310 
00311                 
00312                 
00313                 matcher = Pattern.compile("^([J|j]ames[,]* where can you put it down\\?)").matcher(q);
00314                 if(matcher.find()) {
00315                         
00316                         // visualize communication
00317                         String shortquery = "James, where can you put it down?";
00318                 CommunicationVisApplet.visualizeCommunication(shortquery, null, "", "pr2.jpg");
00319                         dialog_module.setVoice("dfki-obadiah");
00320                         
00321                         
00322                         String res = "Right over here.\n";
00323                         
00324                         // visualize communication
00325                 CommunicationVisApplet.visualizeCommunication(null, res, "", "pr2.jpg");
00326 
00327                         return res;
00328                 }
00329 
00330 
00331                 
00332                 return null;
00333         }
00334 
00335         
00336 
00337 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


mod_dialog
Author(s): Moritz Tenorth
autogenerated on Tue Apr 16 2013 00:38:25