Пример #1
0
 /**
  * {<M ==> S>, <M ==> P>} |- {<S ==> P>,
  *
  * <P ==>S>, <S <=> P>}
  *
  * @param term1 Subject of the first new task
  * @param term2 Predicate of the first new task
  * @param taskSentence The first premise
  * @param belief The second premise
  * @param figure Locations of the shared term in premises
  */
 static void abdIndCom(
     Term term1, Term term2, Sentence taskSentence, Judgment belief, int figure) {
   if (RDFStatement.invalidStatement(term1, term2)) {
     return;
   }
   RDFStatement st1 = (RDFStatement) taskSentence.getContent();
   RDFStatement st2 = (RDFStatement) belief.getContent();
   TruthValue truth1 = null;
   TruthValue truth2 = null;
   TruthValue truth3 = null;
   BudgetValue budget1, budget2, budget3;
   TruthValue value1 = taskSentence.getTruth();
   TruthValue value2 = belief.getTruth();
   if (taskSentence instanceof Question) {
     budget1 = BudgetFunctions.backward(value2);
     budget2 = BudgetFunctions.backwardWeak(value2);
     budget3 = BudgetFunctions.backward(value2);
   } else {
     if (taskSentence instanceof Goal) {
       truth1 = TruthFunctions.desireStrong(value1, value2);
       truth2 = TruthFunctions.desireWeak(value2, value1);
       truth3 = TruthFunctions.desireStrong(value1, value2);
     } else {
       truth1 = TruthFunctions.abduction(value1, value2);
       truth2 = TruthFunctions.abduction(value2, value1);
       truth3 = TruthFunctions.comparison(value1, value2);
     }
     budget1 = BudgetFunctions.forward(truth1);
     budget2 = BudgetFunctions.forward(truth2);
     budget3 = BudgetFunctions.forward(truth3);
   }
   TemporalValue order1 = st1.getOrder();
   TemporalValue order2 = st2.getOrder();
   TemporalValue order = TemporalRules.syllogistic(order1, order2, figure);
   //        if (tense == null) {
   //            tense = TemporalValue.WHEN;
   //            truth1 = TruthFunctions.temporalInduction(truth1);
   //            truth2 = TruthFunctions.temporalInduction(truth2);
   //            truth3 = TruthFunctions.temporalInduction(truth3);
   //        }
   RDFStatement statement1, statement2, statement3;
   statement1 = RDFStatement.make(st1, term1, term2, order);
   statement2 = RDFStatement.make(st1, term2, term1, TemporalValue.getReverse(order));
   statement3 = RDFStatement.makeSym(st1, term1, term2, order);
   Memory.doublePremiseTask(budget1, statement1, truth1);
   Memory.doublePremiseTask(budget2, statement2, truth2);
   Memory.doublePremiseTask(budget3, statement3, truth3);
   if (statement1.isConstant()) {
     Memory.doublePremiseTask(budget1, introVarInd(belief, taskSentence, figure, true), truth1);
     Memory.doublePremiseTask(budget2, introVarInd(taskSentence, belief, figure, true), truth2);
     Memory.doublePremiseTask(budget3, introVarInd(taskSentence, belief, figure, false), truth3);
   }
 }
Пример #2
0
 /**
  * {<M --> S>, <C ==> <M --> P>>} |- <(&&, <#x --> S>, C) ==> <#x --> P>> {<M --> S>, (&&, C, <M
  * --> P>)} |- (&&, C, <<#x --> S> ==> <#x --> P>>)
  *
  * @param premise1 The first premise directly used in internal induction, <M --> S>
  * @param premise2 The component to be used as a premise in internal induction, <M --> P>
  * @param oldCompound The whole content of the first premise, Implication or Conjunction
  */
 static void introVarIndInner(
     RDFStatement premise1, RDFStatement premise2, CompoundTerm oldCompound) {
   Task task = Memory.currentTask;
   Sentence taskSentence = task.getSentence();
   if (!taskSentence.isJudgment()) {
     return;
   }
   if (premise1.getClass() != premise2.getClass()) {
     return;
   }
   Variable var1 = new Variable(Symbols.VARIABLE_TAG + "0");
   Variable var2 = new Variable(Symbols.VARIABLE_TAG + "0");
   RDFStatement state1, state2;
   if (premise1.getSubject().equals(premise2.getSubject())) {
     state1 = RDFStatement.make(premise1, var1, premise1.getPredicate());
     state2 = RDFStatement.make(premise2, var2, premise2.getPredicate());
   } else if (premise1.getPredicate().equals(premise2.getPredicate())) {
     state1 = RDFStatement.make(premise1, premise1.getSubject(), var1);
     state2 = RDFStatement.make(premise2, premise2.getSubject(), var2);
   } else {
     return;
   }
   Sentence belief = Memory.currentBelief;
   Term compound, content;
   TemporalValue tense;
   TruthValue truth;
   if (premise1.equals(taskSentence.getContent())) {
     truth = TruthFunctions.abduction(taskSentence.getTruth(), belief.getTruth());
     tense = TemporalRules.tenseInduction(taskSentence.getTense(), belief.getTense());
   } else {
     truth = TruthFunctions.abduction(belief.getTruth(), taskSentence.getTruth());
     tense = TemporalRules.tenseInduction(belief.getTense(), taskSentence.getTense());
   }
   if (tense == null) {
     return;
   }
   if ((oldCompound instanceof Implication) && (tense == oldCompound.getOrder())) {
     compound = RDFStatement.make((RDFStatement) oldCompound, oldCompound.componentAt(0), state2);
     content = RDFStatement.make((RDFStatement) oldCompound, state1, compound);
   } else if (oldCompound instanceof Conjunction) {
     compound = Implication.make(state1, state2, tense);
     content = CompoundTerm.replaceComponent(oldCompound, premise2, compound);
   } else {
     return;
   }
   BudgetValue budget = BudgetFunctions.forward(truth);
   Memory.doublePremiseTask(budget, content, truth);
 }
Пример #3
0
 /**
  * {<(&&, S2, S3) ==> P>, <(&&, S1, S3) ==> P>} |- <S1 ==> S2>
  *
  * @param cond1 The condition of the first premise
  * @param cond2 The condition of the second premise
  * @param st1 The first premise
  * @param st2 The second premise
  * @return Whether there are derived tasks
  */
 static boolean conditionalAbd(Term cond1, Term cond2, RDFStatement st1, RDFStatement st2) {
   if (!(st1 instanceof Implication) || !(st2 instanceof Implication)) {
     return false;
   }
   if (!(cond1 instanceof Conjunction) && !(cond2 instanceof Conjunction)) {
     return false;
   }
   TemporalValue order1 = st1.getOrder();
   TemporalValue order2 = st2.getOrder();
   if (order1 != order2) {
     return false;
   }
   Term term1 = null;
   Term term2 = null;
   if (cond1 instanceof Conjunction) {
     term1 = CompoundTerm.reduceComponents((Conjunction) cond1, cond2);
   }
   if (cond2 instanceof Conjunction) {
     term2 = CompoundTerm.reduceComponents((Conjunction) cond2, cond1);
   }
   if ((term1 == null) && (term2 == null)) {
     return false;
   }
   Task task = Memory.currentTask;
   Sentence sentence = task.getSentence();
   Judgment belief = Memory.currentBelief;
   TruthValue value1 = sentence.getTruth();
   TruthValue value2 = belief.getTruth();
   boolean keepOrder =
       (Variable.findSubstitute(Variable.VarType.INDEPENDENT, st1, task.getContent()) != null);
   Term content;
   TruthValue truth = null;
   BudgetValue budget;
   if (term1 != null) {
     if (term2 != null) {
       content = RDFStatement.make(st2, term2, term1, order2);
     } else {
       content = term1;
     }
     if (sentence instanceof Question) {
       budget = BudgetFunctions.backwardWeak(value2);
     } else {
       if (sentence instanceof Goal) {
         if (keepOrder) {
           truth = TruthFunctions.desireDed(value1, value2);
         } else {
           truth = TruthFunctions.desireInd(value1, value2);
         }
       } else {
         truth = TruthFunctions.abduction(value2, value1);
       }
       budget = BudgetFunctions.forward(truth);
     }
     Memory.doublePremiseTask(budget, content, truth);
   }
   if (term2 != null) {
     if (term1 != null) {
       content = RDFStatement.make(st1, term1, term2, order1);
     } else {
       content = term2;
     }
     if (sentence instanceof Question) {
       budget = BudgetFunctions.backwardWeak(value2);
     } else {
       if (sentence instanceof Goal) {
         if (keepOrder) {
           truth = TruthFunctions.desireDed(value1, value2);
         } else {
           truth = TruthFunctions.desireInd(value1, value2);
         }
       } else {
         truth = TruthFunctions.abduction(value1, value2);
       }
       budget = BudgetFunctions.forward(truth);
     }
     Memory.currentTense = null;
     Memory.doublePremiseTask(budget, content, truth);
   }
   return true;
 }
Пример #4
0
 /**
  * {<<M --> S> ==> <M --> P>>, <M --> S>} |- <M --> P> {<<M --> S> ==> <M --> P>>, <M --> P>} |-
  * <M --> S>
  *
  * @param mainSentence The implication/equivalence premise
  * @param subSentence The premise on part of s1
  * @param s The location of s2 in s1
  */
 static void detachment(Sentence mainSentence, Sentence subSentence, int s) {
   RDFStatement statement = (RDFStatement) mainSentence.getContent();
   Term subject = statement.getSubject();
   Term predicate = statement.getPredicate();
   Term term = subSentence.getContent();
   Term content;
   int side;
   if (term.equals(subject)) {
     side = 0;
     content = predicate;
   } else if (term.equals(predicate)) {
     side = 1;
     content = subject;
   } else {
     return;
   }
   if ((content instanceof RDFStatement) && ((RDFStatement) content).invalid()) {
     return;
   }
   Sentence taskSentence = Memory.currentTask.getSentence();
   Sentence beliefSentence = Memory.currentBelief;
   TruthValue beliefTruth = beliefSentence.getTruth();
   TruthValue truth1 = mainSentence.getTruth();
   TruthValue truth2 = subSentence.getTruth();
   TruthValue truth = null;
   BudgetValue budget;
   if (taskSentence instanceof Question) {
     if (statement instanceof Equivalence) {
       budget = BudgetFunctions.backward(beliefTruth);
     } else if (side == 0) {
       budget = BudgetFunctions.backwardWeak(beliefTruth);
     } else {
       budget = BudgetFunctions.backward(beliefTruth);
     }
   } else {
     if (taskSentence instanceof Goal) {
       if (statement instanceof Equivalence) {
         truth = TruthFunctions.desireStrong(truth1, truth2);
       } else if (side == 0) {
         truth = TruthFunctions.desireInd(truth1, truth2);
       } else {
         truth = TruthFunctions.desireDed(truth1, truth2);
       }
     } else {
       if (statement instanceof Equivalence) {
         truth = TruthFunctions.analogy(truth1, truth2);
       } else if (side == 0) {
         truth = TruthFunctions.deduction(truth1, truth2);
       } else {
         truth = TruthFunctions.abduction(truth2, truth1);
       }
     }
     budget = BudgetFunctions.forward(truth);
   }
   TemporalValue tense0 = subSentence.getTense();
   TemporalValue order0 = statement.getOrder();
   TemporalValue tense;
   if (order0 == null) {
     tense = tense0;
   } else if (side == 0) {
     tense = TemporalRules.tenseSyllogistic(tense0, subSentence.getCreationTime(), order0);
   } else {
     tense =
         TemporalRules.tenseSyllogistic(
             tense0, subSentence.getCreationTime(), TemporalValue.getReverse(order0));
   }
   Memory.currentTense = tense;
   Memory.doublePremiseTask(budget, content, truth);
 }