Exemple #1
0
        public List <LetterData> GetLettersNotIn(LetterEqualityStrictness equalityStrictness, LetterFilters filters, params LetterData[] tabooArray)
        {
            var comparer         = new StrictLetterDataComparer(equalityStrictness);
            var lettersWithForms = GetAllLettersAndForms(filters);

            return(lettersWithForms.Where(x => !tabooArray.Contains(x, comparer)).ToList());
        }
Exemple #2
0
        public List <LetterData> GetLettersNotInWord(WordData wordData, LetterKindCategory category = LetterKindCategory.Real, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var comparer         = new StrictLetterDataComparer(equalityStrictness);
            var lettersInWord    = GetLettersInWord(wordData);
            var lettersNotInWord = dbManager.FindLetterData(x => !lettersInWord.Contains(x, comparer) && x.IsOfKindCategory(category));

            return(lettersNotInWord);
        }
Exemple #3
0
        public bool AnyWordContainsLetter(LetterData letter, IEnumerable <WordData> words, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var comparer = new StrictLetterDataComparer(equalityStrictness);

            foreach (var word in words)
            {
                if (GetLettersInWord(word).Contains(letter, comparer))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #4
0
        public bool IsLetterContainedInAnyWord(LetterData letter, List <WordData> words, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var comparer = new StrictLetterDataComparer(equalityStrictness);

            foreach (var word in words)
            {
                var containedLetters = GetLettersInWord(word);
                if (containedLetters.Contains(letter, comparer))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        public bool WordContainsAnyLetter(WordData word, IEnumerable <LetterData> letters, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var comparer         = new StrictLetterDataComparer(equalityStrictness);
            var containedLetters = GetLettersInWord(word);

            foreach (var letter in letters)
            {
                if (containedLetters.Contains(letter, comparer))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #6
0
        public List <LetterData> GetLettersNotInWords(LetterKindCategory category = LetterKindCategory.Real, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase, params WordData[] tabooArray)
        {
            var comparer       = new StrictLetterDataComparer(equalityStrictness);
            var lettersInWords = new HashSet <LetterData>(comparer);

            foreach (var tabooWordData in tabooArray)
            {
                var tabooWordDataLetters = GetLettersInWord(tabooWordData);
                lettersInWords.UnionWith(tabooWordDataLetters);
            }
            var lettersNotInWords = dbManager.FindLetterData(x => !lettersInWords.Contains(x, comparer) && x.IsOfKindCategory(category));

            return(lettersNotInWords);
        }
Exemple #7
0
        public List <LetterData> GetCommonLettersInWords(LetterEqualityStrictness letterEqualityStrictness, params WordData[] words)
        {
            var comparer = new StrictLetterDataComparer(letterEqualityStrictness);
            Dictionary <LetterData, int> countDict = new Dictionary <LetterData, int>(comparer);

            foreach (var word in words)
            {
                var nonRepeatingLettersOfWord = new HashSet <LetterData>(comparer);

                var letters = GetLettersInWord(word);
                foreach (var letter in letters)
                {
                    nonRepeatingLettersOfWord.Add(letter);
                }

                foreach (var letter in nonRepeatingLettersOfWord)
                {
                    if (!countDict.ContainsKey(letter))
                    {
                        countDict[letter] = 0;
                    }
                    countDict[letter] += 1;
                }
            }

            // Get only these letters that are in all words
            var commonLettersList = new List <LetterData>();

            foreach (var letter in countDict.Keys)
            {
                if (countDict[letter] == words.Length)
                {
                    commonLettersList.Add(letter);
                }
            }

            return(commonLettersList);
        }
Exemple #8
0
        private List <WordData> GetWordsByLetters(WordFilters filters, LetterData[] okLettersArray, LetterData[] tabooLettersArray, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase)
        {
            if (okLettersArray == null)
            {
                okLettersArray = new LetterData[] { }
            }
            ;
            if (tabooLettersArray == null)
            {
                tabooLettersArray = new LetterData[] { }
            }
            ;

            var okLetters    = new HashSet <LetterData>(okLettersArray);
            var tabooLetters = new HashSet <LetterData>(tabooLettersArray);

            var comparer = new StrictLetterDataComparer(letterEqualityStrictness);

            List <WordData> wordsByLetters = dbManager.FindWordData(word => {
                if (!CheckFilters(filters, word))
                {
                    return(false);
                }

                var lettersInWord = GetLettersInWord(word);

                if (tabooLetters.Count > 0)
                {
                    foreach (var letter in lettersInWord)
                    {
                        if (tabooLetters.Contains(letter, comparer))
                        {
                            return(false);
                        }
                    }
                }

                if (okLetters.Count > 0)
                {
                    bool hasAllOkLetters = true;
                    foreach (var okLetter in okLetters)
                    {
                        bool hasThisLetter = false;
                        foreach (var letter in lettersInWord)
                        {
                            if (letter.IsSameLetterAs(okLetter, letterEqualityStrictness))
                            {
                                hasThisLetter = true;
                                break;
                            }
                        }
                        if (!hasThisLetter)
                        {
                            hasAllOkLetters = false;
                            break;
                        }
                    }
                    if (!hasAllOkLetters)
                    {
                        return(false);
                    }
                }
                return(true);
            }
                                                                    );

            return(wordsByLetters);
        }
Exemple #9
0
        public List <LetterData> GetAllLetterAlterations(List <LetterData> baseLetters, LetterAlterationFilters letterAlterationFilters)
        {
            List <LetterData> letterPool = new List <LetterData>();

            // Filter: only 1 base or multiple bases?
            if (!letterAlterationFilters.differentBaseLetters)
            {
                var chosenLetter = baseLetters.RandomSelectOne();
                baseLetters.Clear();
                baseLetters.Add(chosenLetter);
            }

            // Get all alterations for the given bases
            foreach (var baseLetter in baseLetters)
            {
                // Check all alterations of this base letter
                var letterAlterations = GetLettersWithBase(baseLetter.GetId());
                List <LetterData> availableVariations = new List <LetterData>();
                foreach (var letterData in letterAlterations)
                {
                    if (!FilterByDiacritics(letterAlterationFilters.ExcludeDiacritics, letterData))
                    {
                        continue;
                    }
                    if (!FilterByLetterVariations(letterAlterationFilters.ExcludeLetterVariations, letterData))
                    {
                        continue;
                    }
                    if (!FilterByDipthongs(letterAlterationFilters.excludeDipthongs, letterData))
                    {
                        continue;
                    }
                    availableVariations.Add(letterData);
                }
                //Debug.Log("N availableVariations  " + availableVariations.Count + "  for " + baseLetter.GetId());

                List <LetterData> basesForForms = new List <LetterData>(availableVariations);
                basesForForms.Add(baseLetter);
                //Debug.Log("N bases for forms: " +  basesForForms.Count);
                if (letterAlterationFilters.includeForms)
                {
                    // Place forms only inside the pool, if needed
                    foreach (var baseForForm in basesForForms)
                    {
                        var availableForms = ExtractLettersWithForms(baseForForm);

                        if (letterAlterationFilters.oneFormPerLetter)
                        {
                            // If we are using forms and only one form per letter must appear, add just one at random
                            letterPool.Add(availableForms.RandomSelectOne());
                        }
                        else
                        {
                            // Add all the (different) forms
                            var visualFormComparer = new StrictLetterDataComparer(LetterEqualityStrictness.WithVisualForm);
                            foreach (var availableForm in availableForms)
                            {
                                if (letterAlterationFilters.visuallyDifferentForms && letterPool.Contains(availableForm, visualFormComparer))
                                {
                                    continue;
                                }
                                letterPool.Add(availableForm);
                            }
                        }
                    }
                }
                else
                {
                    // Place just the isolated versions
                    letterPool.AddRange(basesForForms);
                }
            }

            return(letterPool);
        }