<commit_before>/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.opennars.control;

import org.opennars.entity.*;
import org.opennars.inference.TemporalRules;
import org.opennars.inference.TruthFunctions;
import org.opennars.io.Symbols;
import org.opennars.io.events.Events;
import org.opennars.io.events.OutputHandler;
import org.opennars.language.*;
import org.opennars.main.Parameters;
import org.opennars.operator.FunctionOperator;
import org.opennars.operator.Operation;
import org.opennars.operator.Operator;
import org.opennars.operator.mental.*;
import org.opennars.plugin.mental.InternalExperience;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.opennars.inference.LocalRules.*;

public class ConceptProcessing {
    /**
     * Directly process a new task. Called exactly once on each task. Using
     * local information and finishing in a constant time. Provide feedback in
     * the taskBudget value of the task.
     * <p>
     * called in Memory.immediateProcess only
     *
     * @param task The task to be processed
     * @return whether it was processed
     */
    public static boolean processTask(final Concept concept, final DerivationContext nal, final Task task) {
        if(task.isInput()) {
            if(task.sentence.isJudgment() && !task.sentence.isEternal() && task.sentence.term instanceof Operation) {
                final Operation op = (Operation) task.sentence.term;
                final Operator o = (Operator) op.getPredicate();
                //only consider these mental ops an operation to track when executed not already when generated as internal event
                if(!(o instanceof Believe) && !(o instanceof Want) && !(o instanceof Wonder)
                        && !(o instanceof Evaluate) && !(o instanceof Anticipate)) {
                    TemporalInferenceControl.NewOperationFrame(nal.memory, task);
                }
            }
            concept.observable = true;
        }

        final char type = task.sentence.punctuation;
        switch (type) {
            case Symbols.JUDGMENT_MARK:
                //memory.logic.JUDGMENT_PROCESS.commit();
                processJudgment(concept, nal, task);
                break;
            case Symbols.GOAL_MARK:
                //memory.logic.GOAL_PROCESS.commit();
                processGoal(concept, nal, task, true);
                break;
            case Symbols.QUESTION_MARK:
            case Symbols.QUEST_MARK:
                //memory.logic.QUESTION_PROCESS.commit();
                processQuestion(concept, nal, task);
                break;
            default:
                return false;
        }

        maintainDisappointedAnticipations(concept);

        if (task.aboveThreshold()) {    // still need to be processed
            //memory.logic.LINK_TO_TASK.commit();
            concept.linkToTask(task,nal);
        }

        return true;
    }

    /**
     * To accept a new judgment as belief, and check for revisions and solutions
     *
     * @param judg The judgment to be accepted
     * @param task The task to be processed
     * @return Whether to continue the processing of the task
     */
    protected static void processJudgment(final Concept concept, final DerivationContext nal, final Task task) {
        final Sentence judg = task.sentence;

        final boolean satisfiesAnticipation =
            task.isInput() &&
            !task.sentence.isEternal() &&
            concept.negConfirmation != null &&
            task.sentence.getOccurenceTime() > concept.negConfirm_abort_mintime;
        if(satisfiesAnticipation) {
            if(task.sentence.truth.getExpectation() > Parameters.DEFAULT_CONFIRMATION_EXPECTATION) {
                if(((Statement) concept.negConfirmation.sentence.term).getPredicate().equals(task.sentence.getTerm())) {
                    nal.memory.emit(OutputHandler.CONFIRM.class, ((Statement)concept.negConfirmation.sentence.term).getPredicate());
                    concept.negConfirmation = null; // confirmed
                }
            }
        }

        final Task oldBeliefT = concept.selectCandidate(task, concept.beliefs);   // only revise with the strongest -- how about projection?
        Sentence oldBelief = null;
        boolean wasRevised = false;
        if (oldBeliefT != null) {
            oldBelief = oldBeliefT.sentence;
            final Stamp newStamp = judg.stamp;
            final Stamp oldStamp = oldBelief.stamp;       //when table is full, the latter check is especially important too
            if (newStamp.equals(oldStamp,false,false,true)) {
                //if (task.getParentTask() != null && task.getParentTask().sentence.isJudgment()) {<commit_msg>Refactor: ConceptProcessing.processJudgment(): introduced var + fused if<commit_after>/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.opennars.control;

import org.opennars.entity.*;
import org.opennars.inference.TemporalRules;
import org.opennars.inference.TruthFunctions;
import org.opennars.io.Symbols;
import org.opennars.io.events.Events;
import org.opennars.io.events.OutputHandler;
import org.opennars.language.*;
import org.opennars.main.Parameters;
import org.opennars.operator.FunctionOperator;
import org.opennars.operator.Operation;
import org.opennars.operator.Operator;
import org.opennars.operator.mental.*;
import org.opennars.plugin.mental.InternalExperience;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.opennars.inference.LocalRules.*;

public class ConceptProcessing {
    /**
     * Directly process a new task. Called exactly once on each task. Using
     * local information and finishing in a constant time. Provide feedback in
     * the taskBudget value of the task.
     * <p>
     * called in Memory.immediateProcess only
     *
     * @param task The task to be processed
     * @return whether it was processed
     */
    public static boolean processTask(final Concept concept, final DerivationContext nal, final Task task) {
        if(task.isInput()) {
            if(task.sentence.isJudgment() && !task.sentence.isEternal() && task.sentence.term instanceof Operation) {
                final Operation op = (Operation) task.sentence.term;
                final Operator o = (Operator) op.getPredicate();
                //only consider these mental ops an operation to track when executed not already when generated as internal event
                if(!(o instanceof Believe) && !(o instanceof Want) && !(o instanceof Wonder)
                        && !(o instanceof Evaluate) && !(o instanceof Anticipate)) {
                    TemporalInferenceControl.NewOperationFrame(nal.memory, task);
                }
            }
            concept.observable = true;
        }

        final char type = task.sentence.punctuation;
        switch (type) {
            case Symbols.JUDGMENT_MARK:
                //memory.logic.JUDGMENT_PROCESS.commit();
                processJudgment(concept, nal, task);
                break;
            case Symbols.GOAL_MARK:
                //memory.logic.GOAL_PROCESS.commit();
                processGoal(concept, nal, task, true);
                break;
            case Symbols.QUESTION_MARK:
            case Symbols.QUEST_MARK:
                //memory.logic.QUESTION_PROCESS.commit();
                processQuestion(concept, nal, task);
                break;
            default:
                return false;
        }

        maintainDisappointedAnticipations(concept);

        if (task.aboveThreshold()) {    // still need to be processed
            //memory.logic.LINK_TO_TASK.commit();
            concept.linkToTask(task,nal);
        }

        return true;
    }

    /**
     * To accept a new judgment as belief, and check for revisions and solutions
     *
     * @param judg The judgment to be accepted
     * @param task The task to be processed
     * @return Whether to continue the processing of the task
     */
    protected static void processJudgment(final Concept concept, final DerivationContext nal, final Task task) {
        final Sentence judg = task.sentence;

        final boolean satisfiesAnticipation =
            task.isInput() &&
            !task.sentence.isEternal() &&
            concept.negConfirmation != null &&
            task.sentence.getOccurenceTime() > concept.negConfirm_abort_mintime;

        final boolean isExpectactionAbliveThreshold = task.sentence.truth.getExpectation() > Parameters.DEFAULT_CONFIRMATION_EXPECTATION;

        if(
            satisfiesAnticipation && isExpectactionAbliveThreshold &&
            ((Statement) concept.negConfirmation.sentence.term).getPredicate().equals(task.sentence.getTerm())
        ) {
            nal.memory.emit(OutputHandler.CONFIRM.class, ((Statement)concept.negConfirmation.sentence.term).getPredicate());
            concept.negConfirmation = null; // confirmed
        }

        final Task oldBeliefT = concept.selectCandidate(task, concept.beliefs);   // only revise with the strongest -- how about projection?
        Sentence oldBelief = null;
        boolean wasRevised = false;
        if (oldBeliefT != null) {
            oldBelief = oldBeliefT.sentence;
            final Stamp newStamp = judg.stamp;
            final Stamp oldStamp = oldBelief.stamp;       //when table is full, the latter check is especially important too
            if (newStamp.equals(oldStamp,false,false,true)) {
                //if (task.getParentTask() != null && task.getParentTask().sentence.isJudgment()) {
{'fraction_non_alphanumeric': 0.08941740412979352, 'fraction_numerical': 0.00018436578171091445, 'mean_word_length': 2.507597801487229, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6611574', 'n_tokens_mistral': 2961, 'n_tokens_neox': 2810, 'n_words': 846}