예제 #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());
        }
예제 #2
0
 public QuestionBuilderParameters()
 {
     this.correctChoicesHistory    = PackListHistory.RepeatWhenFull;
     this.wrongChoicesHistory      = PackListHistory.RepeatWhenFull;
     this.useJourneyForCorrect     = true;
     this.useJourneyForWrong       = true;
     this.correctSeverity          = SelectionSeverity.MayRepeatIfNotEnough;
     this.wrongSeverity            = SelectionSeverity.MayRepeatIfNotEnough;
     this.letterEqualityStrictness = LetterEqualityStrictness.LetterOnly;
     this.letterFilters            = new LetterFilters();
     this.wordFilters           = new WordFilters();
     this.phraseFilters         = new PhraseFilters();
     this.sortPacksByDifficulty = true;
 }
 public CommonLetterInWordQuestionBuilder(int nPacks,
                                          int nWrong = 0, int nWords = 1,
                                          LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterOnly,
                                          QuestionBuilderParameters parameters = null)
 {
     if (parameters == null)
     {
         parameters = new QuestionBuilderParameters();
     }
     this.nPacks = nPacks;
     this.nWrong = nWrong;
     this.nWords = nWords;
     this.letterEqualityStrictness = letterEqualityStrictness;
     this.parameters = parameters;
 }
예제 #4
0
        public bool IsSameLetterAs(LetterData other, LetterEqualityStrictness strictness)
        {
            bool isEqual = false;

            switch (strictness)
            {
            case LetterEqualityStrictness.LetterOnly:
                isEqual = string.Equals(_Id, other._Id);
                break;

            case LetterEqualityStrictness.WithActualForm:
                isEqual = string.Equals(_Id, other._Id) && Form == other.Form;
                break;

            case LetterEqualityStrictness.WithVisualForm:
                isEqual = string.Equals(_Id, other._Id) && FormsLookTheSame(Form, other.Form);
                break;
            }
            return(isEqual);
        }
예제 #5
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);
        }
예제 #6
0
        public bool WordContainsLetter(WordData selectedWord, LetterData containedLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase)
        {
            //if (containedLetter.Id == "lam_alef") Debug.Log("Looking for lam-alef in " + selectedWord);
            //foreach (var l in ArabicAlphabetHelper.FindLetter(dbManager, selectedWord, containedLetter))
            //if (l.letter.Id == "lam_alef") Debug.Log("Lam alef form " + l.letterForm + " in word " + selectedWord);
            var lettersInWord = GetLettersInWord(selectedWord);

            return(lettersInWord.Any(x => x.IsSameLetterAs(containedLetter, letterEqualityStrictness)));
        }
예제 #7
0
        public bool WordContainsDuplicateLetters(WordData selectedWord, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var wordLetters = GetLettersInWord(selectedWord);

            return(wordLetters.GroupBy(x => x.Id).Any(g => g.Count() > 1));
        }
예제 #8
0
        public int WordContainsLetterTimes(WordData selectedWord, LetterData containedLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var wordLetters = GetLettersInWord(selectedWord);
            int count       = 0;

            foreach (var letter in wordLetters)
            {
                if (letter.IsSameLetterAs(containedLetter, letterEqualityStrictness))
                {
                    count++;
                }
            }
            return(count);
        }
예제 #9
0
        public List <StringPart> FindLetter(DatabaseManager database, WordData wordData, LetterData letterToFind, LetterEqualityStrictness strictness)
        {
            var stringParts = new List <StringPart>();

            bool findSameForm = strictness == LetterEqualityStrictness.WithActualForm || strictness == LetterEqualityStrictness.WithVisualForm;
            var  parts        = SplitWord(database, wordData, separateDiacritics: false, separateVariations: letterToFind.Kind != LetterDataKind.LetterVariation, keepFormInsideLetter: findSameForm);

            for (int i = 0, count = parts.Count; i < count; ++i)
            {
                if (parts[i].letter.IsSameLetterAs(letterToFind, strictness))
                {
                    stringParts.Add(parts[i]);
                }
            }

            return(stringParts);
        }
예제 #10
0
        public List <LetterData> GetNotCommonLettersInWords(LetterFilters letterFilters, LetterEqualityStrictness letterEqualityStrictness, WordData[] words)
        {
            var commonLetters                = GetCommonLettersInWords(letterEqualityStrictness, words);
            var nonCommonLetters             = GetAllLettersAndForms(letterFilters);
            var nonCommonLettersWithComparer = new HashSet <LetterData>(new StrictLetterDataComparer(letterEqualityStrictness));

            nonCommonLettersWithComparer.UnionWith(nonCommonLetters);
            foreach (var commonLetter in commonLetters)
            {
                nonCommonLettersWithComparer.Remove(commonLetter);
            }
            return(nonCommonLettersWithComparer.ToList());
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
 public List <WordData> GetWordsWithoutLetters(WordFilters filters, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase, params LetterData[] tabooLetters)
 {
     return(GetWordsByLetters(filters, null, tabooLetters, letterEqualityStrictness));
 }
예제 #14
0
 public List <WordData> GetWordsWithLetter(WordFilters filters, LetterData okLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase)
 {
     return(GetWordsByLetters(filters, new[] { okLetter }, null, letterEqualityStrictness));
 }
예제 #15
0
 public List <WordData> GetWordsWithLetters(WordFilters filters, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterOnly, params LetterData[] okLetters)
 {
     return(GetWordsByLetters(filters, okLetters, null, letterEqualityStrictness));
 }
예제 #16
0
        public static bool IsDataMatching(ILivingLetterData ll1, ILivingLetterData ll2, LetterEqualityStrictness letterEqualityStrictness)
        {
            if (ll1 is LL_LetterData && ll2 is LL_LetterData)
            {
                var letter1 = ll1 as LL_LetterData;
                var letter2 = ll2 as LL_LetterData;

                //UnityEngine.Debug.Log("Matching letters " + letter1.Data + " and " + letter2.Data);
                return(letter1.Data.IsSameLetterAs(letter2.Data, strictness: letterEqualityStrictness));
            }
            else if ((ll1 is LL_WordData || ll1 is LL_ImageData) && (ll2 is LL_WordData || ll2 is LL_ImageData))
            {
                return(ll1.Id == ll2.Id);
            }
            else if (ll1 is LL_PhraseData && ll2 is LL_PhraseData)
            {
                var phrase1 = ll1 as LL_PhraseData;
                var phrase2 = ll2 as LL_PhraseData;
                return(phrase1.Data.Id == phrase2.Data.Id);
            }
            return(false);
        }
        private bool WordContainsLetter(WordData word, LetterData letter, int maxWordLength, LetterEqualityStrictness strictness)
        {
            // Check max length
            if (word.Letters.Length > maxWordLength)
            {
                return(false);
            }

            // Check that it contains the letter at least once
            if (AppManager.I.VocabularyHelper.WordContainsLetterTimes(word, letter, strictness) >= 1)
            {
                //Debug.Log("Letter " + letter + " is in word " + word + " " + AppManager.I.VocabularyHelper.WordContainsLetterTimes(word, letter, LetterEqualityStrictness.WithActualForm) + " times");
                return(true);
            }

            return(false);
        }
예제 #18
0
 public List <WordData> GetWordsWithoutLetter(WordFilters filters, LetterData tabooLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.Letter)
 {
     return(GetWordsByLetters(filters, null, new[] { tabooLetter }, letterEqualityStrictness));
 }
예제 #19
0
 public List <LetterData> GetLettersNotInWords(LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase, params WordData[] tabooArray)
 {
     return(GetLettersNotInWords(LetterKindCategory.Real, equalityStrictness, tabooArray));
 }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
0
        public bool WordHasAllLettersInCommonWith(WordData word, List <WordData> words, LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase)
        {
            var lettersInWord = GetLettersInWord(word);

            foreach (var letter in lettersInWord)
            {
                if (!IsLetterContainedInAnyWord(letter, words, equalityStrictness))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #23
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);
        }
예제 #24
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);
        }
예제 #25
0
 public StrictLetterDataComparer(LetterEqualityStrictness comparisonStrictness)
 {
     this.comparisonStrictness = comparisonStrictness;
 }