Program: 166693
Project: 166693
Buggy source:
/** 
 * 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(final TaskLink tLink,final TermLink bLink,final DerivationContext nal){
  final Memory memory=nal.mem();
  final Task task=nal.getCurrentTask();
  final Sentence taskSentence=task.sentence;
  final Term taskTerm=taskSentence.term;
  Term beliefTerm=bLink.target;
  final Concept beliefConcept=memory.concept(beliefTerm);
  Sentence belief=(beliefConcept != null) ? beliefConcept.getBelief(nal,task) : null;
  nal.setCurrentBelief(belief);
  if (belief != null) {
    beliefTerm=belief.term;
    if (Stamp.baseOverlap(task.sentence.stamp.evidentialBase,belief.stamp.evidentialBase)) {
      nal.evidentalOverlap=true;
      if (!task.sentence.isEternal() || !belief.isEternal()) {
        return;
      }
    }
    nal.emit(Events.BeliefReason.class,belief,beliefTerm,taskTerm,nal);
    if (LocalRules.match(task,belief,nal)) {
      return;
    }
  }
  nal.setCurrentBelief(belief);
  nal.setCurrentTask(task);
  if (equalSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm))   return;
  final short tIndex=tLink.getIndex(0);
  short bIndex=bLink.getIndex(0);
switch (tLink.type) {
case TermLink.SELF:
switch (bLink.type) {
case TermLink.COMPONENT:
      compoundAndSelf((CompoundTerm)taskTerm,beliefTerm,true,bIndex,nal);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,bIndex,nal);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Statement) {
  SyllogisticRules.detachment(taskSentence,belief,bIndex,nal);
}
}
if (taskSentence.term instanceof Inheritance || taskSentence.term instanceof Similarity) {
StructuralRules.transformNegation((CompoundTerm)Negation.make(taskSentence.term),nal);
}
try {
goalFromQuestion(task,taskTerm,nal);
}
 catch (Exception ex) {
if (Parameters.DEBUG) {
System.out.print("String_Node_Str");
}
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,taskSentence,bIndex,nal);
}
break;
case TermLink.COMPONENT_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd(task.sentence,(Implication)taskTerm,bIndex,beliefTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication) && (beliefTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd(belief,(Implication)beliefTerm,bIndex,taskTerm,tIndex,nal);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.type) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,tIndex,bIndex,nal);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,nal);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
Term[] u=new Term[]{beliefTerm,taskTerm};
if (Variables.unify(VAR_INDEPENDENT,((Statement)beliefTerm).getSubject(),taskTerm,u,true)) {
Sentence newBelief=belief.clone(u[0]);
Sentence newTaskSentence=taskSentence.clone(u[1]);
detachmentWithVar(newBelief,newTaskSentence,bIndex,false,nal);
}
 else {
SyllogisticRules.conditionalDedInd(belief,(Implication)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.type) {
case TermLink.COMPONENT:
if (taskTerm instanceof Statement) {
goalFromWantBelief(task,tIndex,bIndex,taskTerm,nal,beliefTerm);
componentAndStatement((CompoundTerm)nal.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND:
if (taskTerm instanceof Statement) {
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if ((taskTerm instanceof Statement) && (beliefTerm instanceof Implication)) {
conditionalDedIndWithVar(belief,(Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.type) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Statement)taskTerm).getSubject();
if (subj instanceof Negation) {
if (taskSentence.isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,nal);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
 else {
conditionalDedIndWithVar(task.sentence,(Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
break;
}
break;
}
}
}

Fixed version (ground truth):
/** 
 * 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(final TaskLink tLink,final TermLink bLink,final DerivationContext nal){
  final Memory memory=nal.mem();
  final Task task=nal.getCurrentTask();
  final Sentence taskSentence=task.sentence;
  final Term taskTerm=taskSentence.term;
  Term beliefTerm=bLink.target;
  final Concept beliefConcept=memory.concept(beliefTerm);
  Sentence belief=(beliefConcept != null) ? beliefConcept.getBelief(nal,task) : null;
  nal.setCurrentBelief(belief);
  if (belief != null) {
    beliefTerm=belief.term;
    nal.evidentalOverlap=Stamp.baseOverlap(task.sentence.stamp.evidentialBase,belief.stamp.evidentialBase);
    if (nal.evidentalOverlap && (!task.sentence.isEternal() || !belief.isEternal())) {
      return;
    }
    nal.emit(Events.BeliefReason.class,belief,beliefTerm,taskTerm,nal);
    if (LocalRules.match(task,belief,nal)) {
      return;
    }
  }
  nal.setCurrentBelief(belief);
  nal.setCurrentTask(task);
  if (equalSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm))   return;
  final short tIndex=tLink.getIndex(0);
  short bIndex=bLink.getIndex(0);
switch (tLink.type) {
case TermLink.SELF:
switch (bLink.type) {
case TermLink.COMPONENT:
      compoundAndSelf((CompoundTerm)taskTerm,beliefTerm,true,bIndex,nal);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,bIndex,nal);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Statement) {
  SyllogisticRules.detachment(taskSentence,belief,bIndex,nal);
}
}
if (taskSentence.term instanceof Inheritance || taskSentence.term instanceof Similarity) {
StructuralRules.transformNegation((CompoundTerm)Negation.make(taskSentence.term),nal);
}
try {
goalFromQuestion(task,taskTerm,nal);
}
 catch (Exception ex) {
if (Parameters.DEBUG) {
System.out.print("String_Node_Str");
}
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,taskSentence,bIndex,nal);
}
break;
case TermLink.COMPONENT_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd(task.sentence,(Implication)taskTerm,bIndex,beliefTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication) && (beliefTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd(belief,(Implication)beliefTerm,bIndex,taskTerm,tIndex,nal);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.type) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,tIndex,bIndex,nal);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,nal);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
Term[] u=new Term[]{beliefTerm,taskTerm};
if (Variables.unify(VAR_INDEPENDENT,((Statement)beliefTerm).getSubject(),taskTerm,u,true)) {
Sentence newBelief=belief.clone(u[0]);
Sentence newTaskSentence=taskSentence.clone(u[1]);
detachmentWithVar(newBelief,newTaskSentence,bIndex,false,nal);
}
 else {
SyllogisticRules.conditionalDedInd(belief,(Implication)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.type) {
case TermLink.COMPONENT:
if (taskTerm instanceof Statement) {
goalFromWantBelief(task,tIndex,bIndex,taskTerm,nal,beliefTerm);
componentAndStatement((CompoundTerm)nal.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND:
if (taskTerm instanceof Statement) {
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if ((taskTerm instanceof Statement) && (beliefTerm instanceof Implication)) {
conditionalDedIndWithVar(belief,(Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.type) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Statement)taskTerm).getSubject();
if (subj instanceof Negation) {
if (taskSentence.isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,nal);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
 else {
conditionalDedIndWithVar(task.sentence,(Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
break;
}
break;
}
}
}