コード例 #1
0
 public static void main(String[] args) throws Exception {
   TrivialDialogueKB kb = new TrivialDialogueKB();
   DialogueOperatorEffect f3 = parse("assert(or(a,b))");
   kb.store(f3, ACCESSTYPE.AUTO_OVERWRITEAUTO, false);
   // f3=createAssertion(DialogueKBFormula.parse("and(a,b"));
   // DialogueOperatorEffect f3 = parse("++q");
   System.out.println(f3.toString(false));
   System.out.println(f3.extractAllNamesUsed());
 }
コード例 #2
0
 public Set<DialogueKBFormula> extractAllNamesUsed() {
   if (isAssignment()) {
     Object thing = getAssignedExpression();
     if (thing instanceof DialogueKBFormula) {
       DialogueKBFormula r = (DialogueKBFormula) thing;
       return r.extractAllNamesUsed();
     } else return null;
   } else if (isAssertion()) {
     DialogueKBFormula f = getAssertedFormula();
     return f.extractAllNamesUsed();
   } else if (isGoalAchievement()) {
     DialogueKBFormula f = getGoalValue();
     return f.extractAllNamesUsed();
   } else if (isImplication()) {
     Set<DialogueKBFormula> resa = getAntecedent().extractAllNamesUsed();
     Set<DialogueKBFormula> resc = getConsequent().extractAllNamesUsed();
     Set<DialogueKBFormula> ret = null;
     if (resa != null) ret = resa;
     if (resc != null) {
       if (getConsequent().isAssignment()) {
         resc.add(getConsequent().getAssignedVariable());
       }
       if (ret != null) ret.addAll(resc);
       else ret = resc;
     }
     return ret;
   } else if (isAssignmentList()) {
     Set<DialogueKBFormula> res = null;
     for (DialogueOperatorEffect x : getAssignmentList()) {
       Set<DialogueKBFormula> newNames = x.extractAllNamesUsed();
       if (newNames != null) {
         if (res == null) res = newNames;
         else res.addAll(newNames);
       }
     }
     return res;
   } else return null;
 }