SimilarClass.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 edu.tum.cs.ias.knowrob.json_prolog.PrologValue;
00009 import edu.tum.cs.ias.knowrob.mod_dialog.DialogModule;
00010 
00011 public class SimilarClass extends SimpleTopLevelQuery {
00012 
00013         public SimilarClass(DialogModule mod) {
00014                 super(mod);
00015         }
00016 
00017         @Override
00018         public String match(String q) {
00019                 
00020                 Matcher matcher = Pattern.compile("([d|D]o you know anything similar to ([a-zA-Z0-9]*?)\\?)").matcher(q);
00021                 if(matcher.find()) {
00022                         q=matcher.group(2);
00023                         dialog_module.setCurrentObject(DialogModule.toProlog(q));
00024                         
00025 //                      String query = "comp_similarity:rdf_most_similar('http://ias.cs.tum.edu/kb/knowrob.owl#Cup', 'http://ias.cs.tum.edu/kb/knowrob.owl#HumanScaleObject', 4, NMostSim)";
00026                         String query = "comp_similarity:rdf_most_similar("+DialogModule.toProlog(q)+", knowrob:'HumanScaleObject', 4, NMostSim)";
00027 
00028                         HashMap<String, Vector<PrologValue>> res = DialogModule.executeJSONPrologQuery(query);
00029 
00030                         Vector<PrologValue> obj  = (Vector<PrologValue>)res.get("NMostSim");
00031                         
00032                         
00033                         q=DialogModule.toEnglish(q);
00034                         String r = "Yes, for instance ";
00035                         
00036                         if(obj!=null && obj.size()>0) {
00037                                 PrologValue res_list = obj.get(0);
00038                         }
00039                         
00040                         for(int i=0;i<obj.size();i++) {
00041 
00042                                 String val=obj.get(i).toString();
00043                                 
00044                                 if(val.contains("#")) {
00045                                         val=DialogModule.removeSingleQuotes(val).split("#")[1];
00046                                 }
00047                                 
00048                                 r+= DialogModule.toEnglish(val);
00049 
00050                                 if(i==obj.size()-2) {
00051                                         r+=", and ";
00052                                 } else if (i==obj.size()-1) {
00053                                         r+=".";
00054                                 } else { 
00055                                         r+=", ";
00056                                 }
00057                         }
00058                 }
00059                 
00060                 return null;
00061         }
00062 
00063 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


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