<commit_before>package nars.nar;

import com.google.common.util.concurrent.AtomicDouble;
import nars.Global;
import nars.LocalMemory;
import nars.Memory;
import nars.NAR;
import nars.bag.Bag;
import nars.bag.impl.CurveBag;
import nars.budget.Budget;
import nars.budget.ItemAccumulator;
import nars.clock.CycleClock;
import nars.concept.*;
import nars.event.CycleReaction;
import nars.link.TaskLink;
import nars.link.TermLink;
import nars.link.TermLinkKey;
import nars.nal.SimpleDeriver;
import nars.nal.nal8.OpReaction;
import nars.nal.nal8.operator.NullOperator;
import nars.nal.nal8.operator.eval;
import nars.op.app.STMEventInference;
import nars.op.data.Flat;
import nars.op.data.json;
import nars.op.data.similaritree;
import nars.op.io.echo;
import nars.op.io.reset;
import nars.op.io.say;
import nars.op.io.schizo;
import nars.op.math.add;
import nars.op.math.count;
import nars.op.mental.*;
import nars.op.meta.complexity;
import nars.op.meta.reflect;
import nars.op.software.js;
import nars.op.software.scheme.scheme;
import nars.process.ConceptProcess;
import nars.process.TaskProcess;
import nars.task.Sentence;
import nars.task.Task;
import nars.term.Atom;
import nars.term.Term;
import nars.util.data.MutableInteger;
import nars.util.data.random.XorShift1024StarRandom;
import nars.util.event.On;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static nars.op.mental.InternalExperience.InternalExperienceMode.Full;
import static nars.op.mental.InternalExperience.InternalExperienceMode.Minimal;


/**
 * Default set of NAR parameters which have been classically used for development.
 * <p>
 * WARNING this Seed is not immutable yet because it extends Param,
 * which is supposed to be per-instance/mutable. So do not attempt
 * to create multiple NAR with the same Default seed model
 */
public class Default extends NAR {

    public static final OpReaction[] exampleOperators = new OpReaction[]{
            //new Wait(),
            new NullOperator("break"),
            new NullOperator("drop"),
            new NullOperator("goto"),
            new NullOperator("open"),
            new NullOperator("pick"),
            new NullOperator("strike"),
            new NullOperator("throw"),
            new NullOperator("activate"),
            new NullOperator("deactivate")
    };

    //public final Random rng = new RandomAdaptor(new MersenneTwister(1));
    public final Random rng = new XorShift1024StarRandom(1);

    public final OpReaction[] defaultOperators = new OpReaction[]{

            //system control
            echo.the,
            //PauseInput.the,
            new reset(),
            new eval(),
            //new Wait(),

            new believe(),  // accept a statement with a default truth-value
            new want(),     // accept a statement with a default desire-value
            new wonder(),   // find the truth-value of a statement
            new evaluate(), // find the desire-value of a statement
            //concept operations for internal perceptions
            new remind(),   // create/activate a concept
            new consider(),  // do one inference step on a concept
            new name(),         // turn a compount term into an atomic term
            //new Abbreviate(),
            //new Register(),
            new doubt(),        // decrease the confidence of a belief
            new hesitate(),      // decrease the confidence of a goal

            //Meta
            new reflect(),

            // feeling operations
            new feelHappy(),
            new feelBusy(),

            // math operations
            new count(),
            new add(),
            //new MathExpression(),

            new complexity(),

            //Term manipulation
            new Flat.flatProduct(),
            new similaritree(),

            //TODO move Javascript to a UnsafeOperators set, because of remote execution issues
            new scheme(),      // scheme evaluation

            //new NumericCertainty(),

            //io operations
            new say(),

            new schizo(),     //change Memory's SELF term (default: SELF)

            new js(), //javascdript evalaution

            new json.jsonfrom(),
            new json.jsonto()
         /*
+         *          I/O operations under consideration
+         * observe          // get the most active input (Channel ID: optional?)
+         * anticipate       // get the input matching a given statement with variables (Channel ID: optional?)
+         * tell             // output a judgment (Channel ID: optional?)
+         * ask              // output a question/quest (Channel ID: optional?)
+         * demand           // output a goal (Channel ID: optional?)
+         */

//        new Wait()              // wait for a certain number of clock cycle


        /*
         * -think            // carry out a working cycle
         * -do               // turn a statement into a goal
         *
         * possibility      // return the possibility of a term
         * doubt            // decrease the confidence of a belief
         * hesitate         // decrease the confidence of a goal
         *
         * feel             // the overall happyness, average solution quality, and predictions
         * busy             // the overall business
         *


         * do               // to turn a judgment into a goal (production rule) ??

         *
         * count            // count the number of elements in a set
         * arithmatic       // + - * /
         * comparisons      // < = >
         * logic        // binary logic
         *



         * -assume           // local assumption ???
         *
         * observe          // get the most active input (Channel ID: optional?)
         * anticipate       // get input of a certain pattern (Channel ID: optional?)
         * tell             // output a judgment (Channel ID: optional?)
         * ask              // output a question/quest (Channel ID: optional?)
         * demand           // output a goal (Channel ID: optional?)


        * name             // turn a compount term into an atomic term ???
         * -???              // rememberAction the history of the system? excutions of operatons?
         */
    };
    public final DefaultCycle core;
    public int cyclesPerFrame = 1;

    /**
     * Size of TaskLinkBag
     */
    int taskLinkBagSize;
    /**
     * Size of TermLinkBag
     */
    int termLinkBagSize;

    InternalExperience.InternalExperienceMode internalExperience;

    /**
     * Default DEFAULTS
     */
    public Default() {
        this(768, 1, 2, 3);
    }

    public Default(int maxConcepts, int conceptsFirePerCycle, int termLinksPerCycle, int taskLinksPerCycle) {
        this(new LocalMemory(new CycleClock()), maxConcepts, conceptsFirePerCycle, termLinksPerCycle, taskLinksPerCycle);
    }

    public Default(Memory m, int maxConcepts, int conceptsFirePerCycle, int termLinksPerCycle, int taskLinksPerCycle) {
        super(m);

        //termLinkMaxMatched.set(5);


        //Build Parameters
        this.maxNALLevel = Global.DEFAULT_NAL_LEVEL;
        this.internalExperience = InternalExperience.InternalExperienceMode.None; //much too early, this is nonsensical without working NAL

        setTaskLinkBagSize(8);
        setTermLinkBagSize(16);


        m.duration.set(5);
        m.shortTermMemoryHistory.set(5);
        m.conceptActivationFactor.set(1.0);
        m.conceptFireThreshold.set(0.0);

        m.conceptForgetDurations.set(1.0);
        m.taskLinkForgetDurations.set(2.0);
        m.termLinkForgetDurations.set(3.0);

        m.conceptBeliefsMax.set(11);
        m.conceptGoalsMax.set(5);
        m.conceptQuestionsMax.set(4);
        m.activeConceptThreshold.set(0.0);
        m.questionFromGoalThreshold.set(0.35);
        m.taskProcessThreshold.set(Global.BUDGET_EPSILON*2);
        m.termLinkThreshold.set(0); //Global.BUDGET_EPSILON);
        m.taskLinkThreshold.set(0); //Global.BUDGET_EPSILON);
        m.executionThreshold.set(0.5);

        //m.reliance.set(Global.DEFAULT_JUDGMENT_CONFIDENCE);
        m.conceptCreationExpectation.set(0);//.66);

        setCyclesPerFrame(cyclesPerFrame);

        //core loop
        {
            DefaultCycle c = this.core = new DefaultCycle(
                    m.the("defaultCore", this),
                    m.the("logic", getDeriver()),
                    new ConceptBagActivator(this),
                    m.the("inputBuffer", new ItemAccumulator(Budget.max)),
                    newConceptBag()
            );
            m.the("core", c);

            c.conceptsFired = conceptsFirePerCycle;
            c.termlinks = termLinksPerCycle; //TODO make mutable int
            c.tasklinks = taskLinksPerCycle; //TODO make mutable int
            c.capacity.set(maxConcepts);
            c.inputsMaxPerCycle.set(conceptsFirePerCycle);
            c.conceptsFiredPerCycle.set(conceptsFirePerCycle);

        }

        if (maxNALLevel >= 7) {

            //scope: control
            m.the(new PerceptionAccel(this, () -> core.next()));
            m.the(new STMEventInference(this, core.deriver ) );

            if (maxNALLevel >= 8) {

                for (OpReaction o : defaultOperators)
                    on(o);
                /*for (OpReaction o : exampleOperators)
                    on(o);*/

                //n.on(Anticipate.class);      // expect an event

                if (internalExperience == Minimal) {
                    new InternalExperience(this);
                    new Abbreviation(this);
                } else if (internalExperience == Full) {
                    on(FullInternalExperience.class);
                    on(Counting.class);
                }
            }
        }
        //n.on(new RuntimeNARSettings());<commit_msg>nope, no hacks in the new clean design. ^^<commit_after>package nars.nar;

import com.google.common.util.concurrent.AtomicDouble;
import nars.Global;
import nars.LocalMemory;
import nars.Memory;
import nars.NAR;
import nars.bag.Bag;
import nars.bag.impl.CurveBag;
import nars.budget.Budget;
import nars.budget.ItemAccumulator;
import nars.clock.CycleClock;
import nars.concept.*;
import nars.event.CycleReaction;
import nars.link.TaskLink;
import nars.link.TermLink;
import nars.link.TermLinkKey;
import nars.nal.SimpleDeriver;
import nars.nal.nal8.OpReaction;
import nars.nal.nal8.operator.NullOperator;
import nars.nal.nal8.operator.eval;
import nars.op.app.STMEventInference;
import nars.op.data.Flat;
import nars.op.data.json;
import nars.op.data.similaritree;
import nars.op.io.echo;
import nars.op.io.reset;
import nars.op.io.say;
import nars.op.io.schizo;
import nars.op.math.add;
import nars.op.math.count;
import nars.op.mental.*;
import nars.op.meta.complexity;
import nars.op.meta.reflect;
import nars.op.software.js;
import nars.op.software.scheme.scheme;
import nars.process.ConceptProcess;
import nars.process.TaskProcess;
import nars.task.Sentence;
import nars.task.Task;
import nars.term.Atom;
import nars.term.Term;
import nars.util.data.MutableInteger;
import nars.util.data.random.XorShift1024StarRandom;
import nars.util.event.On;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static nars.op.mental.InternalExperience.InternalExperienceMode.Full;
import static nars.op.mental.InternalExperience.InternalExperienceMode.Minimal;


/**
 * Default set of NAR parameters which have been classically used for development.
 * <p>
 * WARNING this Seed is not immutable yet because it extends Param,
 * which is supposed to be per-instance/mutable. So do not attempt
 * to create multiple NAR with the same Default seed model
 */
public class Default extends NAR {

    public static final OpReaction[] exampleOperators = new OpReaction[]{
            //new Wait(),
            new NullOperator("break"),
            new NullOperator("drop"),
            new NullOperator("goto"),
            new NullOperator("open"),
            new NullOperator("pick"),
            new NullOperator("strike"),
            new NullOperator("throw"),
            new NullOperator("activate"),
            new NullOperator("deactivate")
    };

    //public final Random rng = new RandomAdaptor(new MersenneTwister(1));
    public final Random rng = new XorShift1024StarRandom(1);

    public final OpReaction[] defaultOperators = new OpReaction[]{

            //system control
            echo.the,
            //PauseInput.the,
            new reset(),
            new eval(),
            //new Wait(),

            new believe(),  // accept a statement with a default truth-value
            new want(),     // accept a statement with a default desire-value
            new wonder(),   // find the truth-value of a statement
            new evaluate(), // find the desire-value of a statement
            //concept operations for internal perceptions
            new remind(),   // create/activate a concept
            new consider(),  // do one inference step on a concept
            new name(),         // turn a compount term into an atomic term
            //new Abbreviate(),
            //new Register(),
            new doubt(),        // decrease the confidence of a belief
            new hesitate(),      // decrease the confidence of a goal

            //Meta
            new reflect(),

            // feeling operations
            new feelHappy(),
            new feelBusy(),

            // math operations
            new count(),
            new add(),
            //new MathExpression(),

            new complexity(),

            //Term manipulation
            new Flat.flatProduct(),
            new similaritree(),

            //TODO move Javascript to a UnsafeOperators set, because of remote execution issues
            new scheme(),      // scheme evaluation

            //new NumericCertainty(),

            //io operations
            new say(),

            new schizo(),     //change Memory's SELF term (default: SELF)

            new js(), //javascdript evalaution

            new json.jsonfrom(),
            new json.jsonto()
         /*
+         *          I/O operations under consideration
+         * observe          // get the most active input (Channel ID: optional?)
+         * anticipate       // get the input matching a given statement with variables (Channel ID: optional?)
+         * tell             // output a judgment (Channel ID: optional?)
+         * ask              // output a question/quest (Channel ID: optional?)
+         * demand           // output a goal (Channel ID: optional?)
+         */

//        new Wait()              // wait for a certain number of clock cycle


        /*
         * -think            // carry out a working cycle
         * -do               // turn a statement into a goal
         *
         * possibility      // return the possibility of a term
         * doubt            // decrease the confidence of a belief
         * hesitate         // decrease the confidence of a goal
         *
         * feel             // the overall happyness, average solution quality, and predictions
         * busy             // the overall business
         *


         * do               // to turn a judgment into a goal (production rule) ??

         *
         * count            // count the number of elements in a set
         * arithmatic       // + - * /
         * comparisons      // < = >
         * logic        // binary logic
         *



         * -assume           // local assumption ???
         *
         * observe          // get the most active input (Channel ID: optional?)
         * anticipate       // get input of a certain pattern (Channel ID: optional?)
         * tell             // output a judgment (Channel ID: optional?)
         * ask              // output a question/quest (Channel ID: optional?)
         * demand           // output a goal (Channel ID: optional?)


        * name             // turn a compount term into an atomic term ???
         * -???              // rememberAction the history of the system? excutions of operatons?
         */
    };
    public final DefaultCycle core;
    public int cyclesPerFrame = 1;

    /**
     * Size of TaskLinkBag
     */
    int taskLinkBagSize;
    /**
     * Size of TermLinkBag
     */
    int termLinkBagSize;

    InternalExperience.InternalExperienceMode internalExperience;

    /**
     * Default DEFAULTS
     */
    public Default() {
        this(768, 1, 2, 3);
    }

    public Default(int maxConcepts, int conceptsFirePerCycle, int termLinksPerCycle, int taskLinksPerCycle) {
        this(new LocalMemory(new CycleClock()), maxConcepts, conceptsFirePerCycle, termLinksPerCycle, taskLinksPerCycle);
    }

    public Default(Memory m, int maxConcepts, int conceptsFirePerCycle, int termLinksPerCycle, int taskLinksPerCycle) {
        super(m);

        //termLinkMaxMatched.set(5);


        //Build Parameters
        this.maxNALLevel = Global.DEFAULT_NAL_LEVEL;
        this.internalExperience = InternalExperience.InternalExperienceMode.None; //much too early, this is nonsensical without working NAL

        setTaskLinkBagSize(8);
        setTermLinkBagSize(16);


        m.duration.set(5);
        m.shortTermMemoryHistory.set(5);
        m.conceptActivationFactor.set(1.0);
        m.conceptFireThreshold.set(0.0);

        m.conceptForgetDurations.set(1.0);
        m.taskLinkForgetDurations.set(2.0);
        m.termLinkForgetDurations.set(3.0);

        m.conceptBeliefsMax.set(11);
        m.conceptGoalsMax.set(5);
        m.conceptQuestionsMax.set(4);
        m.activeConceptThreshold.set(0.0);
        m.questionFromGoalThreshold.set(0.35);
        m.taskProcessThreshold.set(Global.BUDGET_EPSILON*2);
        m.termLinkThreshold.set(0); //Global.BUDGET_EPSILON);
        m.taskLinkThreshold.set(0); //Global.BUDGET_EPSILON);
        m.executionThreshold.set(0.5);

        //m.reliance.set(Global.DEFAULT_JUDGMENT_CONFIDENCE);
        m.conceptCreationExpectation.set(0);//.66);

        setCyclesPerFrame(cyclesPerFrame);

        //core loop
        {
            DefaultCycle c = this.core = new DefaultCycle(
                    m.the("defaultCore", this),
                    m.the("logic", getDeriver()),
                    new ConceptBagActivator(this),
                    m.the("inputBuffer", new ItemAccumulator(Budget.max)),
                    newConceptBag()
            );
            m.the("core", c);

            c.conceptsFired = conceptsFirePerCycle;
            c.termlinks = termLinksPerCycle; //TODO make mutable int
            c.tasklinks = taskLinksPerCycle; //TODO make mutable int
            c.capacity.set(maxConcepts);
            c.inputsMaxPerCycle.set(conceptsFirePerCycle);
            c.conceptsFiredPerCycle.set(conceptsFirePerCycle);

        }

        if (maxNALLevel >= 7) {

            //scope: control
            m.the(new STMEventInference(this, core.deriver ) );

            if (maxNALLevel >= 8) {

                for (OpReaction o : defaultOperators)
                    on(o);
                /*for (OpReaction o : exampleOperators)
                    on(o);*/

                //n.on(Anticipate.class);      // expect an event

                if (internalExperience == Minimal) {
                    new InternalExperience(this);
                    new Abbreviation(this);
                } else if (internalExperience == Full) {
                    on(FullInternalExperience.class);
                    on(Counting.class);
                }
            }
        }
        //n.on(new RuntimeNARSettings());
{'fraction_non_alphanumeric': 0.10036021612967781, 'fraction_numerical': 0.005503301981188713, 'mean_word_length': 1.9163991829588563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '405955', 'n_tokens_mistral': 5648, 'n_tokens_neox': 5379, 'n_words': 1448}