/**
  * Try to make a new compound from a set of term. Called by the public make methods.
  *
  * @param set a set of Term as compoments
  * @param memory Reference to the memory
  * @return the Term generated from the arguments
  */
 public static Term make(TreeSet<Term> set, Memory memory) {
   if (set.size() == 1) {
     return set.first();
   } // special case: single component
   Term[] argument = set.toArray(new Term[set.size()]);
   CharSequence name = makeCompoundName(NativeOperator.INTERSECTION_EXT, argument);
   Term t = memory.conceptTerm(name);
   return (t != null) ? t : new IntersectionExt(name, argument);
 }
Esempio 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;
   }
 }