Beispiel #1
0
        /// <summary>
        /// 句子列表刷新执行的方法
        /// </summary>
        /// <returns></returns>
        async Task ExecuteLoadSentenceItemsCommand(string sid)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                SentenceItems.Clear();
                var items = await sqliteData.GetSentenceItemsAsync(sid);//DataStore.GetSentenceItemsAsync(true);

                foreach (var item in items)
                {
                    SentenceItems.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #2
0
 public Sentence(IEnumerable <ISentenceItem> sentenceItems) : this()
 {
     foreach (var item in sentenceItems)
     {
         SentenceItems.Add(item);
     }
 }
        /// <summary>
        /// Задание элементов предложения
        /// </summary>
        /// <param name="sentence">предложение</param>
        /// <param name="entities">сущности</param>
        /// <param name="currentContentIndex">индекс, с которого идут контенты данного предложения</param>
        /// <returns>элементы предложения</returns>
        private SentenceItems SetSentenceItems(TextParsing.Sentence sentence, IList <Entity> entities, ref int currentContentIndex)
        {
            var result = new SentenceItems(sentence, entities.ToArray(), currentContentIndex);

            GetContentIndexesInsideSentence(sentence, ref currentContentIndex);
            entities.Clear();
            return(result);
        }
        /// <summary>
        /// Получение нового текста предложения
        /// </summary>
        /// <param name="sentenceItems">элементы предложения</param>
        /// <param name="contentInfo">информация о корректируемом контенте</param>
        /// <returns>новый текст предложения</returns>
        private string GetNewSentenceText(SentenceItems sentenceItems, CorrectedContentInfo contentInfo)
        {
            var sentenceInfo             = new CorrectedSentenceInfo(sentenceItems);
            int entityIndex              = 0;
            int startContentIndex        = sentenceInfo.SentenceItems.ContentIndex - contentInfo.RemovedContentCount;
            int removedContentCountStart = contentInfo.RemovedContentCount;

            foreach (int index in GetContentIndexesInsideSentence(sentenceItems.Sentence, ref startContentIndex, contentInfo.RemovedContentLength))
            {
                int removedContentCount = contentInfo.RemovedContentCount - removedContentCountStart;
                DecomposeEntitiesAndContentToSentence(index - removedContentCount, sentenceInfo, contentInfo, ref entityIndex);
            }
            for (int i = sentenceItems.Entities.Length - 1; i >= entityIndex; --i)
            {
                AddEntity(sentenceItems.Entities[i], contentInfo.CurrentEntityShift);
            }
            return(sentenceInfo.NewSentenceText.ToString());
        }
Beispiel #5
0
        private void CombineSentenceItems(int index, StringBuilder sb)
        {
            _index = index;
            while (true)
            {
                _index++;
                if (_index >= SentenceItems.Count)
                {
                    break;
                }
                sb.Append(SentenceItems[_index].Chars);
                var nextElement = SentenceItems.ElementAtOrDefault(_index + 1);
                if (nextElement == null)
                {
                    continue;
                }
                if (PunctuationHelper.EndSymsols.Contains(SentenceItems[_index].Chars) ||
                    PunctuationHelper.OperationSymbols.Contains(SentenceItems[_index].Chars) ||
                    PunctuationHelper.CloseSymbols.Contains(nextElement.Chars) ||
                    PunctuationHelper.InnerSymbols.Contains(nextElement.Chars) ||
                    PunctuationHelper.EndSymsols.Contains(nextElement.Chars) ||
                    PunctuationHelper.EndSymsols.Contains(nextElement.Chars))
                {
                    continue;
                }
                if (PunctuationHelper.CloseSymbols.Contains(SentenceItems[_index].Chars))
                {
                    break;
                }
                if (PunctuationHelper.OpenSymbols.Contains(SentenceItems[_index].Chars) ||
                    PunctuationHelper.RepeatSymbols.Contains(SentenceItems[_index].Chars))
                {
                    CombineSentenceItems(_index, sb);
                }

                if (!PunctuationHelper.CloseSymbols.Contains(nextElement.Chars) ||
                    PunctuationHelper.OpenSymbols.Contains(nextElement.Chars))
                {
                    sb.Append(" ");
                }
            }
        }
 public CorrectedSentenceInfo(SentenceItems sentenceItems)
 {
     SentenceItems   = sentenceItems;
     NewSentenceText = new StringBuilder(SentenceItems.Sentence.Text);
 }
Beispiel #7
0
 public ISentence RemoveWordsBy(Func <IWord, bool> predicate)
 {
     return(new Sentence(SentenceItems.Where(s => !(s is IWord && predicate((IWord)s)))));
 }
Beispiel #8
0
 public IEnumerable <IWord> GetWordsWithoutRepetition(int length)
 {
     return(SentenceItems.Where(s => s is IWord).Cast <IWord>().Where(s => s.Length == length));
 }