Exemplo n.º 1
0
        public List <UserKnowledgeItem> ConvertEntitiesToItems(long sourceLanguageId,
                                                               long translationLanguageId,
                                                               IEnumerable <UserKnowledge> userKnowledges)
        {
            var knowledgesConverter = new KnowledgesParser();
            var result = userKnowledges.Select(e => new UserKnowledgeItem(e)).ToList();

            knowledgesConverter.FillItemsParsedData(sourceLanguageId, translationLanguageId, result);
            return(result);
        }
Exemplo n.º 2
0
        public Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> > Generate(
            Dictionary <KnowledgeDataType, int> counts)
        {
            var sourceItems = new List <GeneratedKnowledgeItem>();

            int countWords = counts[KnowledgeDataType.WordTranslation];

            WriteShuffleWordsToResult(countWords, sourceItems);

            int countPhrases = counts[KnowledgeDataType.PhraseTranslation];

            WriteShuffledSentencesToResult(KnowledgeDataType.PhraseTranslation, SentenceType.FromGroup, countPhrases,
                                           sourceItems);

            int countSentences      = counts[KnowledgeDataType.SentenceTranslation];
            int countAddedSentences = WriteShuffledSentencesToResult(KnowledgeDataType.SentenceTranslation,
                                                                     SentenceType.Separate, countSentences,
                                                                     sourceItems);

            if (countAddedSentences < countSentences)
            {
                //добавили меньше, чем нужно - попробуем добрать из примеров предложений
                WriteShuffledSentencesToResult(KnowledgeDataType.SentenceTranslation, SentenceType.ComparisonExample,
                                               countSentences - countAddedSentences,
                                               sourceItems);
            }

            var knowledgesConverter = new KnowledgesParser();

            knowledgesConverter.FillItemsParsedData(_mainLanguageId,
                                                    _translationLanguageId,
                                                    sourceItems);

            var result = new Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> >();

            foreach (GeneratedKnowledgeItem sourceItem in sourceItems)
            {
                KnowledgeDataType             dataType = sourceItem.DataType;
                List <GeneratedKnowledgeItem> items;
                if (!result.TryGetValue(dataType, out items))
                {
                    items = new List <GeneratedKnowledgeItem>();
                    result.Add(dataType, items);
                }
                items.Add(sourceItem);
            }
            return(result);
        }