예제 #1
0
        protected void teachNewSingleWord(string word)
        {
            // Wrzucamy do gotowej sieci słowo w losowe miejsce.
            // Jan Grzywacz.

            SentenceNode victim = totallyRandomChild();

            if (victim.word == "NULL")
            {
                victim = this;
            }

            SentenceNode newChild = addNewWord(word, 0);

            victim.appendChild(newChild);

            SentenceNode anotherVictim = totallyRandomChild();

            newChild.appendChild(anotherVictim);
        }
예제 #2
0
        protected void teachNewSentence(string sentence)
        {
            // Analogiczna metoda do tej z NodeV2,
            // różni się wstępną obróbką zdań.
            // Jan Grzywacz.

            // Usuwanie znaków interpunkcyjnych i dużych liter.
            sentence = sentence.ToLower();
            sentence = sentence.RemoveAll(
                new string[] { "\"", ".", ",", "!", "?", "\\", ":", "-", "_" });

            // Dzielenie zdania na słowa.
            string[] words = sentence.Split(new char[] { ' ' });

            SentenceNode lastChild = null;
            SentenceNode newChild  = null;

            for (int i = 0; i < words.Length; i++)
            {
                if (lastChild == null)
                {
                    // Słowo rozpoczynające.
                    newChild = addNewWord(words[i], 1);
                }
                else
                {
                    // Normalne słowo - dodajemy je do listy dziecka.
                    newChild = addNewWord(words[i], 0);
                    lastChild.appendChild(newChild);
                }

                lastChild = newChild;
            }

            // Ostatnie słowo - dodajemy zakończenie.
            lastChild.counters[0]++;
            lastChild.total++;
        }