コード例 #1
1
        public void GenerateWordCloudAsync(Action<WordCloudResult> resultCallback, Action<int> progressCallback)
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;

            FileBasedProject currentProject = Project;
            worker.DoWork += (sender, e) =>
                {
                    WordCloudCache cache = new WordCloudCache();

                    IBlacklist blacklist = DefaultBlacklists.GetDefaultBlacklist(currentProject.GetProjectInfo().SourceLanguage.CultureInfo.TwoLetterISOLanguageName); //new NullBlacklist(); //ComponentFactory.CreateBlacklist(checkBoxExcludeEnglishCommonWords.Checked);
                    IBlacklist customBlacklist = new NullBlacklist(); // CommonBlacklist.CreateFromTextFile(s_BlacklistTxtFileName);

                    IProgressIndicator progress = new ProgressIndicator(); //ComponentFactory.CreateProgressBar(inputType, progressBar);
                    ProjectTextExtractor extractor = new ProjectTextExtractor(currentProject);
                    extractor.Progress += (s, p) => { worker.ReportProgress(p.PercentComplete); };
                    IEnumerable<string> terms = extractor.ExtractWords();  //ComponentFactory.CreateExtractor(inputType, textBox.Text, progress);
                    IWordStemmer stemmer = new NullStemmer(); //ComponentFactory.CreateWordStemmer(checkBoxGroupSameStemWords.Checked);

                    IEnumerable<IWord> rawWords = terms
                        .Filter(blacklist)
                        .Filter(customBlacklist)
                        .CountOccurences();
                    List<IWord> words = rawWords
                            .GroupByStem(stemmer)
                            .SortByOccurences()
                            .Cast<IWord>().ToList();

                    cache.Save("sourcecloud", currentProject, words);
                    e.Result = words;

                    if (Project != null && currentProject.GetProjectInfo().Id == Project.GetProjectInfo().Id)
                    {
                        Words = words;
                    }
                };
            worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (Project != null && currentProject.GetProjectInfo().Id == Project.GetProjectInfo().Id)
                    {
                        WordCloudResult result = new WordCloudResult();
                        if (e.Error != null)
                        {
                            result.Exception = e.Error;
                        }
                        else
                        {
                            result.WeightedWords = (IEnumerable<IWord>)e.Result;
                        }

                        resultCallback(result);
                    }
                };
            worker.ProgressChanged += (sender, e) => {  progressCallback(e.ProgressPercentage); };
            worker.RunWorkerAsync();
        }        
コード例 #2
0
        public void GenerateWordCloudAsync(Action <WordCloudResult> resultCallback, Action <int> progressCallback)
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;

            FileBasedProject currentProject = Project;

            worker.DoWork += (sender, e) =>
            {
                WordCloudCache cache = new WordCloudCache();

                IBlacklist blacklist       = DefaultBlacklists.GetDefaultBlacklist(currentProject.GetProjectInfo().SourceLanguage.CultureInfo.TwoLetterISOLanguageName); //new NullBlacklist(); //ComponentFactory.CreateBlacklist(checkBoxExcludeEnglishCommonWords.Checked);
                IBlacklist customBlacklist = new NullBlacklist();                                                                                                        // CommonBlacklist.CreateFromTextFile(s_BlacklistTxtFileName);

                IProgressIndicator   progress  = new ProgressIndicator();                                                                                                //ComponentFactory.CreateProgressBar(inputType, progressBar);
                ProjectTextExtractor extractor = new ProjectTextExtractor(currentProject);
                extractor.Progress += (s, p) => { worker.ReportProgress(p.PercentComplete); };
                IEnumerable <string> terms   = extractor.ExtractWords(); //ComponentFactory.CreateExtractor(inputType, textBox.Text, progress);
                IWordStemmer         stemmer = new NullStemmer();        //ComponentFactory.CreateWordStemmer(checkBoxGroupSameStemWords.Checked);

                IEnumerable <IWord> rawWords = terms
                                               .Filter(blacklist)
                                               .Filter(customBlacklist)
                                               .CountOccurences();
                List <IWord> words = rawWords
                                     .GroupByStem(stemmer)
                                     .SortByOccurences()
                                     .Cast <IWord>().ToList();

                cache.Save("sourcecloud", currentProject, words);
                e.Result = words;

                if (Project != null && currentProject.GetProjectInfo().Id == Project.GetProjectInfo().Id)
                {
                    Words = words;
                }
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (Project != null && currentProject.GetProjectInfo().Id == Project.GetProjectInfo().Id)
                {
                    WordCloudResult result = new WordCloudResult();
                    if (e.Error != null)
                    {
                        result.Exception = e.Error;
                    }
                    else
                    {
                        result.WeightedWords = (IEnumerable <IWord>)e.Result;
                    }

                    resultCallback(result);
                }
            };
            worker.ProgressChanged += (sender, e) => { progressCallback(e.ProgressPercentage); };
            worker.RunWorkerAsync();
        }