public bool Contains(Word word)
 {
     if (headVerb != null)
     {
         if (WordByValue.Instance.Equals(word, headVerb))
         {
             return(true);
         }
     }
     if (modals != null)
     {
         if (modals.Contains(word))
         {
             return(true);
         }
     }
     if (adverbs != null)
     {
         if (adverbs.Contains(word))
         {
             return(true);
         }
     }
     if (nounComplement != null)
     {
         if (nounComplement.Contains(word))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
    static void GetAllWords(Tile[] tiles, int index, TileWord candidate, List <TileWord> words)
    {
        if (!SubWordSet.Contains(candidate.Word))
        {
            return;
        }

        tiles[index].IsTaken = true;

        if (WordSet.Contains(candidate.Word))
        {
            words.Add(candidate);
        }

        for (int i = 0; i < 8; i++)
        {
            var row = index / 4 + (int)Math.Round(Math.Sin(Math.PI / 4 * (i - 2)));
            var col = index % 4 + (int)Math.Round(Math.Sin(Math.PI / 4 * i));

            if (row >= 0 && row < 4 && col >= 0 && col < 4 && !tiles[row * 4 + col].IsTaken)
            {
                GetAllWords(tiles, row * 4 + col, candidate.Add(tiles[row * 4 + col]), words);
            }
        }

        tiles[index].IsTaken = false;
    }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        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;
        }
Beispiel #6
0
        public WeightedWordDict GetRelatedWords(WeightedWordDict words, WordSet relations)
        {
            WeightedWordDict relatedWords = new WeightedWordDict();

            foreach ( KeyValuePair<Word, int> pair in words )
            {
                if ( relations.Contains(pair.Key) )
                { relatedWords.Add(pair); }
            }

            return relatedWords;
        }
Beispiel #7
0
 public static bool Contains(string word)
 {
     return(WordSet.Contains(word.ToLowerInvariant()));
 }
Beispiel #8
0
        private bool IsWordInDictionary(string word)
        {
            bool isValidWord = WordSet.Contains(word.ToLower());

            return(isValidWord);
        }