Example #1
0
 private static LinkedChain jsonLinkedChainToModelChain(JsonLinkedChain chain, SentenceWord[] words)
 {
     var result = new LinkedChain();
     result.Master.Words.AddRange(chain.Master.WordIndexes.Select(i => words[i]));
     result.Dependent.Words.AddRange(chain.Dependent.WordIndexes.Select(i => words[i]));
     return result;
 }
Example #2
0
            private static List<SentenceWordChain> wordIndexesListsToWordChains(WordIndexesList[] indexesLists, SentenceWord[] words)
            {
                return indexesLists.Select(list =>
                {
                    var result = new SentenceWordChain();

                    result.Words.AddRange(list.WordIndexes.Select(i => words[i]));

                    return result;
                }).ToList();
            }
        private void CreateDependantChain(int parentWordId, SentenceWord sourceWord, int[] excludeIds, ObjectType Type, Stage3ResultElement existingItem)
        {
            var words = _sentence.WordList;
            bool canAddItem = true;
            Stage3ResultElement addItem;
            if (existingItem == null)
            {
                addItem = new Stage3ResultElement();
                addItem.CopyFromSourceWord(sourceWord);
                addItem.DOM = parentWordId;
                addItem.ObjectType = Type;
            }
            else
            {
                addItem = existingItem;
            }

            // ищем Вторые слова
            List<SentenceWord> secondWords = _getChildWordsForWordById(sourceWord.Id, excludeIds);
            if (secondWords.Count > 0)
            {
                foreach (var secondWord in secondWords)
                {
                    // Каждое найденное Второе слово проверяется на наличие тэгов LINK = сочин или LINK = соч-союзн
                    bool hasSecondWordSochinLink = secondWord.Link.Value == LinkType.Sochin.Value || secondWord.Link.Value == LinkType.SochSouz.Value;

                    if (!hasSecondWordSochinLink)
                    {
                        bool firstWordLink = addItem.Link.Value == LinkType.PassAnal.Value || addItem.Link.Value == LinkType.Analit.Value || addItem.Link.Value == LinkType.Predl.Value;

                        if (!firstWordLink)
                        {
                            secondWord.LoadChainList(excludeIds, ref words, false, true);
                            if (existingItem != null)
                                addItem.ChainWordsIds.AddChild(sourceWord.Id);
                            addItem.ChainWordsIds.AddChild(secondWord.ChainWordsIds);
                        }
                        else
                        {
                            List<SentenceWord> thirdWords = _getChildWordsForWordById(secondWord.Id, excludeIds);
                            if (thirdWords.Count > 0)
                            {
                                foreach (var thirdWord in thirdWords)
                                {
                                    bool hasThirdWordSochinLink = thirdWord.Link.Value == LinkType.Sochin.Value || thirdWord.Link.Value == LinkType.SochSouz.Value;

                                    if (!hasThirdWordSochinLink)
                                    {
                                        thirdWord.LoadChainList(excludeIds, ref words, false, true);
                                        var node = addItem.ChainWordsIds.AddChild(thirdWord.Id);
                                        node.AddChild(thirdWord.ChainWordsIds);

                                    }
                                    else
                                    {   // сначала
                                        CreateDependantChain(parentWordId, thirdWord, excludeIds, Type, null);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (secondWord.Link.Value == LinkType.Sochin.Value)
                            CreateDependantChain(parentWordId, secondWord, excludeIds, Type, null);
                        if (secondWord.Link.Value == LinkType.SochSouz.Value)
                        {
                            CreateDependantChain(parentWordId, secondWord, excludeIds, Type, addItem);
                            canAddItem = false;
                        }

                    }
                }
            }
            if (canAddItem)
                Result.Items.Add(addItem);
        }
Example #4
0
 private static SimpleSentence wordIndexesToSimpleSentence(WordIndexesList indexes, SentenceWord[] words)
 {
     var result = new SimpleSentence();
     result.Words.AddRange(indexes.WordIndexes.Select(i => words[i]));
     return result;
 }
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage3Result != null);

            // ищем частицы
            List<SentenceWord> particles = sentence.WordList.Where(x => x.PartOfSpeech.Value == PartOfSpeech.Particle.Value).ToList();

            foreach (var itemStage3 in _stage3Result.Items)
            {
                Stage4ResultElement item = new Stage4ResultElement();
                item.CopyFromSourceWord(itemStage3);

                SentenceWord particle;

                particle = particles.Find(x => x.DOM == item.Id);
                if (particle != null)
                {
                    SentenceWord word = new SentenceWord();
                    word.CopyFromSourceWord(particle);
                    item.ServiceParts.Add(word);
                }

                particle = particles.Find(x => item.ServiceParts.Select(y => y.Id).ToList().Contains(x.DOM));
                if (particle != null)
                {
                    SentenceWord word = new SentenceWord();
                    word.CopyFromSourceWord(particle);
                    item.ServiceParts.Add(word);
                }

                Result.Items.Add(item);
            }
        }
        public override void ProcessSentence(Sentence sentence)
        {
            _sentence = sentence;
            Debug.Assert(_stage2Result != null);

            // TODO: объединить с main parts stage 3
            foreach (var itemStage2 in _stage2Result.Items.FindAll(x => x.IsConfirmed && !x.IsConjuction))
            {
                Stage3ResultElement item = new Stage3ResultElement();
                item.CopyFromSourceWord(itemStage2);

                foreach (var addWord in sentence.WordList.FindAll(x => x.DOM == itemStage2.Id && x.Link.Value == LinkType.Kolichest.Value))
                {
                    SentenceWord addItem = new SentenceWord();
                    addItem.CopyFromSourceWord(addWord);
                    item.AddedWordsCase1.Add(addItem);
                }

                foreach (var addWord in sentence.WordList.FindAll(x => x.DOM == itemStage2.Id && x.Link.Value == LinkType.Elekt.Value))
                {
                    SentenceWord addItem = new SentenceWord();
                    addItem.CopyFromSourceWord(addWord);
                    item.AddedWordsCase2.Add(addItem);

                    foreach (var addWord2 in sentence.WordList.FindAll(x => x.DOM == addItem.Id && x.Link.Value == LinkType.Predl.Value))
                    {
                        SentenceWord addItem2 = new SentenceWord();
                        addItem2.CopyFromSourceWord(addWord2);
                        item.AddedWordsCase2.Add(addItem2);
                    }
                }
                Result.Items.Add(item);
            }
        }
Example #7
0
 private static bool _isUnmapped(SentenceWord word, Sentence targetSentence)
 {
     return !(targetSentence.Subjects.Any(chain => chain.Words.Contains(word)) ||
              targetSentence.Predicates.Any(chain => chain.Words.Contains(word)) ||
              targetSentence.Uniforms.Any(chain => chain.Words.Contains(word)) ||
              targetSentence.ValuableAuxParts.Any(chain => chain.Words.Contains(word)) ||
              targetSentence.LinkedChains.Select(chain => new LinkedChainWords(chain))
                  .Any(words => words.Words.Contains(word)));
 }
Example #8
0
 public int WordIndex(SentenceWord word)
 {
     return _words.IndexOf(word);
 }