diff --git a/nars_core/nars/control/DerivationContext.java b/nars_core/nars/control/DerivationContext.java index 47b9e0b4d2735bc3883780188ec421fa5e17651c..8e12f4d3c49b7c371f82fb9bc00dc6dca56b1f5c 100644 --- a/nars_core/nars/control/DerivationContext.java +++ b/nars_core/nars/control/DerivationContext.java @@ -138,12 +138,13 @@ public class DerivationContext { * @param newBudget The budget value in task */ public boolean doublePremiseTaskRevised(final Term newContent, final TruthValue newTruth, final BudgetValue newBudget) { + Stamp derived_stamp = getTheNewStamp().clone(); + this.resetOccurrenceTime(); //stamp was already obsorbed Sentence newSentence = new Sentence( newContent, getCurrentTask().sentence.punctuation, newTruth, - getTheNewStamp()); - + derived_stamp); Task newTask = new Task(newSentence, newBudget, getCurrentBelief()); return derivedTask(newTask, true, false, true); //allows overlap since overlap was already checked on revisable( function } //which is not the case for other single premise tasks @@ -177,13 +178,14 @@ public class DerivationContext { if(newContent.subjectOrPredicateIsIndependentVar()) { return null; } - + Stamp derive_stamp = getTheNewStamp().clone(); //because occurrence time will be reset: + this.resetOccurrenceTime(); //stamp was already obsorbed into task try { final Sentence newSentence = new Sentence( newContent, getCurrentTask().sentence.punctuation, newTruth, - getTheNewStamp()); + derive_stamp); newSentence.producedByTemporalInduction=temporalInduction; final Task newTask = Task.make(newSentence, newBudget, getCurrentTask(), getCurrentBelief()); @@ -206,7 +208,7 @@ public class DerivationContext { try { TruthValue truthEt=TruthFunctions.eternalize(newTruth); - Stamp st=getTheNewStamp().clone(); + Stamp st=derive_stamp.clone(); st.setEternal(); final Sentence newSentence = new Sentence( newContent, @@ -292,12 +294,15 @@ public class DerivationContext { if(newContent instanceof Interval) { return false; } + + Stamp derive_stamp = this.getTheNewStamp().clone(); + this.resetOccurrenceTime(); //stamp was already obsorbed into task Sentence newSentence = new Sentence( newContent, punctuation, newTruth, - getTheNewStamp()); + derive_stamp); Task newTask = Task.make(newSentence, newBudget, getCurrentTask()); if (newTask!=null) { @@ -347,14 +352,20 @@ public class DerivationContext { /** * @return the newStamp */ + private long original_time = 0; public Stamp getTheNewStamp() { if (newStamp == null) { //if newStamp==null then newStampBuilder must be available. cache it's return value as newStamp newStamp = newStampBuilder.build(); + original_time = newStamp.getOccurrenceTime(); newStampBuilder = null; } return newStamp; } + + public void resetOccurrenceTime() { + newStamp.setOccurrenceTime(original_time); + } /** * @param newStamp the newStamp to set diff --git a/nars_core/nars/inference/CompositionalRules.java b/nars_core/nars/inference/CompositionalRules.java index a6b0c20083bdd102ed87cf2c57c60b887fbc0831..4a4cb78100d990ea36ddb12e72b06bd01d64bf92 100644 --- a/nars_core/nars/inference/CompositionalRules.java +++ b/nars_core/nars/inference/CompositionalRules.java @@ -280,7 +280,6 @@ public final class CompositionalRules { nal.getTheNewStamp().setOccurrenceTime(baseTime); } } - nal.doublePremiseTask(content, truth, budget, false, true); //(allow overlap), a form of detachment } } @@ -298,10 +297,11 @@ public final class CompositionalRules { if (isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) && (index != 0)) { return; } + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); if(isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD)) { if(!nal.getCurrentTask().sentence.isEternal() && compound.term[index + 1] instanceof Interval) { long shift_occurrence = ((Interval)compound.term[1]).getTime(nal.memory); - nal.getTheNewStamp().setOccurrenceTime(nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence); + occurrence_time = nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence; } } @@ -316,6 +316,7 @@ public final class CompositionalRules { BudgetValue budget; if (taskSentence.isQuestion() || taskSentence.isQuest()) { budget = BudgetFunctions.compoundBackward(content, nal); + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, false); // special inference to answer conjunctive questions with query variables if (taskSentence.term.hasVarQuery()) { @@ -332,6 +333,7 @@ public final class CompositionalRules { Term conj = Conjunction.make(component, content); truth = intersection(contentBelief.truth, belief.truth); budget = BudgetFunctions.compoundForward(truth, conj, nal); + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(conj, truth, budget, false, false); } } else { @@ -368,6 +370,7 @@ public final class CompositionalRules { } budget = BudgetFunctions.compoundForward(truth, content, nal); } + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, false); } diff --git a/nars_core/nars/inference/SyllogisticRules.java b/nars_core/nars/inference/SyllogisticRules.java index cb2d725f2f36b1490ddc6020ff67b5b42b3cbfa9..04f77927ec64bbdd0367816d56815cf01a899e50 100644 --- a/nars_core/nars/inference/SyllogisticRules.java +++ b/nars_core/nars/inference/SyllogisticRules.java @@ -125,7 +125,7 @@ public final class SyllogisticRules { * removed? * @param nal Reference to the memory */ - static void abdIndCom(final Term term1, final Term term2, final Sentence sentence1, final Sentence sentence2, final int figure, final DerivationContext nal) { + static void abdIndCom(Term term1, Term term2, final Sentence sentence1, final Sentence sentence2, final int figure, final DerivationContext nal) { if (Statement.invalidStatement(term1, term2) || Statement.invalidPair(term1, term2)) { return; } @@ -164,13 +164,30 @@ public final class SyllogisticRules { budget2 = BudgetFunctions.forward(truth2, nal); budget3 = BudgetFunctions.forward(truth3, nal); } + + long delta2 = 0; + while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) term2).term[0]; + delta2 += interval.getTime(nal.memory); + term2 = ((CompoundTerm)term2).setComponent(0, null, nal.mem()); + } + long delta1 = 0; + while ((term1 instanceof Conjunction) && (((CompoundTerm) term1).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) term1).term[0]; + delta1 += interval.getTime(nal.memory); + term1 = ((CompoundTerm)term1).setComponent(0, null, nal.mem()); + } + if (order != ORDER_INVALID) { + nal.getTheNewStamp().setOccurrenceTime(delta1); nal.doublePremiseTask( Statement.make(taskContent, term1, term2, order), truth1, budget1,false, false); + nal.getTheNewStamp().setOccurrenceTime(delta2); nal.doublePremiseTask( Statement.make(taskContent, term2, term1, reverseOrder(order)), truth2, budget2,false, false); + nal.getTheNewStamp().setOccurrenceTime(delta1); nal.doublePremiseTask( Statement.makeSym(taskContent, term1, term2, order), truth3, budget3,false, false); @@ -397,14 +414,14 @@ public final class SyllogisticRules { return; int order = statement.getTemporalOrder(); + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); if ((order != ORDER_NONE) && (order!=ORDER_INVALID)) { long baseTime = subSentence.getOccurenceTime(); if (baseTime == Stamp.ETERNAL) { // =/> always should produce events baseTime = nal.getTime(); } long inc = order * nal.mem().param.duration.get(); - long time = (side == 0) ? baseTime+inc : baseTime-inc; - nal.getTheNewStamp().setOccurrenceTime(time); + occurrence_time = (side == 0) ? baseTime+inc : baseTime-inc; } TruthValue beliefTruth = beliefSentence.truth; @@ -455,6 +472,7 @@ public final class SyllogisticRules { } if(!Variables.indepVarUsedInvalid(content)) { boolean allowOverlap = taskSentence.isJudgment() && strong; + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, allowOverlap); //(strong) when strong on judgement } } @@ -574,22 +592,12 @@ public final class SyllogisticRules { if (content == null) return; - if(!predictedEvent && !((Conjunction) subj).isSpatial && ((Conjunction) subj).getTemporalOrder() == TemporalRules.ORDER_FORWARD) { //do not allow sequences - boolean last_ival = false; //which have two intervals as result of this, makes sure we only detach (&/ from left side - for(Term t: ((Conjunction) subj).term) { - boolean ival = t instanceof Interval; - if(last_ival && ival) { - return; - } - last_ival = ival; - } - } - + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); if (delta != 0) { long baseTime = taskSentence.getOccurenceTime(); if (baseTime != Stamp.ETERNAL) { baseTime += delta; - nal.getTheNewStamp().setOccurrenceTime(baseTime); + occurrence_time = baseTime; } } @@ -620,6 +628,7 @@ public final class SyllogisticRules { budget = BudgetFunctions.forward(truth, nal); } + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); List<Task> ret = nal.doublePremiseTask(content, truth, budget,false, taskSentence.isJudgment() && deduction); //(allow overlap) when deduction on judgment if(!nal.evidentalOverlap && ret != null && ret.size() > 0) { if(predictedEvent && taskSentence.isJudgment() && truth != null && truth.getExpectation() > Parameters.DEFAULT_CONFIRMATION_EXPECTATION &&