コード例 #1
0
 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;
 }
コード例 #2
0
  public static DialogueOperatorEffect getEffectExpr(Node c, NamedNodeMap att) throws Exception {
    boolean isSwapOut = c.getNodeName().toLowerCase().equals(XMLConstants.SWAPOUTID);
    boolean isInterrupt = c.getNodeName().toLowerCase().equals(XMLConstants.INTERRUPTID);
    boolean isSend = c.getNodeName().toLowerCase().equals(XMLConstants.SENDID);
    if (isSwapOut) return createSwapOut();
    else if (isInterrupt) return createInterrupt();
    else if (isSend) {
      Node send = att.getNamedItem(XMLConstants.IDID);
      if (send != null) {
        String sendEventName = send.getNodeValue();
        return createSend(sendEventName);
      }
    } else {
      Node nodeExpr = att.getNamedItem(XMLConstants.EXPRID);
      Node nodeGoal = att.getNamedItem(XMLConstants.GOALID);
      if (nodeGoal != null) {
        String goalName = nodeGoal.getNodeValue();
        if (StringUtils.isEmptyString(goalName))
          throw new Exception(
              "invalid goal effect: '" + XMLUtils.domNode2String(c, true, false) + "'");
        String varGoalName = buildVarNameForGoal(goalName);

        String valueString =
            (nodeExpr != null) ? StringUtils.cleanupSpaces(nodeExpr.getNodeValue()) : null;
        DialogueKBFormula value;
        if (StringUtils.isEmptyString(valueString)) value = DialogueKBFormula.parse(varGoalName);
        else value = DialogueKBFormula.parse(valueString);

        value = processGoalExpression(value, varGoalName);

        return DialogueOperatorEffect.createGoal(goalName, value);
      } else if (nodeExpr != null) {
        DialogueOperatorEffect e = DialogueOperatorEffect.parse(nodeExpr.getNodeValue());
        DialogueKBFormula f = null;
        if (e == null)
          throw new Exception(
              "Effect '"
                  + XMLUtils.domNode2String(c, true, false)
                  + "' returned an empty expression for effects (only assertions and assignments).");
        else if (e.isAssertion()
            && (((f = e.getAssertedFormula()) == null) || f.isConjunction() || f.isDisjunction()))
          throw new Exception("Invalid assertion: " + f);
        else if (e.isAssignment() && (e.getAssignedVariable() == null))
          throw new Exception("Invalid assignmend: " + f);
        else return e;
      }
    }
    return null;
  }