Beispiel #1
0
 /**
  * Meta-table of syllogistic rules, indexed by the content classes of the taskSentence and the
  * belief
  *
  * @param tLink The link to task
  * @param bLink The link to belief
  * @param taskTerm The content of task
  * @param beliefTerm The content of belief
  * @param memory Reference to the memory
  */
 private static void syllogisms(
     TaskLink tLink, TermLink bLink, Term taskTerm, Term beliefTerm, Memory memory) {
   Sentence taskSentence = memory.currentTask.getSentence();
   Sentence belief = memory.currentBelief;
   int figure;
   if (taskTerm instanceof Inheritance) {
     if (beliefTerm instanceof Inheritance) {
       figure = indexToFigure(tLink, bLink);
       asymmetricAsymmetric(taskSentence, belief, figure, memory);
     } else if (beliefTerm instanceof Similarity) {
       figure = indexToFigure(tLink, bLink);
       asymmetricSymmetric(taskSentence, belief, figure, memory);
     } else {
       detachmentWithVar(belief, taskSentence, bLink.getIndex(0), memory);
     }
   } else if (taskTerm instanceof Similarity) {
     if (beliefTerm instanceof Inheritance) {
       figure = indexToFigure(bLink, tLink);
       asymmetricSymmetric(belief, taskSentence, figure, memory);
     } else if (beliefTerm instanceof Similarity) {
       figure = indexToFigure(bLink, tLink);
       symmetricSymmetric(belief, taskSentence, figure, memory);
     }
   } else if (taskTerm instanceof Implication) {
     if (beliefTerm instanceof Implication) {
       figure = indexToFigure(tLink, bLink);
       asymmetricAsymmetric(taskSentence, belief, figure, memory);
     } else if (beliefTerm instanceof Equivalence) {
       figure = indexToFigure(tLink, bLink);
       asymmetricSymmetric(taskSentence, belief, figure, memory);
     } else if (beliefTerm instanceof Inheritance) {
       detachmentWithVar(taskSentence, belief, tLink.getIndex(0), memory);
     }
   } else if (taskTerm instanceof Equivalence) {
     if (beliefTerm instanceof Implication) {
       figure = indexToFigure(bLink, tLink);
       asymmetricSymmetric(belief, taskSentence, figure, memory);
     } else if (beliefTerm instanceof Equivalence) {
       figure = indexToFigure(bLink, tLink);
       symmetricSymmetric(belief, taskSentence, figure, memory);
     } else if (beliefTerm instanceof Inheritance) {
       detachmentWithVar(taskSentence, belief, tLink.getIndex(0), memory);
     }
   }
 }
Beispiel #2
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);
   }
 }
Beispiel #3
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;
   }
 }