InstancePosition.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 
00010 import edu.tum.cs.ias.knowrob.json_prolog.PrologValue;
00011 import edu.tum.cs.ias.knowrob.mod_dialog.DialogModule;
00012 
00013 public class InstancePosition extends SimpleTopLevelQuery {
00014         
00015         public InstancePosition(DialogModule mod) {
00016                 super(mod);
00017         }
00018 
00019         @Override
00020         public String match(String q) {
00021                 
00022                 Matcher matcher = Pattern.compile("([w|W]here exactly is ([a-zA-Z0-9]*?)\\?)").matcher(q);
00023                 if(matcher.find()) {
00024                         q=matcher.group(2);
00025                         dialog_module.setCurrentObject(DialogModule.toProlog(q));
00026 
00027                         
00028                         // visualize communication
00029                         String shortquery = "rdf_triple(orientation, "+DialogModule.toProlog(q)+", Pose),\n" +
00030                         "rdf_triple(m03, Pose, X),\n" +
00031                         "rdf_triple(m13, Pose, Y),\n" +
00032                         "rdf_triple(m23, Pose, Z)";
00033                 CommunicationVisApplet.visualizeCommunication(shortquery, null, null, "rosie.png");
00034 
00035                         
00036                         String query = "rdf_triple(knowrob:orientation, "+DialogModule.toProlog(q)+", Pose)," +
00037                         "rdf_triple(knowrob:m03, Pose, literal(type('http://www.w3.org/2001/XMLSchema#float', X)))," +
00038                         "rdf_triple(knowrob:m13, Pose, literal(type('http://www.w3.org/2001/XMLSchema#float', Y)))," +
00039                         "rdf_triple(knowrob:m23, Pose, literal(type('http://www.w3.org/2001/XMLSchema#float', Z)))";
00040                 
00041                         HashMap<String, Vector<PrologValue>> res = DialogModule.executeJSONPrologQuery(query);
00042                         String x = res.get("X").toString(); x=x.substring(1, x.length()-1);
00043                         String y = res.get("Y").toString(); y=y.substring(1, y.length()-1);
00044                         String z = res.get("Z").toString(); z=z.substring(1, z.length()-1);
00045                         
00046 
00047                         // visualize communication
00048                 CommunicationVisApplet.visualizeCommunication(null, "Position: ["+x+", "+y+", "+z+"]", null, "rosie.png");
00049 
00050                         
00051                         return "At position ("+x+", "+y+", "+z+").\n"; 
00052                 }
00053                 
00054                 return null;
00055         }
00056 
00057 }
 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