00001 package edu.tum.cs.prolog; 00002 00003 import java.util.Collection; 00004 import java.util.HashSet; 00005 import java.util.Vector; 00006 00007 import yprolog.ParseException; 00008 00014 public class PrologKnowledgeBase extends yprolog.YProlog { 00015 public PrologKnowledgeBase() { 00016 00017 } 00018 00024 public void tell(String formula) throws ParseException { 00025 this.consult(formula); 00026 } 00027 00034 public boolean ask(String query) throws ParseException { 00035 return this.yp_eng.setQuery(query); 00036 } 00037 00038 00044 public Collection<String> fetchAtoms(String goal) { 00045 HashSet<String> set = new HashSet<String>(); 00046 String res = this.queryToString(goal, 0, ""); 00047 if(res == null) 00048 return set; 00049 for(String s : res.substring(0, res.length()-1).split("\\.")) 00050 set.add(s); 00051 return set; 00052 } 00053 00059 public Vector<String[]> fetchBindings(String goal) { 00060 return this.queryToTable(goal, 0, true); 00061 } 00062 }