Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 /**
  * Inference between a compound term and a statement
  *
  * @param compound The compound term
  * @param index The location of the current term in the compound
  * @param statement The statement
  * @param side The location of the current term in the statement
  * @param beliefTerm The content of the belief
  * @param memory Reference to the memory
  */
 private static void compoundAndStatement(
     CompoundTerm compound,
     short index,
     Statement statement,
     short side,
     Term beliefTerm,
     Memory memory) {
   Term component = compound.componentAt(index);
   Task task = memory.currentTask;
   if (component.getClass() == statement.getClass()) {
     if ((compound instanceof Conjunction) && (memory.currentBelief != null)) {
       if (Variable.unify(Symbols.VAR_DEPENDENT, component, statement, compound, statement)) {
         SyllogisticRules.elimiVarDep(compound, component, statement.equals(beliefTerm), memory);
       } else if (task.getSentence().isJudgment()) {
         CompositionalRules.introVarInner(statement, (Statement) component, compound, memory);
       }
     }
   } else {
     if (!task.isStructural() && task.getSentence().isJudgment()) {
       if (statement instanceof Inheritance) {
         StructuralRules.structuralCompose1(compound, index, statement, memory);
         //                    if (!(compound instanceof SetExt) && !(compound instanceof SetInt))
         // {
         if (!(compound instanceof SetExt
             || compound instanceof SetInt
             || compound instanceof Negation)) {
           StructuralRules.structuralCompose2(compound, index, statement, side, memory);
         } // {A --> B, A @ (A&C)} |- (A&C) --> (B&C)
       } else if ((statement instanceof Similarity) && !(compound instanceof Conjunction)) {
         StructuralRules.structuralCompose2(compound, index, statement, side, memory);
       } // {A <-> B, A @ (A&C)} |- (A&C) <-> (B&C)
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * Conditional deduction or induction, with variable unification
  *
  * @param conditional The premise that is an Implication with a Conjunction as condition
  * @param index The location of the shared term in the condition
  * @param statement The second premise that is a statement
  * @param side The location of the shared term in the statement
  * @param memory Reference to the memory
  */
 private static void conditionalDedIndWithVar(
     Implication conditional, short index, Statement statement, short side, Memory memory) {
   CompoundTerm condition = (CompoundTerm) conditional.getSubject();
   Term component = condition.componentAt(index);
   Term component2 = null;
   if (statement instanceof Inheritance) {
     component2 = statement;
     side = -1;
   } else if (statement instanceof Implication) {
     component2 = statement.componentAt(side);
   }
   if ((component2 != null)
       && Variable.unify(Symbols.VAR_INDEPENDENT, component, component2, conditional, statement)) {
     SyllogisticRules.conditionalDedInd(conditional, index, statement, side, memory);
   }
 }
Ejemplo n.º 4
0
 /**
  * {<S ==> P>, <M <=> P>} |- <S ==> P>
  *
  * @param term1 Subject of the new task
  * @param term2 Predicate of the new task
  * @param asym The asymmetric premise
  * @param sym The symmetric premise
  * @param figure Locations of the shared term in premises
  */
 static void analogy(Term term1, Term term2, Sentence asym, Sentence sym, int figure) {
   if (RDFStatement.invalidStatement(term1, term2)) {
     return;
   }
   RDFStatement asymSt = (RDFStatement) asym.getContent();
   RDFStatement symSt = (RDFStatement) sym.getContent();
   TruthValue truth = null;
   BudgetValue budget;
   Sentence sentence = Memory.currentTask.getSentence();
   CompoundTerm taskTerm = (CompoundTerm) sentence.getContent();
   if (sentence instanceof Question) {
     if (taskTerm.isCommutative()) {
       budget = BudgetFunctions.backwardWeak(asym.getTruth());
     } else {
       budget = BudgetFunctions.backward(sym.getTruth());
     }
   } else {
     if (sentence instanceof Goal) {
       if (taskTerm.isCommutative()) {
         truth = TruthFunctions.desireWeak(asym.getTruth(), sym.getTruth());
       } else {
         truth = TruthFunctions.desireStrong(asym.getTruth(), sym.getTruth());
       }
     } else {
       truth = TruthFunctions.analogy(asym.getTruth(), sym.getTruth());
     }
     budget = BudgetFunctions.forward(truth);
   }
   TemporalValue order1 = asymSt.getOrder();
   TemporalValue order2 = symSt.getOrder();
   TemporalValue order;
   switch (figure) {
     case 11:
     case 12:
       order = TemporalRules.syllogistic(order2, order1, figure);
       break;
     case 21:
     case 22:
       order = TemporalRules.syllogistic(order1, order2, figure);
       break;
     default:
       return;
   }
   Term content = RDFStatement.make(asymSt, term1, term2, order);
   Memory.doublePremiseTask(budget, content, truth);
 }
Ejemplo n.º 5
0
 /**
  * The TaskLink is of type TRANSFORM, and the conclusion is an equivalent transformation
  *
  * @param tLink The task link
  * @param memory Reference to the memory
  */
 public static void transformTask(TaskLink tLink, Memory memory) {
   CompoundTerm content = (CompoundTerm) memory.currentTask.getContent().clone();
   short[] indices = tLink.getIndices();
   Term inh = null;
   if ((indices.length == 2) || (content instanceof Inheritance)) { // <(*, term, #) --> #>
     inh = content;
   } else if (indices.length == 3) { // <<(*, term, #) --> #> ==> #>
     inh = content.componentAt(indices[0]);
   } else if (indices.length == 4) { // <(&&, <(*, term, #) --> #>, #) ==> #>
     Term component = content.componentAt(indices[0]);
     if ((component instanceof Conjunction)
         && (((content instanceof Implication) && (indices[0] == 0))
             || (content instanceof Equivalence))) {
       inh = ((CompoundTerm) component).componentAt(indices[1]);
     } else {
       return;
     }
   }
   if (inh instanceof Inheritance) {
     StructuralRules.transformProductImage((Inheritance) inh, content, indices, memory);
   }
 }
Ejemplo n.º 6
0
 /**
  * Inference between two compound terms
  *
  * @param taskTerm The compound from the task
  * @param beliefTerm The compound from the belief
  * @param memory Reference to the memory
  */
 private static void compoundAndCompound(
     CompoundTerm taskTerm, CompoundTerm beliefTerm, Memory memory) {
   if (taskTerm.getClass() == beliefTerm.getClass()) {
     if (taskTerm.size() > beliefTerm.size()) {
       compoundAndSelf(taskTerm, beliefTerm, true, memory);
     } else if (taskTerm.size() < beliefTerm.size()) {
       compoundAndSelf(beliefTerm, taskTerm, false, memory);
     }
   }
 }
Ejemplo n.º 7
0
 /**
  * Inference between a compound term and a component of it
  *
  * @param compound The compound term
  * @param component The component term
  * @param compoundTask Whether the compound comes from the task
  * @param memory Reference to the memory
  */
 private static void compoundAndSelf(
     CompoundTerm compound, Term component, boolean compoundTask, Memory memory) {
   if ((compound instanceof Conjunction) || (compound instanceof Disjunction)) {
     if (memory.currentBelief != null) {
       CompositionalRules.decomposeStatement(compound, component, compoundTask, memory);
     } else if (compound.containComponent(component)) {
       StructuralRules.structuralCompound(compound, component, compoundTask, memory);
     }
   } else if ((compound instanceof Negation) && !memory.currentTask.isStructural()) {
     if (compoundTask) {
       StructuralRules.transformNegation(((Negation) compound).componentAt(0), memory);
     } else {
       StructuralRules.transformNegation(compound, memory);
     }
   }
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 /**
  * {<(&&, S1, S2, S3) ==> P>, S1} |- <(&&, S2, S3) ==> P> {<(&&, S2, S3) ==> P>, <S1 ==> S2>} |-
  * <(&&, S1, S3) ==> P> {<(&&, S1, S3) ==> P>, <S1 ==> S2>} |- <(&&, S2, S3) ==> P>
  *
  * @param premise1 The conditional premise
  * @param index The location of the shared term in the condition of premise1
  * @param premise2 The premise which, or part of which, appears in the condition of premise1
  * @param side The location of the shared term in premise2: 0 for subject, 1 for predicate, -1 for
  *     the whole term
  */
 static void conditionalDedInd(Implication premise1, short index, Term premise2, int side) {
   Task task = Memory.currentTask;
   Sentence taskSentence = task.getSentence();
   Judgment belief = Memory.currentBelief;
   boolean deduction = (side != 0);
   HashMap substitute =
       Variable.findSubstitute(Variable.VarType.ALL, premise2, belief.getContent());
   boolean conditionalTask = (substitute != null);
   TemporalValue tense1 = (conditionalTask ? taskSentence.getTense() : belief.getTense());
   TemporalValue tense2 = (conditionalTask ? belief.getTense() : taskSentence.getTense());
   TemporalValue order1 = premise1.getOrder();
   TemporalValue order2 = premise2.getOrder();
   if ((side == -1) && (tense2 != null) && (tense2.getDelta() > 0)) {
     return;
   }
   if ((side == 0) && (order2 != null) && (order2.getDelta() > 0)) {
     return;
   }
   if ((side == 1) && (order2 != null) && (order2.getDelta() < 0)) {
     return;
   }
   TemporalValue tense = TemporalRules.syllogistic(tense1, tense2);
   if (tense != null) {
     tense = new TemporalValue(0);
   }
   Term commonComponent;
   Term newComponent = null;
   if (side == 0) {
     commonComponent = ((RDFStatement) premise2).getSubject();
     newComponent = ((RDFStatement) premise2).getPredicate();
   } else if (side == 1) {
     commonComponent = ((RDFStatement) premise2).getPredicate();
     newComponent = ((RDFStatement) premise2).getSubject();
   } else {
     commonComponent = premise2;
   }
   Conjunction oldCondition = (Conjunction) premise1.getSubject();
   boolean match =
       Variable.unify(
           Variable.VarType.INDEPENDENT,
           oldCondition.componentAt(index),
           commonComponent,
           premise1,
           premise2);
   if (!match && (commonComponent.getClass() == oldCondition.getClass())) {
     match =
         Variable.unify(
             Variable.VarType.INDEPENDENT,
             oldCondition.componentAt(index),
             ((CompoundTerm) commonComponent).componentAt(index),
             premise1,
             premise2);
   }
   if (!match) {
     return;
   }
   Term newCondition;
   if (oldCondition.equals(commonComponent)) {
     newCondition = null;
   } else {
     newCondition = CompoundTerm.replaceComponent(oldCondition, index, newComponent);
     if ((newCondition instanceof Conjunction) && ((CompoundTerm) newCondition).size() == 1) {
       newCondition = ((CompoundTerm) newCondition).componentAt(0);
     }
   }
   Term content;
   if (newCondition != null) {
     content = RDFStatement.make(premise1, newCondition, premise1.getPredicate(), order1);
   } else {
     content = premise1.getPredicate();
   }
   if (content == null) {
     return;
   }
   TruthValue truth1 = taskSentence.getTruth();
   TruthValue truth2 = belief.getTruth();
   TruthValue truth = null;
   BudgetValue budget;
   if (taskSentence instanceof Question) {
     budget = BudgetFunctions.backwardWeak(truth2);
   } else {
     if (taskSentence instanceof Goal) {
       if (conditionalTask) {
         truth = TruthFunctions.desireWeak(truth1, truth2);
       } else if (deduction) {
         truth = TruthFunctions.desireInd(truth1, truth2);
       } else {
         truth = TruthFunctions.desireDed(truth1, truth2);
       }
       budget = BudgetFunctions.forward(truth);
     } else {
       if (deduction) {
         truth = TruthFunctions.deduction(truth1, truth2);
       } else if (conditionalTask) {
         truth = TruthFunctions.induction(truth2, truth1);
       } else {
         truth = TruthFunctions.induction(truth1, truth2);
       }
     }
     budget = BudgetFunctions.forward(truth);
   }
   Memory.currentTense = tense;
   Memory.doublePremiseTask(budget, content, truth);
 }