public static DialogueOperatorEffect createAssertion(DialogueKBFormula left) throws Exception { DialogueOperatorEffect f = new DialogueOperatorEffect(); left = left.normalize(); if (left.isConstant()) { f.type = EffectType.ASSIGNMENT; f.left = left; f.right = DialogueKBFormula.trueFormula; return f; } else if (left.isNegatedFormula()) { DialogueKBFormula child = (DialogueKBFormula) left.getFirstChild(); if (child.isConstant()) { f.type = EffectType.ASSIGNMENT; f.left = child; f.right = DialogueKBFormula.falseFormula; return f; } } f.type = EffectType.ASSERTION; if (left.isNegatedFormula()) { left = (DialogueKBFormula) left.getFirstChild(); f.right = DialogueKBFormula.falseFormula; } else { f.right = DialogueKBFormula.trueFormula; } f.left = left; return f; }
public static DialogueOperatorEffect createGoal(String goal, DialogueKBFormula value) { DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.GOAL; f.goalName = goal; f.left = value; return f; }
public static DialogueOperatorEffect createSend(String eventName) throws Exception { if (StringUtils.isEmptyString(eventName)) throw new Exception("empty event used to create a send effect."); DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.SEND; f.eventName = eventName; return f; }
public static DialogueOperatorEffect createList(List<DialogueOperatorEffect> args) throws Exception { DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.AssignmentLIST; f.list = new ArrayList<DialogueOperatorEffect>(); for (DialogueOperatorEffect a : args) { if (!a.isAssignment()) throw new Exception(a + " is not an assigment."); f.list.add(a); } return f; }
public static DialogueOperatorEffect createImplication( DialogueKBFormula ante, DialogueOperatorEffect then, DialogueOperatorEffect elsePart) throws Exception { if (then == null) throw new Exception("invalid implication: null effect"); else { DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.IMPLICATION; f.left = ante; f.value = then; f.implyElse = elsePart; return f; } }
public static DialogueOperatorEffect createAssignment( DialogueKBFormula left, Object value, boolean parseValue) throws Exception { if (!left.isConstant()) throw new Exception("Invalid left hand side of assignment: " + left); if (value != null) { if (value instanceof String) { String rightString = ((String) value).toLowerCase(); if (rightString.equals("true")) return DialogueOperatorEffect.createAssertion(left); else if (rightString.equals("false")) return DialogueOperatorEffect.createAssertion(left.negate()); } else if (value instanceof DialogueKBFormula) { if (((DialogueKBFormula) value).isConstant()) { String rightString = ((DialogueKBFormula) value).getName(); if (rightString.equals("true")) return DialogueOperatorEffect.createAssertion(left); else if (rightString.equals("false")) return DialogueOperatorEffect.createAssertion(left.negate()); } } else if (value instanceof Boolean) { if ((Boolean) value) return DialogueOperatorEffect.createAssertion(left); else return DialogueOperatorEffect.createAssertion(left.negate()); } } DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.ASSIGNMENT; f.left = left; if (value instanceof DialogueKBFormula) { DialogueKBFormula right = (DialogueKBFormula) value; // if (!right.isNumericFormula() && !right.isConstant()) throw new Exception("Right hand side // of assignment is not a numeric expression or constant: "+right); f.right = right; } else { if (parseValue && ((value instanceof String) || (value instanceof Number))) { try { if (value != null) { if (value instanceof String && !DialogueKBFormula.isStringConstant((String) value)) { value = DialogueKBFormula.generateStringConstantFromContent((String) value); } DialogueKBFormula nv = DialogueKBFormula.parse(value.toString()); f.right = nv; } } catch (Exception e) { f.value = value; } } else f.value = value; } return f; }
public static DialogueOperatorEffect createInterrupt() { DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.INTERRUPT; return f; }
public static DialogueOperatorEffect createSwapOut() { DialogueOperatorEffect f = new DialogueOperatorEffect(); f.type = EffectType.SWAPOUT; return f; }