예제 #1
0
        }                                    // disable ctor

        public static void selectConceptForInference(Memory mem, CompoundAndTermContext compoundAndTermContext)
        {
            ClassicalConcept currentConcept = mem.workingCyclish.concepts.takeNext();

            if (currentConcept == null)
            {
                return;
            }

            if (currentConcept.taskLinks.size == 0)   // remove concepts without tasklinks and without termlinks
            {
                mem.workingCyclish.concepts.take(currentConcept.term);
                mem.conceptWasRemoved(currentConcept);
                return;
            }

            if (currentConcept.termLinks.size == 0)    // remove concepts without tasklinks and without termlinks
            {
                mem.workingCyclish.concepts.take(currentConcept.term);
                mem.conceptWasRemoved(currentConcept);
                return;
            }

            DerivationContext ctx = new DerivationContext(mem, compoundAndTermContext);

            ctx.currentConcept = currentConcept;
            fireConcept(ctx, 1);
        }
예제 #2
0
        // debugging
        // ===

        static private void debugTermsToConsole(CompoundAndTermContext compoundAndTermContext, TemporaryDerivedTerm[] terms)
        {
            string message = "";

            foreach (var iterationTerm in terms)
            {
                message += String.Format("derived term = ({0})\n", dumpToString(iterationTerm, compoundAndTermContext));
            }

            Console.WriteLine(message);
        }
예제 #3
0
        // returns the refered payload as an referer
        public TermOrCompoundTermOrVariableReferer returnReferer(CompoundAndTermContext compoundAndTermContext)
        {
            Trace.Assert(payloadType != EnumPayloadType.NONE, "Must not be None because it must have a value to be referenced!"); // if it is NONE we can't return the referer

            if (payloadType == EnumPayloadType.REFERER)
            {
                return(privateReferer);
            }
            else
            {
                Debug.Assert(payloadType == EnumPayloadType.COMPOUNDINDEX);
                return(compoundAndTermContext.accessCompoundByIndex(compoundIndex).thisTermReferer);
            }
        }
예제 #4
0
파일: Class1.cs 프로젝트: chargen/AGI-X0
        static void testNars()
        {
            CompoundAndTermContext compoundAndTermContext = new CompoundAndTermContext();

            RuleDispatcher.compoundAndTermContext = compoundAndTermContext; // for debugging

            PrototypingInput prototypingInput = new PrototypingInput(compoundAndTermContext);

            Nar nar = Nar.make(compoundAndTermContext, new MetaNix.nars.config.RuntimeParameters());

            CompoundIndex compoundIndex1 = prototypingInput.makeInheritance("a", "b");

            ClassicalSentence.MakeByTermPunctuationTruthStampNormalizeParameters task1SentenceParameters = new ClassicalSentence.MakeByTermPunctuationTruthStampNormalizeParameters();
            task1SentenceParameters.term       = compoundAndTermContext.accessCompoundByIndex(compoundIndex1).thisTermReferer;
            task1SentenceParameters.truth      = TruthValue.make(1.0f, 0.5f);
            task1SentenceParameters.stamp      = Stamp.makeWithPresentTense(nar.memory);
            task1SentenceParameters.punctation = ClassicalSentence.EnumPunctation.JUDGMENT;
            ClassicalSentence task1Sentence = ClassicalSentence.makeByTermPunctuationTruthStampNormalize(task1SentenceParameters);

            ClassicalTask.MakeParameters task1MakeParameters = new ClassicalTask.MakeParameters();
            task1MakeParameters.sentence = task1Sentence;
            task1MakeParameters.budget   = new ClassicalBudgetValue(0.5f, 0.5f, 0.5f);

            nar.inputTask(ClassicalTask.make(task1MakeParameters));



            CompoundIndex compoundIndex2 = prototypingInput.makeInheritance("b", "c");

            ClassicalSentence.MakeByTermPunctuationTruthStampNormalizeParameters task2SentenceParameters = new ClassicalSentence.MakeByTermPunctuationTruthStampNormalizeParameters();
            task2SentenceParameters.term       = compoundAndTermContext.accessCompoundByIndex(compoundIndex2).thisTermReferer;
            task2SentenceParameters.truth      = TruthValue.make(1.0f, 0.5f);
            task2SentenceParameters.stamp      = Stamp.makeWithPresentTense(nar.memory);
            task2SentenceParameters.punctation = ClassicalSentence.EnumPunctation.JUDGMENT;
            ClassicalSentence task2Sentence = ClassicalSentence.makeByTermPunctuationTruthStampNormalize(task2SentenceParameters);

            ClassicalTask.MakeParameters task2MakeParameters = new ClassicalTask.MakeParameters();
            task2MakeParameters.sentence = task2Sentence;
            task2MakeParameters.budget   = new ClassicalBudgetValue(0.5f, 0.5f, 0.5f);

            nar.inputTask(ClassicalTask.make(task2MakeParameters));

            for (;;)
            {
                nar.cycle();
            }

            int here = 5;
        }
예제 #5
0
파일: Memory.cs 프로젝트: chargen/AGI-X0
        public Memory(
            CompoundAndTermContext compoundAndTermContext,
            RuntimeParameters runtimeParameters,
            IAttentionMechanism <ClassicalTask> attention
            )
        {
            this.compoundAndTermContext = compoundAndTermContext;
            this.param     = runtimeParameters;
            this.attention = attention;

            conceptProcessing = new ClassicalConceptProcessing(this, compoundAndTermContext);

            workingCyclish          = new WorkingCyclish();
            workingCyclish.concepts = new ArrayBag <ClassicalConcept, TermOrCompoundTermOrVariableReferer>();
            workingCyclish.concepts.setMaxSize(Parameters.CONCEPT_BAG_SIZE);
        }
예제 #6
0
 public string debugToStringRecursivly(CompoundAndTermContext compoundAndTermContext)
 {
     if (isLeaf)
     {
         return(String.Format("<LEAF={0}>", compoundAndTermContext.getDebugStringByTermReferer(termReferer)));
     }
     else if (isIndependentVariable)
     {
         return(String.Format("<$VAR:{0}>", independentVariableId));
     }
     else if (isDependentVariable)
     {
         return(String.Format("<#VAR:{0}>", dependentVariableId));
     }
     else
     {
         // TODO< implement for nonbinary >
         return(String.Format("<COMPOUND={0} {1} {2}>", leftChildren.debugToStringRecursivly(compoundAndTermContext), flagsOfCopula.convToHumanString(), rightChildren.debugToStringRecursivly(compoundAndTermContext)));
     }
 }
예제 #7
0
        public ClassicalConcept(CompoundAndTermContext compoundAndTermContext, TermOrCompoundTermOrVariableReferer term, BagBuilder bagBuilder, ClassicalBudgetValue budget, Memory memory) : base(budget)
        {
            this.memory = memory;
            this.term   = term;

            tasks = bagBuilder.createForConcept_tasksBag();

            taskLinks = bagBuilder.createForConcept_taskLinksBag();
            termLinks = bagBuilder.createForConcept_termLinksBag();

            { // calculate term links
                bool isCompoundTerm = !term.isAtomic && !term.isVariable;
                if (isCompoundTerm)
                {
                    // TODO< decide if it is COMPOUND_STATEMENT or COMPOUND >
                    // https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/language/Terms.java#L470;
                    ClassicalTermLink.EnumType type = ClassicalTermLink.EnumType.COMPOUND;

                    this.termLinkTemplates = TermHelper.prepareComponentLinks(compoundAndTermContext, term, type);
                }
            }
        }
예제 #8
0
        public uint calcComplexityRecursive(CompoundAndTermContext compoundAndTermContext)
        {
            if (isLeaf)
            {
                return(compoundAndTermContext.getTermComplexityOfAndByTermReferer(termReferer));
            }
            else if (isIndependentVariable)
            {
                return(Compound.COMPLEXITYINDEPENDENTVARIABLE);
            }
            else if (isDependentVariable)
            {
                return(Compound.COMPLEXITYDEPENDENTVARIABLE);
            }
            else
            {
                uint complexity = flagsOfCopula.getComplexityOfFlagsOfCopula();

                // TODO< implement for nonbinary >
                complexity += leftChildren.calcComplexityRecursive(compoundAndTermContext);
                complexity += rightChildren.calcComplexityRecursive(compoundAndTermContext);
                return(complexity);
            }
        }
예제 #9
0
        public static IList <TemporaryDerivedTerm> derive(CompoundAndTermContext compoundAndTermContext, Compound premiseLeft, Compound premiseRight, bool isQuestion)
        {
            IList <TemporaryDerivedTerm> resultTerms = new List <TemporaryDerivedTerm>();

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)) && (premiseLeft.right(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.STRUCTINT));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)) && (premiseRight.right(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.STRUCTINT));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)) && (premiseLeft.right(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.STRUCTABD));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)) && (premiseRight.right(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.STRUCTABD));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)) && (premiseLeft.right(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.CONVERSION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)) && (premiseRight.right(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && isQuestion
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.CONVERSION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.right(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.right(compoundAndTermContext)), RuleTable.EnumTruthFunction.DEDUCTION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.right(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.right(compoundAndTermContext)), RuleTable.EnumTruthFunction.DEDUCTION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.right(compoundAndTermContext) != premiseRight.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.ABDUCTION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.right(compoundAndTermContext) != premiseLeft.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.ABDUCTION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.right(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.INDUCTION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.right(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.INDUCTION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.right(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.right(compoundAndTermContext) != premiseLeft.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.EXEMPLIFICATION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.right(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.right(compoundAndTermContext) != premiseRight.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.EXEMPLIFICATION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)) && (premiseLeft.right(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >

                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.INTERSECTION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)) && (premiseRight.right(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >

                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.INTERSECTION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)) && (premiseLeft.right(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >

                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.left(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.REDUCECONJUNCTION));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)) && (premiseRight.right(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >

                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.left(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.REDUCECONJUNCTION));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.right(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseLeft.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.COMPARISON));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.right(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseRight.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.COMPARISON));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.right(compoundAndTermContext) != premiseLeft.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseRight.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.COMPARISON));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.left(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.right(compoundAndTermContext) != premiseRight.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseLeft.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.COMPARISON));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.ANALOGY));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.ANALOGY));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.right(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseLeft.left(compoundAndTermContext), premiseLeft.right(compoundAndTermContext)), RuleTable.EnumTruthFunction.ANALOGY));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, false, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.right(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.left(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, false, true, false), premiseRight.left(compoundAndTermContext), premiseRight.right(compoundAndTermContext)), RuleTable.EnumTruthFunction.ANALOGY));
            }

            if (
                // AUTOGEN< check flags for match >
                ((premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseLeft.left(compoundAndTermContext) == premiseRight.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseRight.left(compoundAndTermContext) != premiseLeft.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseLeft.right(compoundAndTermContext), premiseRight.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.RESEMBLANCE));
            }

            else if (
                // AUTOGEN< check flags for match >
                ((premiseRight.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)) && (premiseLeft.flagsOfCopula == new FlagsOfCopula(true, false, true, true, false)))

                // AUTOGEN< check for source pattern >
                && (true && (premiseRight.left(compoundAndTermContext) == premiseLeft.right(compoundAndTermContext)))

                // AUTOGEN< check eventually for the preconditions >
                && (premiseLeft.left(compoundAndTermContext) != premiseRight.right(compoundAndTermContext))
                )
            {
                resultTerms.Add(TemporaryDerivedTerm.genTerm(DeriverUtilities.genBinary(new FlagsOfCopula(true, false, true, true, false), premiseRight.right(compoundAndTermContext), premiseLeft.left(compoundAndTermContext)), RuleTable.EnumTruthFunction.RESEMBLANCE));
            }
            ;
            return(resultTerms);
        }
예제 #10
0
        }                               // disable standard ctor

        public CompoundHashtable(CompoundAndTermContext compoundAndTermContext, bool withCompoundId)
        {
            this.compoundAndTermContext = compoundAndTermContext;
            this.withCompoundId         = withCompoundId;
        }
예제 #11
0
        }                          // disable standard ctor

        public DerivationContext(Memory memory, CompoundAndTermContext compoundAndTermContext)
        {
            this.memory = memory;
            this.compoundAndTermContext = compoundAndTermContext;
        }
예제 #12
0
        static IList <TemporaryDerivedCompoundWithDecorationAndTruth> insertDerivedCompoundTermsAndReturnDerivedCompoundTermsWithDecoration(CompoundAndTermContext compoundAndTermContext, IList <TemporaryDerivedTerm> derivedCompoundTerms)
        {
            List <TemporaryDerivedCompoundWithDecorationAndTruth> derivedCompoundTermsWithDecorationAndTruth = new List <TemporaryDerivedCompoundWithDecorationAndTruth>();

            foreach (TemporaryDerivedTerm iterationDerivedCompoundTerm in derivedCompoundTerms)
            {
                var newDerivedCompoundTermWithDecorationAndTruth = new TemporaryDerivedCompoundWithDecorationAndTruth();
                newDerivedCompoundTermWithDecorationAndTruth.derivedCompoundWithDecoration = TemporaryDerivedCompoundDecoration.makeRecursive(iterationDerivedCompoundTerm.derivedCompound);
                newDerivedCompoundTermWithDecorationAndTruth.truthfunction = iterationDerivedCompoundTerm.truthfunction;
                derivedCompoundTermsWithDecorationAndTruth.Add(newDerivedCompoundTermWithDecorationAndTruth);
            }

            foreach (var iterationDerivedCompoundTermWithDecorationAndTruth in derivedCompoundTermsWithDecorationAndTruth)
            {
                insertDerivedCompoundTerm(compoundAndTermContext, iterationDerivedCompoundTermWithDecorationAndTruth.derivedCompoundWithDecoration);
            }

            return(derivedCompoundTermsWithDecorationAndTruth);
        }
예제 #13
0
 private static string dumpToString(TemporaryDerivedTerm derivedTerm, CompoundAndTermContext compoundAndTermContext)
 {
     return(String.Format("{0} truthfn={1}", derivedTerm.derivedCompound.debugToStringRecursivly(compoundAndTermContext), derivedTerm.truthfunction.ToString()));
 }
예제 #14
0
        // - calls deriver
        // - checks if the termcomplexity is too large, if so its thrown away
        // - for each remaining derivation result insert and translate to compounds and termTuples
        public static IEnumerable <TemporaryDerivedTerm> deriverCaller(
            CompoundAndTermContext compoundAndTermContext,
            Compound premiseLeft,
            Compound premiseRight,
            out IList <TemporaryDerivedCompoundWithDecorationAndTruth> derivedCompoundTermsWithDecorationAndTruth,
            bool insert = true
            )
        {
            /* still in here because it shows how to recalculate complexity recursivly
             * uint recalcTermComplexityRecursive(TemporaryDerivedCompound* derivedCompound) {
             *  uint getTermComplexityOfLeaf() {
             *      assert( derivedCompound.isLeaf );
             *      return reasonerInstance.getTermComplexityOfAndByTermReferer(derivedCompound.termReferer);
             *  }
             *
             *  if( derivedCompound.isLeaf ) {
             *      return derivedCompound.termComplexity = getTermComplexityOfLeaf();
             *  }
             *  else if( derivedCompound )
             *  else {
             *      derivedCompound.termComplexity = getComplexityOfFlagsOfCopula(derivedCompound.flagsOfCopula);
             *
             *      // TODO< implement for nonbinary >
             *      assert(derivedCompound.leftChildren !is null);
             *      assert(derivedCompound.rightChildren !is null);
             *      derivedCompound.termComplexity += recalcTermComplexityRecursive(derivedCompound.leftChildren);
             *      derivedCompound.termComplexity += recalcTermComplexityRecursive(derivedCompound.rightChildren);
             *
             *      return derivedCompound.termComplexity;
             *  }
             * }
             */

            bool isQuestion = false; // HACK, TODO< pull this from the task >

            IList <TemporaryDerivedTerm> temporaryDerivedTerms = Autogenerated.derive(compoundAndTermContext, premiseLeft, premiseRight, isQuestion);

            foreach (TemporaryDerivedTerm iterationTemporaryDerivedTerms in temporaryDerivedTerms)
            {
                // TODO< optimize this by storing the termcomplexity into the TemporaryDerivedTerm in the method ! >
                iterationTemporaryDerivedTerms.derivedCompound.termComplexity = iterationTemporaryDerivedTerms.derivedCompound.calcComplexityRecursive(compoundAndTermContext);

                // recalcTermComplexityRecursive(iterationTemporaryDerivedTerms.derivedCompound);
            }

            // filter by maximal term complexity
            var filteredTerms = temporaryDerivedTerms.Where(a => a.derivedCompound.termComplexity <= Parameters.MAXIMAL_TERM_COMPLEXITY);

            // debug
            // for now we just dump the TemporaryDerivedCompounds and the compounds they reference
            debugTermsToConsole(compoundAndTermContext, filteredTerms.ToArray());

            derivedCompoundTermsWithDecorationAndTruth = null;
            if (insert)
            {
                // insert and translate to compounds and termTuples
                derivedCompoundTermsWithDecorationAndTruth = insertDerivedCompoundTermsAndReturnDerivedCompoundTermsWithDecoration(compoundAndTermContext, filteredTerms.ToArray());
            }

            return(filteredTerms);
        }
예제 #15
0
        static void insertDerivedCompoundTerm(CompoundAndTermContext compoundAndTermContext, TemporaryDerivedCompoundWithDecoration derivedCompoundTerm)
        {
            // TODO< good place to hook in (compound)term compression >


            // the index of the compound in the compound table is returned with the decoration of the argument "derivedCompoundTerm"
            void innerFnInsertIfItDoesntExistRecursivly(TemporaryDerivedCompoundWithDecoration derivedCompoundTermInner)
            {
                // recurse to children
                if (derivedCompoundTermInner.type == TemporaryDerivedCompoundWithDecoration.EnumType.COMPOUND)
                {
                    innerFnInsertIfItDoesntExistRecursivly(derivedCompoundTermInner.leftChildren);
                    innerFnInsertIfItDoesntExistRecursivly(derivedCompoundTermInner.rightChildren);
                }

                // create if not exist

                if (derivedCompoundTermInner.type == TemporaryDerivedCompoundWithDecoration.EnumType.COMPOUND)   // is a Temporary compound(term)
                {
                    bool innerFnEarlyTestExistsCompound()
                    {
                        var childrenCompoundsWithDecorations = new TemporaryDerivedCompoundWithDecoration[] { derivedCompoundTermInner.leftChildren, derivedCompoundTermInner.rightChildren };

                        return(compoundAndTermContext.existTermTuple(new List <TermOrCompoundTermOrVariableReferer>(childrenCompoundsWithDecorations.Select(n => n.decoration.returnReferer(compoundAndTermContext)))));
                    }

                    // returns compoundIndex
                    CompoundIndex innerFnCreateCompoundAndAddToReasoner(TermTupleIndex termTupleIndex)
                    {
                        // create compound
                        ulong compoundIndex2 = compoundAndTermContext.getCompoundCreateIndex(); // get the index where the compound will be created

                        Compound.MakeParameters compoundMakeParameters2 = new Compound.MakeParameters();
                        compoundMakeParameters2.termComplexity  = derivedCompoundTermInner.termComplexity;
                        compoundMakeParameters2.flagsOfCopula   = derivedCompoundTermInner.flagsOfCopula;
                        compoundMakeParameters2.thisTermReferer = TermOrCompoundTermOrVariableReferer.makeNonatomic(/* 32 bit conversion*/ (int)compoundIndex2); // create new referer based on the compound index
                        compoundMakeParameters2.termTupleIndex  = termTupleIndex;

                        Compound createdCompound = compoundAndTermContext.createCompound(compoundMakeParameters2);

                        // insert compound
                        compoundAndTermContext.addCompound(createdCompound);

                        return(CompoundIndex.make(/*quick and dirty conversation*/ (uint)compoundIndex2));
                    }

                    // build the term, calculate the hash, try to lookup the compound based on the hash
                    // if it exists we return the compoundIndex of the found compound
                    // if it doesn't exist we create a new Compound and return it

                    if (innerFnEarlyTestExistsCompound())               // if the term tuple exists then the compound could exist

                    // build compound and calc hash and try to look it up and compare it to the built compound

                    {
                        var            childrenCompoundsWithDecorations = new TemporaryDerivedCompoundWithDecoration[] { derivedCompoundTermInner.leftChildren, derivedCompoundTermInner.rightChildren };
                        TermTupleIndex termTupleIndex = compoundAndTermContext.getTermTupleIndexByReferers(childrenCompoundsWithDecorations.Select(n => n.decoration.returnReferer(compoundAndTermContext)).ToArray <TermOrCompoundTermOrVariableReferer>());

                        //   * build compound
                        Compound.MakeParameters compoundMakeParameters = new Compound.MakeParameters();
                        compoundMakeParameters.termComplexity = derivedCompoundTermInner.termComplexity;
                        compoundMakeParameters.flagsOfCopula  = derivedCompoundTermInner.flagsOfCopula;

                        //compoundMakeParameters.compoundId;      we don't need to initialize it because the hash computation for this lookup doesn't use it
                        //                                        the hash computation doesn't use it because we don't know it

                        //compoundMakeParameters.thisTermReferer  we don't need to intialize it because it's not used for hash computation
                        compoundMakeParameters.termTupleIndex = termTupleIndex;
                        Compound createdCompoundForHash = Compound.make(compoundMakeParameters);
                        //   * calc hash
                        createdCompoundForHash.updateHash(/*with compoundId*/ false);

                        //    * lookup hash and compare if possible
                        //      if the compound doesn't exist we create and add it
                        CompoundIndex compoundIndex2;
                        if (compoundAndTermContext.existsCompoundWithoutCompoundId(createdCompoundForHash, out compoundIndex2))
                        {
                            // set as the result the compound
                            derivedCompoundTermInner.decoration.compoundIndex = compoundIndex2;
                        }
                        else
                        {
                            // create and add compound
                            compoundIndex2 = innerFnCreateCompoundAndAddToReasoner(termTupleIndex);

                            // set as the result the compound
                            derivedCompoundTermInner.decoration.compoundIndex = compoundIndex2;
                        }
                    }
                    else               // if the term tuple doesn't exist then the compound can't exist so we have to create and return it

                    // create termTuple
                    {
                        var            childrenCompoundsWithDecorations = new TemporaryDerivedCompoundWithDecoration[] { derivedCompoundTermInner.leftChildren, derivedCompoundTermInner.rightChildren };
                        TermTupleIndex termTupleIndex = compoundAndTermContext.addTermTupleByReferers(childrenCompoundsWithDecorations.Select(n => n.decoration.returnReferer(compoundAndTermContext)).ToArray());
                        // create and add compound
                        CompoundIndex compoundIndex = innerFnCreateCompoundAndAddToReasoner(termTupleIndex);

                        // set as the result the compound
                        derivedCompoundTermInner.decoration.compoundIndex = compoundIndex;
                    }
                }
                else if (
                    derivedCompoundTermInner.type == TemporaryDerivedCompoundType <TemporaryDerivedCompoundDecoration> .EnumType.LEAF ||
                    derivedCompoundTermInner.type == TemporaryDerivedCompoundType <TemporaryDerivedCompoundDecoration> .EnumType.INDEPENDENTVARIABLE ||
                    derivedCompoundTermInner.type == TemporaryDerivedCompoundType <TemporaryDerivedCompoundDecoration> .EnumType.DEPENDENTVARIABLE
                    )
                {
                    if (derivedCompoundTermInner.type == TemporaryDerivedCompoundType <TemporaryDerivedCompoundDecoration> .EnumType.LEAF)
                    {
                        TermOrCompoundTermOrVariableReferer termReferer = derivedCompoundTermInner.termReferer;

                        derivedCompoundTermInner.decoration.referer = termReferer;
                    }

                    /* commented because we have to figure out how to translate the variable id's
                     *
                     *          else if( derivedCompoundTermInner.type == TemporaryDerivedCompoundType<TemporaryDerivedCompoundDecoration>.EnumType.INDEPENDENTVARIABLE ) {
                     *                  compoundId = derivedCompoundTermInner.independentVariableId; // ASSUMPTION< compoundId is the id of the variable >
                     *          }
                     *          else if( derivedCompoundTermInner.type == TemporaryDerivedCompoundType<TemporaryDerivedCompoundDecoration>.EnumType.DEPENDENTVARIABLE ) {
                     *                  compoundId = derivedCompoundTermInner.dependentVariableId; // ASSUMPTION< compoundId is the id of the variable >
                     *          }
                     */
                    else
                    {
                        throw new Exception("Internal error");
                    }
                }
                else
                {
                    throw new Exception("Internal error");
                }
            }

            // for now we just check for the existence and insert it recursivly
            innerFnInsertIfItDoesntExistRecursivly(derivedCompoundTerm);
        }
예제 #16
0
        }                                       // disable standard ctor

        public ClassicalConceptProcessing(Memory memory, CompoundAndTermContext compoundAndTermContext)
        {
            this.memory = memory;
            this.compoundAndTermContext = compoundAndTermContext;
        }
예제 #17
0
        // https://github.com/opennars/opennars/blob/master/nars_core/nars/inference/TemporalRules.java#L502

        /**
         * Evaluate the quality of the judgment as a solution to a problem
         *
         * \param problem A goal or question
         * \param solution The solution to be evaluated
         * \return The quality of the judgment as the solution
         */
        public static float solutionQuality(EnumRateByConfidence rateByConfidence, ClassicalTask problemTask, ClassicalSentence solution, Memory memory, CompoundAndTermContext compoundAndTermContext)
        {
            ClassicalSentence problem = problemTask.sentence;

            /* TODO< implement TEMPORAL
             * if (!matchingOrder(problem.temporalOrder, solution.temporalOrder)) {
             *  return 0.0F;
             * }
             */

            TruthValue truth = solution.truth;

            if (problem.stamp.occurrenceTime != solution.stamp.occurrenceTime)
            {
                truth = solution.projectionTruth(problem.stamp.occurrenceTime, memory.time);
            }

            //when the solutions are comparable, we have to use confidence!! else truth expectation.
            //this way negative evidence can update the solution instead of getting ignored due to lower truth expectation.
            //so the previous handling to let whether the problem has query vars decide was wrong.
            if (rateByConfidence == EnumRateByConfidence.NO)
            {
                return((float)(truth.expectation / Math.Sqrt(Math.Sqrt(Math.Sqrt(compoundAndTermContext.getTermComplexityOfAndByTermReferer(solution.term) * Parameters.COMPLEXITY_UNIT)))));
            }
            else
            {
                return(truth.confidence);
            }
        }