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()); }
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; }
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); }
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); }
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))); }
public bool WordContainsDuplicateLetters(WordData selectedWord, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase) { var wordLetters = GetLettersInWord(selectedWord); return(wordLetters.GroupBy(x => x.Id).Any(g => g.Count() > 1)); }
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); }
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); }
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()); }
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); }
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); }
public List <WordData> GetWordsWithoutLetters(WordFilters filters, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase, params LetterData[] tabooLetters) { return(GetWordsByLetters(filters, null, tabooLetters, letterEqualityStrictness)); }
public List <WordData> GetWordsWithLetter(WordFilters filters, LetterData okLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterBase) { return(GetWordsByLetters(filters, new[] { okLetter }, null, letterEqualityStrictness)); }
public List <WordData> GetWordsWithLetters(WordFilters filters, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.LetterOnly, params LetterData[] okLetters) { return(GetWordsByLetters(filters, okLetters, null, letterEqualityStrictness)); }
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); }
public List <WordData> GetWordsWithoutLetter(WordFilters filters, LetterData tabooLetter, LetterEqualityStrictness letterEqualityStrictness = LetterEqualityStrictness.Letter) { return(GetWordsByLetters(filters, null, new[] { tabooLetter }, letterEqualityStrictness)); }
public List <LetterData> GetLettersNotInWords(LetterEqualityStrictness equalityStrictness = LetterEqualityStrictness.LetterBase, params WordData[] tabooArray) { return(GetLettersNotInWords(LetterKindCategory.Real, equalityStrictness, tabooArray)); }
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); }
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); }
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); }
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); }
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); }
public StrictLetterDataComparer(LetterEqualityStrictness comparisonStrictness) { this.comparisonStrictness = comparisonStrictness; }