private void ButtonExportTopics_Click(object sender, RoutedEventArgs e) { ExpeditionDataSource eds = web_library_detail.Xlibrary?.ExpeditionManager?.ExpeditionDataSource; if (null != eds) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < eds.LDAAnalysis.NUM_TOPICS; ++i) { string topic_description = eds.GetDescriptionForTopic(i); sb.AppendFormat("{1}\r\n", i, topic_description); } string filename = TempFile.GenerateTempFilename("txt"); File.WriteAllText(filename, sb.ToString()); Process.Start(filename); } else { MessageBoxes.Error("You need to first run Expedition for this library."); } }
private void PopulateDetail(bool detailed_mode) { // Clear the old ObjHeader.Header = null; ObjHeader.ToolTip = null; ObjPapers.Children.Clear(); // Try to get the context TopicOverviewData tod = DataContext as TopicOverviewData; if (null == tod) { return; } // Quick refs ExpeditionDataSource eds = tod.web_library_detail.Xlibrary?.ExpeditionManager?.ExpeditionDataSource; if (null != eds) { LDAAnalysis lda_analysis = eds.LDAAnalysis; // First the terms header { string header = eds.GetDescriptionForTopic(tod.topic); ObjHeader.Header = header; ObjHeader.ToolTip = header; ObjHeader.HeaderBackground = new SolidColorBrush(eds.Colours[tod.topic]); } // Then the docs { int NUM_DOCS = Math.Min(detailed_mode ? 50 : 10, lda_analysis.NUM_DOCS); ASSERT.Test(tod.topic >= 0); ASSERT.Test(tod.topic < lda_analysis.NUM_TOPICS); for (int d = 0; d < NUM_DOCS && d < eds.docs.Count; ++d) { DocProbability[] docs = lda_analysis.DensityOfDocsInTopicsSorted[tod.topic]; ASSERT.Test(docs != null); ASSERT.Test(docs.Length == lda_analysis.NUM_DOCS); DocProbability lda_elem = docs[d]; ASSERT.Test(lda_elem != null); PDFDocument pdf_document = tod.web_library_detail.Xlibrary.GetDocumentByFingerprint(eds.docs[lda_elem.doc]); string doc_percentage = String.Format("{0:N0}%", 100 * lda_elem.prob); bool alternator = false; TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Features.Expedition_TopicDocument, TopicDocumentPressed_MouseButtonEventHandler, doc_percentage + " - "); ObjPapers.Children.Add(text_doc); } // The MORE button if (!detailed_mode && NUM_DOCS < eds.docs.Count) { AugmentedButton button_more = new AugmentedButton(); button_more.Caption = "Show me more"; button_more.Click += button_more_Click; ObjPapers.Children.Add(button_more); } // The BRAINSTORM button { AugmentedButton button_brainstorm = new AugmentedButton(); button_brainstorm.Caption = "Show me in Brainstorm"; button_brainstorm.Click += button_brainstorm_Click; button_brainstorm.Tag = tod; ObjPapers.Children.Add(button_brainstorm); } } } }
private void ExpeditionPaperThemesControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // Clear the old ObjSeriesTopics.DataSource = null; TxtPleaseRunExpedition.Visibility = Visibility.Visible; ChartTopics.Visibility = Visibility.Collapsed; AugmentedBindable <PDFDocument> pdf_document_bindable = DataContext as AugmentedBindable <PDFDocument>; if (null == pdf_document_bindable) { return; } PDFDocument pdf_document = pdf_document_bindable.Underlying; if (null == pdf_document.Library.ExpeditionManager.ExpeditionDataSource) { return; } ExpeditionDataSource eds = pdf_document.Library.ExpeditionManager.ExpeditionDataSource; LDAAnalysis lda_analysis = eds.LDAAnalysis; // Draw the pie chart { try { if (!eds.docs_index.ContainsKey(pdf_document.Fingerprint)) { return; } int doc_id = eds.docs_index[pdf_document.Fingerprint]; TopicProbability[] topics = lda_analysis.DensityOfTopicsInDocsSorted[doc_id]; int ITEMS_IN_CHART = Math.Min(topics.Length, 3); Brush[] brushes = new Brush[ITEMS_IN_CHART + 1]; List <ChartItem> chart_items = new List <ChartItem>(); double remaining_segment_percentage = 1.0; for (int t = 0; t < ITEMS_IN_CHART; ++t) { string topic_name = eds.GetDescriptionForTopic(topics[t].topic); double percentage = topics[t].prob; chart_items.Add(new ChartItem { Topic = topic_name, Percentage = percentage }); brushes[t] = new SolidColorBrush(eds.Colours[topics[t].topic]); remaining_segment_percentage -= percentage; } chart_items.Add(new ChartItem { Topic = "Others", Percentage = remaining_segment_percentage }); brushes[ITEMS_IN_CHART] = new SolidColorBrush(Colors.White); ObjChartTopicsArea.ColorModel.CustomPalette = brushes; ObjChartTopicsArea.ColorModel.Palette = ChartColorPalette.Custom; ObjSeriesTopics.DataSource = chart_items; // Silly ObjSeriesTopics.AnimationDuration = TimeSpan.FromMilliseconds(1000); ObjSeriesTopics.EnableAnimation = false; ObjSeriesTopics.AnimateOneByOne = true; ObjSeriesTopics.AnimateOption = AnimationOptions.Fade; ObjSeriesTopics.EnableAnimation = true; } catch (Exception ex) { Logging.Error(ex, "There was a problem while generating the topics chart for document {0}", pdf_document.Fingerprint); } } TxtPleaseRunExpedition.Visibility = Visibility.Collapsed; ChartTopics.Visibility = Visibility.Visible; }