Beispiel #1
0
 private void Clear()
 {
     SearchText = "";
     FilteredSentenceResultVM.Clear();
     _allSentenceResultVM.Clear();
     CombinationsResultVM.Clear();
     ClearFoundWords();
     Progress   = 0;
     TotalFound = 0;
 }
Beispiel #2
0
        public void FilterSentencesByWords()
        {
            if (_skipFilterSentences)
            {
                return;
            }

            FilteredSentenceResultVM.Clear();

            var selectedWordsDict = SelectedWords.ToLookup(x => x);

            var filteredSentences =
                _allSentenceResultVM
                .Where(x => x.Words.Any(y => selectedWordsDict.Contains(y)));

            _uiContext.Send(state =>
            {
                foreach (var item in filteredSentences)
                {
                    FilteredSentenceResultVM.Add((SentenceResultVM)item);
                }
            }, null);
        }
Beispiel #3
0
        private async Task Search()
        {
            if (string.IsNullOrEmpty(SearchText))
            {
                return;
            }

            ChangeEnableButtons(false);

            Progress = 0;

            FilteredSentenceResultVM.Clear();
            _allSentenceResultVM.Clear();

            ClearFoundWords();

            wordsFound.Clear();

            var searchText     = SearchText.ToCharArray();
            var ignoreTextArr  = IgnoreText?.Split(' ');
            var ignoreTextFunc = GetIgnoreTextFunction(ignoreTextArr);
            var i = 0;

            TotalFound = 1;
            //_isSearching = true;

            await Task.Run(() =>
            {
                var sentencesList  = GetSentencesList();
                var foundWords     = new Dictionary <int, string>();
                var searchFunction = GetSearchFunction(SearchText, SearchType);

                foreach (var sentence in sentencesList)
                {
                    if (_searchStopped)
                    {
                        break;
                    }

                    foundWords.Clear();
                    var wordsIndex = 0;

                    foreach (var word in sentence.Words)
                    {
                        if (word == null)
                        {
                            Debug.WriteLine($"Word is null. Sentence: {sentence}");
                            break;
                        }

                        if (ignoreTextFunc(ignoreTextArr, word))
                        {
                            break;
                        }

                        if (searchFunction(word))
                        {
                            foundWords.Add(wordsIndex, word);
                            wordsFound.Add(word);
                        }

                        wordsIndex++;
                    }

                    if (foundWords.Count > 0)
                    {
                        if (sentence.Text == null)
                        {
                            int foundWordIndex = 0;

                            foreach (var foundWord in foundWords)
                            {
                                var sentenceVM = new SentenceResultVM
                                {
                                    Sentence       = sentence,
                                    Id             = TotalFound,
                                    Words          = new ObservableCollection <string>(new[] { foundWord.Value }),
                                    FoundWordIndex = foundWord.Key
                                };

                                _allSentenceResultVM.Add(sentenceVM);

                                _uiContext.Send(state =>
                                {
                                    FilteredSentenceResultVM.Add(sentenceVM);
                                }, null);

                                ++TotalFound;
                                ++foundWordIndex;
                            }
                        }
                        else
                        {
                            var sentenceVM = new SentenceResultVM
                            {
                                Sentence = sentence,
                                Id       = TotalFound,
                                Words    = new ObservableCollection <string>(foundWords.Values)
                            };

                            _allSentenceResultVM.Add(sentenceVM);

                            _uiContext.Send(state =>
                            {
                                FilteredSentenceResultVM.Add(sentenceVM);
                            }, null);

                            ++TotalFound;
                        }
                    }

                    i++;

                    var progress = (int)((i / (float)sentencesList.Count) * 100);

                    _uiContext.Send((state) => Progress = progress, null);
                }

                --TotalFound;

                ChangeEnableButtons(true);

                Progress = 0;
            });

            _skipFilterSentences = true;

            foreach (var word in wordsFound.OrderBy(x => x))
            {
                WordsVM.Add(word);
                SelectedWords.Add(word);
            }

            _skipFilterSentences = false;
        }