예제 #1
0
        private void AssociateWordsWithVisuals(Thing attnAudibleTarget)
        {
            if (attnAudibleTarget != null)
            {
                //IList<Thing> recentlyFiredWords = uks.Labeled("Word").DescendentsWhichFired;
                List <Thing> recentlyFiredWords = new List <Thing>();
                recentlyFiredWords.Add(attnAudibleTarget);
                IList <Thing> recentlyFiredRelationships = uks.Labeled("Relationship").DescendentsWhichFired;
                IList <Thing> recentlyFiredVisuals       = uks.Labeled("Visual").DescendentsWhichFired;


                //set the hits
                foreach (Thing word in recentlyFiredWords)
                {
                    foreach (Thing relationshipType in recentlyFiredRelationships)
                    {
                        word.AdjustReference(relationshipType);
                    }
                    foreach (Thing visual in recentlyFiredVisuals)
                    {
                        if (!visual.HasAncestor(uks.GetOrAddThing("MentalModel", "Visual")))
                        {
                            word.AdjustReference(visual);
                        }
                    }
                }

                //set the misses for relationships
                foreach (Thing relationshipType in recentlyFiredRelationships)
                {
                    foreach (Link l in relationshipType.ReferencedBy)
                    {
                        Thing word = l.T;
                        if (word.HasAncestor(uks.Labeled("Word")))
                        {
                            if (!recentlyFiredWords.Contains(word))
                            {
                                word.AdjustReference(relationshipType, -1);
                            }
                        }
                    }
                }

                //set the misses for properties
                foreach (Thing visual in recentlyFiredVisuals)
                {
                    foreach (Link l in visual.ReferencedBy)
                    {
                        Thing word = l.T;
                        if (word.HasAncestor(uks.Labeled("Word")))
                        {
                            if (!recentlyFiredWords.Contains(word))
                            {
                                word.AdjustReference(visual, -1);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        //if a reward/punishment has been given, save the inputs and action
        private void LearnActions()
        {
            if (lastPhraseHeard == null || lastActionPerformed == null)
            {
                return;
            }
            List <Thing> outcomes = GetChildren(Labeled("Outcome"));

            foreach (Thing outcome in outcomes)
            {
                if (Fired(outcome, immediateMemory))
                {
                    float positive = (outcome.Label == "Positive") ? 1 : -1;
                    //do we already know this?
                    List <Thing> Events = GetChildren(Labeled("Event"));
                    foreach (Thing learned in Events)
                    {
                        //TODO we now have other types of Events...need to detect
                        if (learned.References.Count > 0 && learned.References[0].T == lastPhraseHeard)  //TODO remove hard-coding of phrase as first reference
                        {
                            learned.AdjustReference(lastActionPerformed, positive);
                            //TODO do some use-count here?
                            lastPhraseHeard     = null;
                            lastActionPerformed = null;
                            break;
                        }
                    }

                    //store the new Event memory
                    //TODO add a time limit so really old inputs aren't stored?
                    if (lastPhraseHeard != null && lastActionPerformed != null)
                    {
                        Thing newEvent = AddThing("si" + EventCount++, new Thing[] { Labeled("Event") }, null, new Thing[] { lastPhraseHeard });
                        if (newEvent != null)
                        {
                            newEvent.AdjustReference(lastActionPerformed, positive);
                        }
                    }
                    Fire(lastActionPerformed, false);
                    lastPhraseHeard     = null;
                    lastActionPerformed = null;
                }
            }
        }