Exemple #1
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
            {
                SpeakPhrase(UKS);
                HandlePhonemes(UKS);

                if (GetNeuronValue("Word") == 1)
                {
                    PruneWords(UKS);
                }
                if (GetNeuronValue("Phrase") == 1)
                {
                    PrunePhrases(UKS);
                }
                if (GetNeuronValue("Stext") == 1)
                {
                    currentText = UKS.AddThing("txt" + textCount++, UKS.Labeled("Text"));
                }
                if (GetNeuronValue("Etext") == 1)
                {
                    currentText = null;
                }
            }
        }
Exemple #2
0
        //did the neuron associated with a thing fire?
        //firing at least minPastCycles but not more than maxPastCycles ago
        public bool Fired(Thing t, long maxPastCycles = 1, bool firedInput = true, long minPastCycles = 0)
        {
            int        i        = UKS.IndexOf(t);
            ModuleView naModule = na;

            if (!firedInput)
            {
                naModule = GetOutputModule();
                if (naModule == null)
                {
                    return(false);
                }
            }
            Neuron n = naModule.GetNeuronAt(i);

            if (n == null)
            {
                return(false);
            }
            long timeSinceLastFire = MainWindow.theNeuronArray.Generation - n.LastFired;
            bool retVal            = timeSinceLastFire <= maxPastCycles;

            if (retVal)
            {
                retVal = timeSinceLastFire >= minPastCycles;
            }
            return(retVal);
        }
Exemple #3
0
        public override void DeleteThing(Thing t)
        {
            int i = UKS.IndexOf(t);

            base.DeleteThing(t);
            //because we removed a node, any external synapses to related neurons need to be adjusted to point to the right place
            //on any neurons which might have shifted.
            if (i > -1)
            {
                for (int j = i + 1; j < na.NeuronCount; j++)
                {
                    Neuron targetNeuron = na.GetNeuronAt(j - 1);
                    Neuron sourceNeuron = na.GetNeuronAt(j);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                }
                //repeat this process for the output array
                ModuleView naModule = theNeuronArray.FindAreaByLabel("KBOut");
                if (naModule != null)
                {
                    for (int j = i + 1; j < naModule.NeuronCount; j++)
                    {
                        Neuron targetNeuron = naModule.GetNeuronAt(j - 1);
                        Neuron sourceNeuron = naModule.GetNeuronAt(j);
                        MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                    }
                }
            }
            UpdateNeuronLabels();
        }
Exemple #4
0
        //TODO add more properties to Stroke
        public Thing AddStrokeToUKS(PointPlus P1, PointPlus P2)
        {
            ModuleUKS uks = (ModuleUKS)FindModuleByType(typeof(ModuleUKS));

            if (uks is ModuleUKS UKS)
            {
                if (uks.Labeled("AbsStroke") == null)
                {
                    uks.AddThing("AbsStroke", "Visual");
                }
                Thing t1 = uks.Valued(P1);
                if (t1 == null)
                {
                    t1 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P1);
                }
                Thing t2 = uks.Valued(P2);
                if (t2 == null)
                {
                    t2 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P2);
                }
                Thing newThing = UKS.AddThing("s" + strokeCount++, new Thing[] { UKS.Labeled("AbsStroke") }, null, new Thing[] { t1, t2 });
                return(newThing);
            }
            return(null);
        }
Exemple #5
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>

        //execute the debugging commands if the associated neuron fired
        private void ShowReferences()
        {
            for (int i = firstThing; i < na.NeuronCount && i < UKS.Count; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (NeuronFired("Parent"))
                {
                    if (n.Fired())
                    {
                        foreach (Thing t in UKS[i].Parents)
                        {
                            int j = UKS.IndexOf(t);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
                if (NeuronFired("Ref"))
                {
                    if (n.Fired())
                    {
                        foreach (Link l in UKS[i].References)
                        {
                            int j = UKS.IndexOf(l.T);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
                if (NeuronFired("Max"))
                {
                    if (n.Fired())
                    {
                        Link Max = new Link {
                            weight = -1
                        };
                        foreach (Link l in UKS[i].References)
                        {
                            if (l.Value() > Max.weight)
                            {
                                Max = l;
                            }
                        }
                        if (Max.weight > -1)
                        {
                            int j = UKS.IndexOf(Max.T);
                            if (j >= 0)
                            {
                                SetNeuronValue("KBOut", j, 1);
                            }
                        }
                    }
                }
            }
        }
Exemple #6
0
        //return neuron associated with KB thing
        public Neuron GetNeuron(Thing t, bool input = true)
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return(null);
            }
            return(GetNeuron(i, input));
        }
Exemple #7
0
 public void SpeakThing(string label)
 {
     if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
     {
         if (UKS.Labeled(label) is Thing t)
         {
             SpeakThing(UKS, t);
         }
     }
 }
Exemple #8
0
        //fire the neuron associated with a KB thing
        public void Fire(Thing t, bool fireInput = true) //false fires the neuron in the output array
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return;
            }
            Neuron n = GetNeuron(i, fireInput);

            n.SetValue(1);
            t.useCount++;
        }
        public void GetSegmentsFromUKS()
        {
            ModuleUKSN nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));

            if (nmUKS is ModuleUKS UKS)
            {
                UKSSegments = UKS.Labeled("Segment").Children;
                UKSPoints   = new List <Thing>();
                if (UKS.Labeled("ModelThing") != null)
                {
                    UKSPoints = UKS.Labeled("ModelThing").Children;
                }
            }
        }
Exemple #10
0
        //did the neuron associated with a thing fire?
        //firing at least minPastCycles but not more than maxPastCycles ago
        public bool Fired(Thing t, long maxPastCycles = 1, bool firedInput = true, long minPastCycles = 0)
        {
            int    i = UKS.IndexOf(t);
            Neuron n = GetNeuron(i, firedInput);

            if (n == null)
            {
                return(false);
            }
            long timeSinceLastFire = MainWindow.theNeuronArray.Generation - n.LastFired;
            bool retVal            = timeSinceLastFire <= maxPastCycles;

            if (retVal)
            {
                retVal = timeSinceLastFire >= minPastCycles;
            }
            return(retVal);
        }
Exemple #11
0
        public override void Initialize()
        {
            wordCount   = 0;
            phraseCount = 0;
            textCount   = 0;
            currentText = null;
            AddLabel("Word");
            AddLabel("Phrase");
            AddLabel("Stext");
            AddLabel("Etext");

            shortTermMemoryList.Clear();
            if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
            {
                UKS.AddThing("Word", "Audible");
                UKS.AddThing("Phrase", "Audible");
                UKS.AddThing("Text", "Audible");
            }
        }
Exemple #12
0
        //fire the neuron associated with a KB thing
        public void Fire(Thing t, bool fireInput = true) //false fires the neuron in the output array
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return;
            }
            if (fireInput)
            {
                SetNeuronValue(null, i, 1);
            }
            else
            {
                SetNeuronValue("KBOut", i, 1);
            }

            t.useCount++;
        }
Exemple #13
0
        public override void DeleteThing(Thing t)
        {
            int i = UKS.IndexOf(t);

            base.DeleteThing(t);
            //because we removed a node, any external synapses to related neurons need to be adjusted to point to the right place
            //on any neurons which might have shifted.
            if (i > -1)
            {
                for (int j = i + 1; j < UKS.Count; j++)
                {
                    Neuron sourceNeuron = GetNeuron(j, false);
                    Neuron targetNeuron = PrevNeuron(sourceNeuron);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                    sourceNeuron = GetNeuron(j, true);
                    targetNeuron = PrevNeuron(sourceNeuron);
                    MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron);
                }
            }
            UpdateNeuronLabels();
        }
Exemple #14
0
        //return neuron associated with KB thing
        public Neuron GetNeuron(Thing t, bool input = true)
        {
            int i = UKS.IndexOf(t);

            if (i == -1)
            {
                return(null);
            }
            if (input)
            {
                return(na.GetNeuronAt(i));
            }
            else
            {
                ModuleView na1 = theNeuronArray.FindAreaByLabel("KBOut");
                if (na1 == null)
                {
                    return(null);
                }
                return(na1.GetNeuronAt(i));
            }
        }
        public Thing AddSegmentToUKS(PointPlus P1, PointPlus P2, int theColor, PointPlus motion = null, bool addToModel = true)
        {
            ModuleUKS nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));

            if (nmUKS is ModuleUKS UKS)
            {
                Thing t1, t2;
                Thing t3 = null;
                t1 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P1);
                t2 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P2);
                if (addToModel)
                {
                    t1.AddParent(UKS.Labeled("ModelThing"));
                    t2.AddParent(UKS.Labeled("ModelThing"));
                }
                if (motion != null)
                {
                    t3 = UKS.AddThing("m" + mCount++, new Thing[] { UKS.Labeled("Motion") }, motion);
                }
                Thing color = UKS.Valued(theColor);
                if (color == null)
                {
                    color = UKS.AddThing("c" + cCount++, new Thing[] { UKS.Labeled("Color") }, theColor);
                }
                Thing newThing = null;
                if (motion != null)
                {
                    newThing = UKS.AddThing("s" + sCount++, new Thing[] { UKS.Labeled("Segment") }, null, new Thing[] { t1, t2, color, t3 });
                }
                else
                {
                    newThing = UKS.AddThing("s" + sCount++, new Thing[] { UKS.Labeled("Segment") }, null, new Thing[] { t1, t2, color });
                }
                return(newThing);
            }
            return(null);
        }
Exemple #16
0
        //this returns the most recent firing regardless of how long ago it was
        Thing MostRecentFired(Thing t)
        {
            if (t == null)
            {
                return(null);
            }
            Thing retVal  = null;
            long  firedAt = 0;

            foreach (Thing child in t.Children)
            {
                int    i = UKS.IndexOf(child);
                Neuron n = GetNeuron(i);
                if (n != null)
                {
                    if (n.LastFired > firedAt)
                    {
                        retVal  = child;
                        firedAt = n.LastFired;
                    }
                }
            }
            return(retVal);
        }
Exemple #17
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            if (GetNeuronValue("Cancel") == 1)
            {
                synth.SpeakAsyncCancelAll();
            }
            if (GetNeuronValue("Validate") == 1)
            {
                if (!validating)
                {
                    hitWords.Clear();
                    missWords.Clear();
                    missPhrase.Clear();
                    hit  = 0;
                    miss = 0;
                }
                validating = true;
            }
            else
            {
                if (validating)
                {
                    if (hit + miss == 0)
                    {
                        Debug.WriteLine("No Validation Data");
                    }
                    else
                    {
                        Debug.WriteLine("Validation: " + hit + " / " + miss + " = " + 100 * hit / (hit + miss));
                        Debug.WriteLine("Validation: " + hitWords.Count + " / " + missWords.Count + " = " + 100 * hitWords.Count / (hitWords.Count + missWords.Count));
                    }
                }
                validating = false;
            }

            bool paused = true;

            for (int i = 3; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (n.Fired())
                {
                    if (n.Label.Length == 1)
                    {
                        phraseToSpeak += n.Label;
                        paused         = false;
                    }
                    if (n.Synapses.Count == 0)
                    {
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n1.SetValue(1);
                                n2.AddSynapse(n.Id, 1);
                            }
                        }
                    }
                }
            }
            if (phonemesToFire != "")
            {
                char c     = phonemesToFire[0];
                bool fired = false;
                if (c != ' ')
                {
                    for (int i = 0; i < na.NeuronCount; i++)
                    {
                        Neuron n = na.GetNeuronAt(i);
                        if (n.Label == c.ToString())
                        {
                            n.SetValue(1);
                            fired = true;
                            break;
                        }
                    }
                    if (!fired)
                    {
                        Neuron n = AddLabel(c.ToString());
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n2.AddSynapse(n.Id, 1);
                                n.SetValue(1);
                            }
                        }
                    }
                }
                phonemesToFire = phonemesToFire.Substring(1);
            }

            if (paused && phraseToSpeak != "")
            {
                if (dlg != null)
                {
                    ((ModuleSpeakPhonemes2Dlg)dlg).SetLabel(phraseToSpeak);
                }

                if (na.GetNeuronAt("Enable").Fired())
                {
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    //synth.SpeakAsync(phraseToSpeak + ".");
                    //phraseToSpeak = "";

                    PromptBuilder pb1 = new PromptBuilder();
                    if (typedIn)
                    {
                        pb1.StartVoice("Microsoft David Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Medium));
                    }
                    else
                    {
                        pb1.StartVoice("Microsoft Zira Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Slow));
                    }

                    pb1.AppendTextWithPronunciation("not used", phraseToSpeak.Trim());
                    pb1.EndStyle();
                    pb1.EndVoice();
                    string x = pb1.ToXml();
                    Debug.WriteLine(debugString(phraseToSpeak));
                    //synth.Speak(pb1);
                    synth.SpeakAsync(pb1);
                }
                //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine
                phraseToSpeak = "";
                typedIn       = false;
            }
        }
Exemple #18
0
        //fill this method in with code which will execute once
        //when the module is added, when "initialize" is selected from the context menu,
        //or when the engine restart button is pressed
        public override void Initialize()
        {
            base.Initialize();
            foreach (Neuron n in na.Neurons())
            {
                n.DeleteAllSynapes();
            }
            ModuleView na1 = theNeuronArray.FindAreaByLabel("KBOut");

            if (na1 != null)
            {
                foreach (Neuron n in na1.Neurons())
                {
                    n.DeleteAllSynapes();
                }
            }

            //since we are inserting at 0, these are in reverse order
            UKS.Insert(0, new Thing {
                Label = "Sleep"
            });
            UKS.Insert(0, new Thing {
                Label = "Max"
            });
            UKS.Insert(0, new Thing {
                Label = "Ref"
            });
            UKS.Insert(0, new Thing {
                Label = "Parent"
            });
            firstThing  = 4;
            EventCount  = 0;
            phraseCount = 0;

            //add connections from speakPhonemes to this module

            ModuleView naPhonemes = theNeuronArray.FindAreaByLabel("ModuleSpeakPhonemes");

            if (naPhonemes != null)
            {
                Neuron n2 = GetNeuron(Labeled("SayRnd"));
                Neuron n3 = naPhonemes.GetNeuronAt("BabyTalk");
                if (n2 != null && n3 != null)
                {
                    n3.AddSynapse(n2.Id, 1);
                }
                Thing parent = Labeled("Vowel");
                foreach (Neuron n in naPhonemes.Neurons())
                {
                    if (n.Label == "Conson.")
                    {
                        parent = Labeled("Consonant");
                    }
                    if (n.Label.Length == 1)
                    {
                        string label = "spk" + n.Label;
                        Thing  pn    = AddThing(label, new Thing[] { parent });
                        Neuron n1    = GetNeuron(pn, false);
                        if (n1 != null)
                        {
                            n1.AddSynapse(n.Id, 1);
                        }
                    }
                }
            }

            UpdateNeuronLabels();
        }