private static bool CheckIfWordpairIsInCollection(VocabularyCollectionDto vocabularies, WordPairDto wordPair) { var isNewWordInCollection = vocabularies.English.All(v => v.Word != wordPair.English) || vocabularies.Arabic.All(v => v.Word != wordPair.Arabic); return(isNewWordInCollection); }
private static VocabularyCollectionDto ProduceVocabularies(Text text) { var vocabularies = new VocabularyCollectionDto { Arabic = new List <VocabularyDto> (), English = new List <VocabularyDto> () }; var numberOfSentences = text.Sentences.Count; int numberOfVocabulariesToAdd = numberOfSentences > 6 ? 5 : numberOfSentences - 1; while (vocabularies.Arabic.Count < numberOfVocabulariesToAdd) { var randomNumber = new Random(); var randomSentenceId = randomNumber.Next(0, text.Sentences.Count); var randomWordPair = GetRandomWordPairFromSentences(randomSentenceId, text.Sentences); var isWordLengthSatisfied = CheckWordLength(randomWordPair); var isNewWordInCollection = CheckIfWordpairIsInCollection(vocabularies, randomWordPair); var allConditionsSatisfied = isWordLengthSatisfied && isNewWordInCollection; if (!allConditionsSatisfied) { continue; } vocabularies.English.Add(new VocabularyDto { Word = randomWordPair.English, WordId = vocabularies.English.Count }); vocabularies.Arabic.Add(new VocabularyDto { Word = randomWordPair.Arabic, WordId = vocabularies.Arabic.Count }); } // Shuffle vocabulary lists so that arabic and english words don't appear in the same order vocabularies.Arabic = ShuffleVocabularies(vocabularies.Arabic); vocabularies.English = ShuffleVocabularies(vocabularies.English); return(vocabularies); }