PrologQueryUtils.java
Go to the documentation of this file.
00001 package edu.tum.cs.ias.knowrob.prolog;
00002 
00003 import java.io.IOException;
00004 import java.util.ArrayList;
00005 import java.util.HashMap;
00006 import java.util.Vector;
00007 
00008 import edu.tum.cs.ias.knowrob.owl.OWLThing;
00009 
00010 
00011 
00027 public class PrologQueryUtils {
00028 
00029         
00030         
00031         public static void setActionVisHighlight(String action_class) {
00032                 try {
00033                         action_class = PrologInterface.removeSingleQuotes(action_class);
00034                         PrologInterface.executeQuery("planvis_clear_highlight(_), planvis_highlight('"+ action_class +"', _)");
00035                 } catch (Exception e) {}
00036         }
00037         
00038         public static void clearActionVisHighlight() {
00039                 try {
00040                         PrologInterface.executeQuery("planvis_clear_highlight(_)");
00041                 } catch (Exception e) {}
00042         }
00043 
00044         public static void startActionVis(String recipe_class) {
00045                 recipe_class = PrologInterface.removeSingleQuotes(recipe_class);
00046                 PrologInterface.executeQuery("planvis_create(P), planvis_load('"+ recipe_class +"', _)");
00047         }
00048         
00049         public static void loadActionIntoVis(String recipe_class) {
00050                 recipe_class = PrologInterface.removeSingleQuotes(recipe_class);
00051                 PrologInterface.executeQuery("planvis_load('"+ recipe_class +"', _)");
00052         }
00053 
00054         public static void parseOwlFile(String filename) {
00055                 PrologInterface.executeQuery("owl_parser:owl_parse('"+ filename +"', false, false, true)");
00056         }
00057         
00058         
00066         public static int readNumObjectInstances(String objClass) {
00067                 
00068                 objClass = PrologInterface.removeSingleQuotes(objClass);
00069 
00070                 HashMap<String, Vector<String>> obj_insts = 
00071                         PrologInterface.executeQuery("owl_individual_of(Inst, '" + objClass + "')");
00072 
00073                 if(obj_insts!=null && obj_insts.get("Inst").size()>0) {
00074 
00075                         return obj_insts.get("Inst").size();
00076                 }
00077 
00078                 return 0;
00079         }       
00080         
00081         
00088         public static Vector<String> readAllInstancesOfClass(String owlClass) {
00089                 
00090                 owlClass = PrologInterface.removeSingleQuotes(owlClass);
00091                 
00092                 HashMap<String, Vector<String>> obj_insts = 
00093                         PrologInterface.executeQuery("owl_individual_of(Inst, '" + owlClass + "')");
00094 
00095                 if(obj_insts!=null && obj_insts.get("Inst").size()>0) {
00096 
00097                         return obj_insts.get("Inst");
00098                 }
00099                 return null;
00100         }
00101         
00102         
00109         public static String readLatestDetectionOfObjectInst(String objInst) {
00110 
00111                 objInst = PrologInterface.removeSingleQuotes(objInst);
00112                 
00113                 HashMap<String, Vector<String>> detections = 
00114                         PrologInterface.executeQuery("latest_detection_of_instance('" + objInst + "', LatestDetection)");
00115 
00116                 if(detections!=null && detections.get("LatestDetection").size()>0) {
00117                         return detections.get("LatestDetection").get(0);
00118                 }
00119                 return null;
00120         }
00121 
00122         
00129         public static String readLatestDetectionOfObjectClass(String objClass) {
00130 
00131                 objClass = PrologInterface.removeSingleQuotes(objClass);
00132                 
00133                 HashMap<String, Vector<String>> detections = 
00134                         PrologInterface.executeQuery("latest_detection_of_type('" + objClass + "', LatestDetection)");
00135 
00136                 if(detections!=null && detections.get("LatestDetection").size()>0) {
00137                         return detections.get("LatestDetection").get(0);
00138                 }
00139                 return null;
00140         }
00141         
00142         
00149         public static HashMap<String, Vector<String>> readInformationForInstance(String owlInst) {
00150 
00151                 owlInst = PrologInterface.removeSingleQuotes(owlInst);
00152                 
00153                 HashMap<String, Vector<String>> values = 
00154                         PrologInterface.executeQuery("owl_has('" + owlInst + "', P, O)");
00155                 
00156                 return values;
00157         }
00158         
00159         
00166         public static HashMap<String, Vector<String>> readInformationForClass(String owlClass) {
00167 
00168                 owlClass = PrologInterface.removeSingleQuotes(owlClass);
00169                 
00170                 HashMap<String, Vector<String>> values = 
00171                         PrologInterface.executeQuery("class_properties('" + owlClass + "', P, O)");
00172                 
00173                 return values;
00174         }
00175         
00176         public static Vector<String> readTypesOfInstance(String owlInst) {
00177 
00178                 owlInst = PrologInterface.removeSingleQuotes(owlInst);
00179                 
00180                 HashMap<String, Vector<String>> types = 
00181                         PrologInterface.executeQuery("owl_has('" + owlInst + "', rdf:type, T)");
00182                 
00183                 if(types!=null && types.get("T").size()>0) {
00184                         return types.get("T");
00185                 }
00186                 return new Vector<String>();
00187         }
00188 
00189 
00197         public static String readRecipeClass(String command) {
00198 
00199                 HashMap<String, Vector<String>> recipe_classes = 
00200                         PrologInterface.executeQuery("rdf(RecipeClass, rdfs:label, literal(like('*"+command+"*'), _))");
00201 
00202                 if(recipe_classes.get("RecipeClass").size()==0) {
00203                         return null;
00204                 } 
00205                 return recipe_classes.get("RecipeClass").firstElement();
00206         }
00207 
00208         
00209         
00216         public static Vector<String> readPrevActionInTask(String currentActInst) {
00217 
00218                 currentActInst = PrologInterface.removeSingleQuotes(currentActInst);
00219                 
00220                 HashMap<String, Vector<String>> values =
00221                         PrologInterface.executeQuery("rdf_reachable(Prev, 'http://ias.cs.tum.edu/kb/knowrob.owl#nextAction', '" + currentActInst + "')");
00222                 
00223                 if(values!=null && values.get("Prev").size()>0) {
00224                         return values.get("Prev");
00225                 }
00226                 return null;
00227         }
00228         
00229         
00238         public static String readOutputOfPrevAction(String currentActInst, String prevActionClass, String prop) {
00239 
00240                 prevActionClass = PrologInterface.removeSingleQuotes(prevActionClass);
00241                 prop = OWLThing.getShortNameOfIRI(PrologInterface.removeSingleQuotes(prop));
00242                 Vector<String> prev_acts = readPrevActionInTask(currentActInst);
00243                 prevActionClass = OWLThing.getOWLThingByShortname(prevActionClass).getIRI();
00244                 
00245                 for(String prev_act : prev_acts) {
00246                         
00247                         HashMap<String, Vector<String>> values =  // TODO: check that that action is in the same task!
00248                                 PrologInterface.executeQuery(
00249                                                 "owl_individual_of('" + PrologInterface.removeSingleQuotes(prev_act) + "', '" + prevActionClass + "'), " +
00250                                                 "rdf_has('" + PrologInterface.removeSingleQuotes(prev_act) + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#" + prop + "' , Val)");
00251 //                      "rdf_has(prev_act, 'http://ias.cs.tum.edu/kb/knowrob.owl#" + prop + "' , Val)");
00252                         
00253                         if(values!=null && values.get("Val").size()>0) {
00254                                 return PrologInterface.stripLiteralType(values.get("Val").firstElement());
00255                         }
00256                 }
00257                 return null;
00258         }
00259         
00260         
00261         
00262         
00271         public static Vector<Float> readPointXYPose(String pointInst) {
00272 
00273                 pointInst = PrologInterface.removeSingleQuotes(pointInst);
00274                 
00275                 if(PrologInterface.executeQuery("owl_individual_of('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#Point2D')") != null) {
00276 
00277                         Vector<Float> res = new Vector<Float>();
00278                         HashMap<String, Vector<String>> obj_pose = 
00279                                 PrologInterface.executeQuery("rdf_has('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#xCoord', X), " +
00280                                                 "rdf_has('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#yCoord', Y)");
00281 
00282                         if(obj_pose!=null && obj_pose.get("X").size()>0 && obj_pose.get("X").size()>0) {
00283 
00284                                 res.add(Float.valueOf(PrologInterface.stripLiteralType(obj_pose.get("X").get(0))));   // x coord
00285                                 res.add(Float.valueOf(PrologInterface.stripLiteralType(obj_pose.get("Y").get(0))));   // y coord
00286                                 return res;
00287                         }
00288                 }
00289                 return null;
00290         }
00291         
00292         
00301         public static Vector<Float> readPointXYAZPose(String pointInst) {
00302 
00303                 pointInst = PrologInterface.removeSingleQuotes(pointInst);
00304                 
00305                 if(PrologInterface.executeQuery("owl_individual_of('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#Point2D')") != null) {
00306 
00307                         Vector<Float> res = new Vector<Float>();
00308                         HashMap<String, Vector<String>> obj_pose = 
00309                                 PrologInterface.executeQuery("rdf_has('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#xCoord', X), " +
00310                                                 "rdf_has('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#yCoord', Y)," +
00311                                                 "rdf_has('" + pointInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#orientationAZ', AZ)");
00312 
00313                         if(obj_pose!=null && obj_pose.get("X").size()>0 && obj_pose.get("X").size()>0 && obj_pose.get("AZ").size()>0) {
00314 
00315                                 res.add(Float.valueOf(PrologInterface.stripLiteralType(obj_pose.get("X").get(0))));   // x coord
00316                                 res.add(Float.valueOf(PrologInterface.stripLiteralType(obj_pose.get("Y").get(0))));   // y coord
00317                                 res.add(Float.valueOf(PrologInterface.stripLiteralType(obj_pose.get("AZ").get(0))));  // orientation
00318                                 return res;
00319                         }
00320                 }
00321                 return null;
00322         }
00323         
00324 
00336         public static Vector<Float> readObjectPose(String objInst) {
00337 
00338                 objInst = PrologInterface.removeSingleQuotes(objInst);
00339                 
00340                 if(PrologInterface.executeQuery("owl_individual_of('" + objInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#EnduringThing-Localized')") != null) {
00341 
00342                         Vector<Float> res = new Vector<Float>();
00343                         HashMap<String, Vector<String>> obj_pose = 
00344                                 PrologInterface.executeQuery("current_object_pose('" + objInst + "', Pose)");
00345 
00346                         if(obj_pose.get("Pose").size()>0) {
00347 
00348                                 ArrayList<String[]> pose = PrologInterface.dottedPairsToArrayList(obj_pose.get("Pose").get(0));
00349 
00350                                 for(String[] elem : pose) {
00351                                         res.add(Float.valueOf(elem[0]));
00352                                 }
00353                                 return res;
00354                         }
00355                 }
00356                 return null;
00357         }
00358 
00359 
00371         public static Vector<Float> readObjectClassPose(String objClass) {
00372 
00373                 objClass = PrologInterface.removeSingleQuotes(objClass);
00374                 
00375                 if(PrologInterface.executeQuery("owl_subclass_of('" + objClass + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#EnduringThing-Localized')") != null) {
00376 
00377                         Vector<Float> res = new Vector<Float>();
00378                         
00379                         // read pose of first instance and set as target position
00380                         HashMap<String, Vector<String>> obj_inst = 
00381                                 PrologInterface.executeQuery("owl_individual_of(Ind, '" + objClass + "')");
00382 
00383                         if(obj_inst!=null && obj_inst.get("Ind")!=null && obj_inst.get("Ind").size()>0) {
00384 
00385                                 HashMap<String, Vector<String>> obj_pose = 
00386                                         PrologInterface.executeQuery("current_object_pose(" + obj_inst.get("Ind").get(0) + ", Pose)");
00387 
00388                                 if(obj_pose.get("Pose").size()>0) {
00389 
00390                                         ArrayList<String[]> pose = PrologInterface.dottedPairsToArrayList(obj_pose.get("Pose").get(0));
00391 
00392                                         for(String[] elem : pose) {
00393                                                 res.add(Float.valueOf(elem[0]));
00394                                         }
00395                                         return res;
00396 
00397                                 }
00398                         }
00399                 }
00400                 return null;
00401         }
00402         
00403         
00411         public static boolean owlClassExists(String owlClass) {
00412 
00413                 owlClass = PrologInterface.removeSingleQuotes(owlClass);
00414                 
00415                 HashMap<String, Vector<String>> values = 
00416                         PrologInterface.executeQuery("rdfs_subclass_of('" + owlClass + "', Super), \\+ rdf_equal('" + owlClass + "',Super)");
00417                 
00418                 if(values!=null && values.get("Super")!=null && values.get("Super").size()>0) {
00419                         
00420                         // there is a superclass different from the class itself -> class exists
00421                         return true;
00422                 }
00423                 return false;
00424         }
00425         
00426         
00432         public static String createActionInst(String currentActClass) {
00433 
00434                 currentActClass = PrologInterface.removeSingleQuotes(currentActClass);
00435                 
00436                 String inst = createOWLInst(currentActClass);
00437                 
00438                 HashMap<String, Vector<String>> st_time = 
00439                         PrologInterface.executeQuery("get_timepoint(NOW), " +
00440                                                                                  "rdf_assert(" + inst + ", 'http://ias.cs.tum.edu/kb/knowrob.owl#startTime', NOW)");
00441 
00442                 if(st_time !=null && st_time.get("NOW").size() > 0) {
00443                         return inst;
00444                 }
00445                 return null;
00446         }
00447         
00448         
00454         public static void assertActionEndTime(String actionInst) {
00455 
00456                 actionInst = PrologInterface.removeSingleQuotes(actionInst);
00457                 
00458                 PrologInterface.executeQuery("get_timepoint(NOW), " +
00459                                 "rdf_assert('" + actionInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#endTime', NOW)");
00460         }
00461         
00462         
00469         public static void linkActionInTaskContext(String actionInst, String recipeInst) {
00470 
00471                 actionInst = PrologInterface.removeSingleQuotes(actionInst);
00472                 recipeInst = PrologInterface.removeSingleQuotes(recipeInst);
00473                 
00474                 
00475                 // find subAction of recipeInst that does not yet have a nextAction
00476                 // (which should be the end of the sequence)
00477                 
00478                 HashMap<String, Vector<String>> prev_action = PrologInterface.executeQuery(
00479                                 "rdf_has('" + recipeInst + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#subAction', SUB)," +
00480                                 " not(rdf_has(SUB, 'http://ias.cs.tum.edu/kb/knowrob.owl#nextAction', _))");
00481 
00482                 // if there is any, assert the current action as nextAction (now being the end of the sequence)
00483                 if(prev_action !=null && prev_action.get("SUB").size() > 0) {
00484                         assertObjectPropertyForInst(prev_action.get("SUB").get(0), "'http://ias.cs.tum.edu/kb/knowrob.owl#nextAction'", actionInst);
00485                 }
00486 
00487                 // set actionInst as subAction of recipeInst
00488                 assertObjectPropertyForInst(recipeInst, "'http://ias.cs.tum.edu/kb/knowrob.owl#subAction'", actionInst);
00489         }
00490 
00491 
00498         public static void assertPropertiesForInstance(String inst, HashMap<String, Vector<String>> propVal) {
00499 
00500                 inst = PrologInterface.removeSingleQuotes(inst);
00501                 
00502                 for(String prop: propVal.keySet()) {
00503                         prop = PrologInterface.removeSingleQuotes(prop);
00504                         for(String val : propVal.get(prop)) {
00505                                 val = PrologInterface.removeSingleQuotes(val);
00506                                 PrologInterface.executeQuery("rdf_assert('" + inst + "', '"+prop+"', '" + val + "')");
00507                         }
00508                 }
00509         }       
00510 
00511         
00519         public static void assertObjectPropertyForInst(String inst, String prop, String val) {
00520 
00521                 inst = PrologInterface.removeSingleQuotes(inst);
00522                 prop = PrologInterface.removeSingleQuotes(prop);
00523                 val = PrologInterface.removeSingleQuotes(val);
00524                 
00525                 PrologInterface.executeQuery("rdf_assert('" + inst + "', '"+prop+"', '" + val + "')");
00526         }
00527         
00528 
00529         
00538         public static void assertDataPropertyForInst(String inst, String prop, String val, String type) {
00539 
00540                 inst = PrologInterface.removeSingleQuotes(inst);
00541                 prop = PrologInterface.removeSingleQuotes(prop);
00542                 val = PrologInterface.removeSingleQuotes(val);
00543                 type = PrologInterface.removeSingleQuotes(type);
00544                 
00545                 PrologInterface.executeQuery("rdf_assert('" + inst + "', '"+prop+"', literal(type('" + type + "', '" + val + "')))");
00546         }
00547         
00548         
00549         
00560         public static String createRestriction(String owlClass, String prop, String value, String restrType, String sourceRef) {
00561 
00562                 owlClass  = PrologInterface.removeSingleQuotes(owlClass);
00563                 prop      = PrologInterface.removeSingleQuotes(prop);
00564                 value     = PrologInterface.removeSingleQuotes(value);
00565                 restrType = PrologInterface.removeSingleQuotes(restrType);
00566                 sourceRef = PrologInterface.removeSingleQuotes(sourceRef);
00567                 
00568                 HashMap<String, Vector<String>> restr = 
00569                         PrologInterface.executeQuery("create_restr('"+owlClass+"', '" + prop + "', '" + value + "', '" + restrType + "', '" + sourceRef + "', Restr)");
00570 
00571                 if(restr !=null && restr.get("Restr")!=null && restr.get("Restr").size() > 0) {
00572                         return restr.get("Restr").firstElement();
00573                 }
00574                 return null;
00575         }
00576         
00577         
00584         public static void assertSubClassOf(String subClass, String superClass) {
00585 
00586                 subClass = PrologInterface.removeSingleQuotes(subClass);
00587                 superClass = PrologInterface.removeSingleQuotes(superClass);
00588                 
00589                 PrologInterface.executeQuery("rdf_assert('" + subClass + "', rdfs:subClassOf, '" + superClass + "')");
00590         }
00591         
00592         
00599         public static String createOWLInst(String owlClass) {
00600 
00601                 owlClass = PrologInterface.removeSingleQuotes(owlClass);
00602                 
00603                 HashMap<String, Vector<String>> inst = 
00604                         PrologInterface.executeQuery("rdf_instance_from_class('" + owlClass + "', ObjInst)");
00605 
00606                 if(inst !=null && inst.get("ObjInst").size() > 0) {
00607 
00608                         return inst.get("ObjInst").get(0);
00609                 }
00610                 return null;
00611         }
00612         
00613         
00620         public static String createStateTransition(String fromState, String toState, String causedBy) {
00621 
00622                 fromState = PrologInterface.removeSingleQuotes(fromState);
00623                 toState   = PrologInterface.removeSingleQuotes(toState);
00624                 
00625                 // check if there is already a transition with the defined from- and to-classes
00626                 HashMap<String, Vector<String>> t_insts = 
00627                         PrologInterface.executeQuery("owl_individual_of(T, 'http://ias.cs.tum.edu/kb/knowrob.owl#IntrinsicStateChangeEvent'), " +
00628                                                                                  "rdf_has(T, 'http://ias.cs.tum.edu/kb/knowrob.owl#fromState', '" + fromState + "'), " +
00629                                                                                  "rdf_has(T, 'http://ias.cs.tum.edu/kb/knowrob.owl#toState', '" + toState + "'), " +
00630                                                                                  "rdf_has(T, 'http://ias.cs.tum.edu/kb/knowrob.owl#causedBy', '" + causedBy+ "')");
00631 
00632                 // return existing instance if there is one with the respective arguments
00633                 if(t_insts !=null && t_insts.get("T").size() > 0) {
00634                         return t_insts.get("T").get(0);
00635                         
00636                 } else {
00637                         
00638                         // create new transition otherwise:
00639                         String t_inst = PrologQueryUtils.createOWLInst("http://ias.cs.tum.edu/kb/knowrob.owl#IntrinsicStateChangeEvent");
00640                         
00641                         assertObjectPropertyForInst(t_inst, "http://ias.cs.tum.edu/kb/knowrob.owl#fromState", fromState);
00642                         assertObjectPropertyForInst(t_inst, "http://ias.cs.tum.edu/kb/knowrob.owl#toState",   toState);
00643                         assertObjectPropertyForInst(t_inst, "http://ias.cs.tum.edu/kb/knowrob.owl#causedBy",  causedBy); // TODO: is this value already in the UNR Actions OWL namespace?
00644                         return t_inst;
00645                 }
00646         }
00647         
00648         
00654         public static void clearActionStateTransitions(String action) {
00655 
00656                 action = PrologInterface.removeSingleQuotes(action);
00657                 
00658                 HashMap<String, Vector<String>> t_insts = PrologInterface.
00659                                 executeQuery("class_properties('" + action + "', 'http://ias.cs.tum.edu/kb/knowrob.owl#stateTransition', T)");
00660 
00661                 if(t_insts !=null && t_insts.get("T").size() > 0) {
00662                         
00663                         for(String t : t_insts.get("T")) {
00664 
00665                                 // remove restriction on this transition
00666                                 PrologInterface.executeQuery("findall(R, rdf_has(R, 'http://www.w3.org/2002/07/owl#hasValue', " + t + "), Rs), " +
00667                                                 "member(Restr, Rs), rdf_retractall(Restr, _, _), rdf_retractall(_, 'http://www.w3.org/2000/01/rdf-schema#subClassOf', Restr)");
00668 
00669                                 // remove transition properties and transition itself
00670                                 PrologInterface.executeQuery("rdf_retractall(" + t + ", _, _)");
00671 
00672                         }
00673                 }
00674         }
00675         
00676         
00684         public static String createObjInstWithPose(String objClass, String perceptionMethod, Vector<Float> pose) {
00685 
00686                 objClass = PrologInterface.removeSingleQuotes(objClass);
00687                 perceptionMethod = PrologInterface.removeSingleQuotes(perceptionMethod);
00688                 
00689                 String q = "";
00690                 
00691                 if(pose.size()==2) {
00692                         q="create_object_perception('" + objClass + "', [1.0,0.0,0.0," + 
00693                                 pose.get(0) + ",0.0,1.0,0.0," + pose.get(1) + ",0.0,0.0,1.0," +
00694                                 "0.0,0.0,0.0,0.0,1.0], ['" + perceptionMethod + "'], ObjInst)";
00695                 } else if(pose.size()==16) {
00696                         q="create_object_perception('" + objClass + "', ["+
00697                         pose.get(0)  +","+ pose.get(1)  +","+ pose.get(2)  +","+ pose.get(3)  +","+
00698                         pose.get(4)  +","+ pose.get(5)  +","+ pose.get(6)  +","+ pose.get(7)  +","+
00699                         pose.get(8)  +","+ pose.get(9)  +","+ pose.get(10) +","+ pose.get(11) +","+
00700                         pose.get(12) +","+ pose.get(13) +","+ pose.get(14) +","+ pose.get(15) +
00701                         "], ['" + perceptionMethod + "'], ObjInst)";                    
00702                 }
00703 
00704                 HashMap<String, Vector<String>> obj_id = PrologInterface.executeQuery(q);
00705                 if(obj_id != null && obj_id.get("ObjInst").size() > 0) {
00706 
00707                         return obj_id.get("ObjInst").get(0);
00708                 }
00709                 return null;
00710         }
00711         
00712         
00713         
00721         public static void setObjPose(String objInst, String perceptionMethod, Vector<Float> pose) {
00722 
00723                 objInst = PrologInterface.removeSingleQuotes(objInst);
00724                 perceptionMethod = PrologInterface.removeSingleQuotes(perceptionMethod);
00725                 String q = "";
00726                 
00727                 if(pose.size()==2) {
00728                         q="create_perception_instance(['"+perceptionMethod+"'], Perception),"+
00729                     "set_object_perception('"+objInst+"', Perception),"+
00730                     "set_perception_pose(Perception, [1.0,0.0,0.0," + pose.get(0) + 
00731                     ",0.0,1.0,0.0," + pose.get(1) + ",0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]).";
00732                         
00733                 } else if(pose.size()==16) {
00734                         q="create_perception_instance(['"+perceptionMethod+"'], Perception),"+
00735                     "set_object_perception('"+objInst+"', Perception),"+
00736                     "set_perception_pose(Perception, ["+
00737                         pose.get(0)  +","+ pose.get(1)  +","+ pose.get(2)  +","+ pose.get(3)  +","+
00738                         pose.get(4)  +","+ pose.get(5)  +","+ pose.get(6)  +","+ pose.get(7)  +","+
00739                         pose.get(8)  +","+ pose.get(9)  +","+ pose.get(10) +","+ pose.get(11) +","+
00740                         pose.get(12) +","+ pose.get(13) +","+ pose.get(14) +","+ pose.get(15) +
00741                         "])";                   
00742                 }
00743 
00744                 PrologInterface.executeQuery(q);
00745         }
00746         
00747         
00757         public static boolean evaluateCondition(String condition, String objActOn) {
00758 
00759                 condition = PrologInterface.removeSingleQuotes(condition);
00760                 objActOn = PrologInterface.removeSingleQuotes(objActOn);
00761                 
00762                 // covers the cases that 
00763                 // - objectActedOn is class: check if there is an instance of that class that fulfills the condition
00764                 // - objectActedOn is instance: check if that instance fulfills the condition
00765                 
00766                 HashMap<String, Vector<String>> cond_check = 
00767                         PrologInterface.executeQuery("owl_individual_of('" + objActOn+ "', '" + condition + "');" +
00768                                         "owl_individual_of(Inst, '" + objActOn + "'), owl_individual_of(Inst, '" + condition + "')");   
00769 
00770                 if(cond_check !=null) {
00771 
00772                         return true;
00773                 }
00774                 return false;
00775         }
00776 
00777         
00787         public static String getSemanticMapInstance(String roomNumber, String floorNumber, String streetNumber, String streetName) {
00788 
00789                 String q =      "owl_individual_of(Map, 'http://ias.cs.tum.edu/kb/knowrob.owl#SemanticEnvironmentMap')";
00790                 
00791                 if(roomNumber!=null && !roomNumber.isEmpty()) {
00792                         roomNumber = PrologInterface.removeSingleQuotes(roomNumber);
00793                         q+= ",owl_has(R, 'http://ias.cs.tum.edu/kb/knowrob.owl#describedInMap', Map)," +
00794                              "owl_has(R, 'http://ias.cs.tum.edu/kb/knowrob.owl#roomNumber', literal(type(_,'"+roomNumber+"')))";
00795                 }
00796                 
00797                 if(floorNumber!=null && !floorNumber.isEmpty()) {
00798                         floorNumber = PrologInterface.removeSingleQuotes(floorNumber);
00799                         q+= ",owl_has(S1, 'http://ias.cs.tum.edu/kb/knowrob.owl#properPhysicalParts', R)," +
00800                                  "rdf_has(R,  'http://ias.cs.tum.edu/kb/knowrob.owl#floorNumber', literal(type(_, '"+floorNumber+"')))";
00801                 }
00802                 
00803                 if(streetNumber!=null && !streetNumber.isEmpty()) {
00804                         streetNumber = PrologInterface.removeSingleQuotes(streetNumber);
00805                         q+= ",owl_has(S1, 'http://ias.cs.tum.edu/kb/knowrob.owl#properPhysicalParts', R)," +
00806                                 "rdf_has(R, 'http://ias.cs.tum.edu/kb/knowrob.owl#streetNumber', literal(type(_, '"+streetNumber+"')))";
00807                 }
00808                 
00809                 if(streetName!=null && !streetName.isEmpty()) {
00810                         streetName = PrologInterface.removeSingleQuotes(streetName);
00811                         q+= ",owl_has(S1, 'http://ias.cs.tum.edu/kb/knowrob.owl#properPhysicalParts', R)," +
00812                                 "rdf_has(S2, rdfs:label, literal(like('*"+streetName+"*'), _))";
00813                 }
00814                 
00815                 HashMap<String, Vector<String>> map_insts = PrologInterface.executeQuery(q);
00816                 
00817                 if(map_insts!=null && map_insts.get("Map").size()>0) {
00818                         return map_insts.get("Map").firstElement();
00819                 }
00820                 return null;
00821         }
00822 
00823         
00824         public static void writeActionToOWLFile(String actionClass, String file) {
00825                 PrologInterface.executeQuery("export_action('" + actionClass + "', '" + file + "')");
00826         }
00827         
00828         
00829         public static void deleteObjectInstance(String iri) {
00830                 iri = PrologInterface.removeSingleQuotes(iri);
00831                 PrologInterface.executeQuery("delete_object_information('" + iri + "')");
00832         }
00833 
00834         public static void deleteObjectInstanceWithChildren(String iri) {
00835                 iri = PrologInterface.removeSingleQuotes(iri);
00836                 PrologInterface.executeQuery("delete_object_information_recursive('" + iri + "')");
00837         }
00838 }


knowrob_common
Author(s): Moritz Tenorth
autogenerated on Sat Dec 28 2013 17:09:28