import java.util.*; class BooleanLogic { Random random = new Random(); public static void main(String[] args) { String rules = "a<-b,c;b<-d,e;c<-d,f;d;e;f"; hornReasoning(rules.split(";")); unitResolution(rules.split(";")); } public static String neg(String pTerm) { if (pTerm.startsWith("-")) return pTerm.substring(1); else return "-"+pTerm; } public static String rewrite(String rule) { StringBuffer rzRule = new StringBuffer(); String head = STR.head(rule, "<-"); String body = STR.tail(rule, "<-"); rzRule.append(head); if (body.length() > 0) { String[] conds = body.split(","); for (int i=0; i0) continue; // it's not unit rule. String term = rule1; String negTerm = neg(term); for (int rj=0; rj0) { String unifyExp = STR.replace(exp, ","+negTerm+",", ","); String newRule = unifyExp.substring(1, unifyExp.length()-1); rules.add(newRule); System.out.println("unfiy("+rule1+"|"+rule2+")="+newRule); } } } } public static void hornReasoning(String[] rules) { TreeMap trueMap = new TreeMap(); int satisfyRuleCount; do { satisfyRuleCount = 0; for (int ri=0; ri 0); } } /* a-b(X),c(Y);b(X)<-d(X),e(X);c(Y)<-d(Y),f(Y);d(a);e(a);d(b);f(b) */