Exemplo n.º 1
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)
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Entry point of the inference engine
  *
  * @param tLink The selected TaskLink, which will provide a task
  * @param bLink The selected TermLink, which may provide a belief
  * @param memory Reference to the memory
  */
 public static void reason(TaskLink tLink, TermLink bLink, Memory memory) {
   Task task = memory.currentTask;
   Sentence taskSentence = task.getSentence();
   Term taskTerm = (Term) taskSentence.getContent().clone(); // cloning for substitution
   Term beliefTerm = (Term) bLink.getTarget().clone(); // cloning for substitution
   Concept beliefConcept = memory.termToConcept(beliefTerm);
   Sentence belief = null;
   if (beliefConcept != null) {
     belief = beliefConcept.getBelief(task);
   }
   memory.currentBelief = belief; // may be null
   if (belief != null) {
     LocalRules.match(task, belief, memory);
   }
   if (!memory.noResult()) {
     return;
   }
   short tIndex = tLink.getIndex(0);
   short bIndex = bLink.getIndex(0);
   switch (tLink.getType()) { // dispatch first by TaskLink type
     case TermLink.SELF:
       switch (bLink.getType()) {
         case TermLink.COMPONENT:
           compoundAndSelf((CompoundTerm) taskTerm, beliefTerm, true, memory);
           break;
         case TermLink.COMPOUND:
           compoundAndSelf((CompoundTerm) beliefTerm, taskTerm, false, memory);
           break;
         case TermLink.COMPONENT_STATEMENT:
           if (belief != null) {
             SyllogisticRules.detachment(task.getSentence(), belief, bIndex, memory);
           }
           break;
         case TermLink.COMPOUND_STATEMENT:
           if (belief != null) {
             SyllogisticRules.detachment(belief, task.getSentence(), bIndex, memory);
           }
           break;
         case TermLink.COMPONENT_CONDITION:
           if (belief != null) {
             bIndex = bLink.getIndex(1);
             SyllogisticRules.conditionalDedInd(
                 (Implication) taskTerm, bIndex, beliefTerm, tIndex, memory);
           }
           break;
         case TermLink.COMPOUND_CONDITION:
           if (belief != null) {
             bIndex = bLink.getIndex(1);
             SyllogisticRules.conditionalDedInd(
                 (Implication) beliefTerm, bIndex, taskTerm, tIndex, memory);
           }
           break;
       }
       break;
     case TermLink.COMPOUND:
       switch (bLink.getType()) {
         case TermLink.COMPOUND:
           compoundAndCompound((CompoundTerm) taskTerm, (CompoundTerm) beliefTerm, memory);
           break;
         case TermLink.COMPOUND_STATEMENT:
           compoundAndStatement(
               (CompoundTerm) taskTerm,
               tIndex,
               (Statement) beliefTerm,
               bIndex,
               beliefTerm,
               memory);
           break;
         case TermLink.COMPOUND_CONDITION:
           if (belief != null) {
             if (beliefTerm instanceof Implication) {
               SyllogisticRules.conditionalDedInd(
                   (Implication) beliefTerm, bIndex, taskTerm, -1, memory);
             } else if (beliefTerm instanceof Equivalence) {
               SyllogisticRules.conditionalAna(
                   (Equivalence) beliefTerm, bIndex, taskTerm, -1, memory);
             }
           }
           break;
       }
       break;
     case TermLink.COMPOUND_STATEMENT:
       switch (bLink.getType()) {
         case TermLink.COMPONENT:
           componentAndStatement(
               (CompoundTerm) memory.currentTerm, bIndex, (Statement) taskTerm, tIndex, memory);
           break;
         case TermLink.COMPOUND:
           compoundAndStatement(
               (CompoundTerm) beliefTerm,
               bIndex,
               (Statement) taskTerm,
               tIndex,
               beliefTerm,
               memory);
           break;
         case TermLink.COMPOUND_STATEMENT:
           if (belief != null) {
             //                            bIndex = bLink.getIndex(1);
             syllogisms(tLink, bLink, taskTerm, beliefTerm, memory);
           }
           break;
         case TermLink.COMPOUND_CONDITION:
           if (belief != null) {
             bIndex = bLink.getIndex(1);
             if (beliefTerm instanceof Implication) {
               conditionalDedIndWithVar(
                   (Implication) beliefTerm, bIndex, (Statement) taskTerm, tIndex, memory);
             }
           }
           break;
       }
       break;
     case TermLink.COMPOUND_CONDITION:
       switch (bLink.getType()) {
         case TermLink.COMPOUND_STATEMENT:
           if (belief != null) {
             //                            if (beliefTerm instanceof Implication)
             // TODO adding instanceof test changes results of Example-NAL6-in.txt
             // TODO maybe put instanceof test within conditionalDedIndWithVar()
             conditionalDedIndWithVar(
                 (Implication) taskTerm, tIndex, (Statement) beliefTerm, bIndex, memory);
           }
           break;
       }
       break;
   }
 }