コード例 #1
0
        public static WordSet RandomModals()
        {
            Dictionary <int, int> odds = new Dictionary <int, int>
            {
                { 0, 74 },
                { 1, 10 },
                { 2, 10 },
                { 3, 6 },
                { 4, 0 },
            };

            ConvertToCummulative(odds);

            int dice    = random.Next(0, 101);
            var howMany = odds.Where(x => dice <= x.Value).Select(x => x.Key).First();

            WordSet ws = new WordSet();

            while (howMany > 0)
            {
                ws.Add(new Word(Token.Modals[random.Next(0, Token.Modals.Length)]));
                howMany--;
            }

            return(ws);
        }
コード例 #2
0
        public WordSet RandomAdverbs()
        {
            Dictionary <int, int> odds = new Dictionary <int, int>
            {
                { 0, 88 },
                { 1, 7 },
                { 2, 5 },
                { 3, 0 },
                { 4, 0 },
            };

            ConvertToCummulative(odds);
            int dice    = random.Next(0, 101);
            var howMany = odds.Where(x => dice <= x.Value).Select(x => x.Key).First();

            WordSet ws = new WordSet();

            while (howMany > 0)
            {
                ws.Add(RandomWord("adv"));
                howMany--;
            }

            return(ws);
        }
        //Can be combined with li (predicate) or en (subject).
        // kasi suli laso ==> kasi suli en kasi laso
        // kasi suli laso ==> kasi li suli li laso
        // kasi suli laso ==> kasi li suli. kasi li laso
        public Chain ExpandedToChain()
        {
            List <HeadedPhrase> l = new List <HeadedPhrase>();

            foreach (Word modifier in phrase.Modifiers)
            {
                WordSet modifiers = new WordSet();
                modifiers.Add(modifier);
                l.Add(new HeadedPhrase(phrase.Head, modifiers));
            }
            Chain c = new Chain(Particles.en, l.ToArray());

            return(c);
        }
コード例 #4
0
ファイル: AI.cs プロジェクト: RoryHiggins/Portfolio
        public string GenerateSentence(WordSet inputWords, WordSet relatedWords, Word startingWord, Random rand)
        {
            //If the starting word is moot, generate another one

            Word currentWord, lastWord;
            string ret = "";
            int wordCount = 1;
            int maxWordCount = Math.Min(Sentence.maxWords, wordbank.AverageSentenceLength);
            maxWordCount = Math.Max(maxWordCount, Sentence.minWords);
            lastWord = startingWord;
            ret += Word.ToSentenceCase(lastWord.name);
            WordSet appearedWords = new WordSet();

            while ( wordCount < maxWordCount )
            {
                if ( lastWord.followingWords.Count == 0 ) { break; }

                WeightedWordDict relatedFollowingWords = GetRelatedWords(lastWord.followingWords, relatedWords);

                //Tries to choose the current word.  If it cant choose a related followed word, choose any followed one
                if ( wordCount >= Sentence.minWords )
                {
                    currentWord = relatedFollowingWords.ChooseRandomEndingWord(rand);
                    if ( currentWord == null ) { currentWord = relatedFollowingWords.ChooseRandomWord(rand); }
                }
                else
                { currentWord = relatedFollowingWords.ChooseRandomWord(rand); }

                if ( appearedWords.Contains(currentWord) )
                {
                    relatedFollowingWords.Remove(currentWord);
                    currentWord = relatedFollowingWords.ChooseRandomWord(rand);
                }
                if ( currentWord == null ) { currentWord = lastWord.followingWords.ChooseRandomWord(rand); }
                if ( currentWord == null ) { DANI.Program.NullError("ChooseRandomWord returned null with non-empty list (last word "+lastWord+")."); break; }

                appearedWords.Add(currentWord);
                lastWord = currentWord;

                ret += " " + currentWord.GetName;
                wordCount++;

                if ( ( currentWord.endingWord ) && ( wordCount >= Sentence.minWords ) )
                { DANI.Program.DebugMsg("endingWord ended: " + currentWord.GetName); break; }
            }

            return ret;
        }
コード例 #5
0
        //language|word|noun|adj|vt|vi|adv|prep|pronoun|kama|conditional|interj|conj|
        private Sentence SingleExclamation()
        {
            Word interj = RandomWord("interj");
            //Word[] exclamationModifiers = new Word[]
            //{
            //    Words.a, Words.kin
            //};
            Dictionary <int, int> odds = new Dictionary <int, int>
            {
                { 0, 85 },
                { 1, 10 },
                { 2, 5 }
            };

            ConvertToCummulative(odds);
            int     dice = random.Next(0, 101);
            WordSet ws   = new WordSet();

            if (dice < 25)
            {
                dice = random.Next(0, 101);
                var howMany = odds.Where(x => dice <= x.Value).Select(x => x.Key).First();
                while (howMany > 0)
                {
                    ws.Add(new Word(Token.Modals[random.Next(0, Token.Modals.Length)]));
                    howMany--;
                }
                Exclamation e = new Exclamation(new HeadedPhrase(interj, ws));
                Sentence    s = new Sentence(e, new Punctuation("!"), SentenceDiagnostics.NotFromParser);
                return(s);
            }
            else
            {
                Exclamation e = new Exclamation(new HeadedPhrase(interj));
                Sentence    s = new Sentence(e, new Punctuation("!"), SentenceDiagnostics.NotFromParser);
                return(s);
            }
        }
コード例 #6
0
ファイル: AI.cs プロジェクト: RoryHiggins/Portfolio
        public WordSet GetRelatedWords(WordSet words)
        {
            WordSet relatedWords = new WordSet();
            foreach ( Word word in words )
            {
                foreach ( Word associatedWord in word.associations )
                {
                    if ( relatedWords.Contains(associatedWord) == false )
                    { relatedWords.Add(associatedWord); }
                }
            }

            return relatedWords;
        }
コード例 #7
0
ファイル: AI.cs プロジェクト: RoryHiggins/Portfolio
        public WordSet TextToWordlist(string text)
        {
            WordSet wordlist = new WordSet();
            Word currentWord = null;

            foreach ( string sentence in Sentence.TextToSentences(text) )
            {
                foreach ( string word in Sentence.ToWords(sentence) )
                {
                    wordbank.wordlist.TryGetValue(word.ToLower(), out currentWord);

                    if ( ( currentWord != null ) && ( wordlist.Contains(currentWord) == false ) )
                    { wordlist.Add(currentWord); }
                }
            }

            return wordlist;
        }