private void ReSearch()
        {
            int MAX_DOCUMENTS = 20;

            ObjPDFDocuments.ItemsSource = null;

            if (null != web_library_detail)
            {
                string query = TxtSearchTerms.Text;
                if (!String.IsNullOrEmpty(query))
                {
                    List <IndexResult> matches     = web_library_detail.library.LibraryIndex.GetFingerprintsForQuery(query);
                    List <TextBlock>   text_blocks = new List <TextBlock>();
                    bool alternator = false;
                    for (int i = 0; i < MAX_DOCUMENTS && i < matches.Count; ++i)
                    {
                        PDFDocument pdf_document = web_library_detail.library.GetDocumentByFingerprint(matches[i].fingerprint);
                        if (null == pdf_document || pdf_document.Deleted)
                        {
                            continue;
                        }

                        string    prefix     = String.Format("{0:0%} - ", matches[i].score);
                        TextBlock text_block = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, null, VOID_MouseButtonEventHandler, prefix, null);
                        text_blocks.Add(text_block);
                    }

                    ObjPDFDocuments.ItemsSource = text_blocks;
                    if (0 < text_blocks.Count)
                    {
                        ObjPDFDocuments.SelectedIndex = 0;
                    }
                }
            }
        }
Exemple #2
0
        void ApplyNewSearch()
        {
            ObjDocumentsPanel.Children.Clear();

            WebLibraryDetail web_library_detail = ObjLibraryPicker.WebLibraryDetail;

            if (null != web_library_detail)
            {
                string query = ObjSearchFilter.Text;
                if (!String.IsNullOrEmpty(query))
                {
                    HashSet <string>   fingerprints  = web_library_detail.library.GetDocumentFingerprintsWithKeyword(query);
                    List <PDFDocument> pdf_documents = web_library_detail.library.GetDocumentByFingerprints(fingerprints);

                    List <PDFDocument> pdf_documents_sorted = new List <PDFDocument>(pdf_documents.OrderBy(x => x.TitleCombined));
                    bool alternator = false;
                    foreach (PDFDocument pdf_document in pdf_documents_sorted)
                    {
                        TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Feature, OnDocumentClicked);
                        ObjDocumentsPanel.Children.Add(text_doc);
                    }

                    // If the panel is empty, put NONE
                    if (0 == ObjDocumentsPanel.Children.Count)
                    {
                        TextBlock text_doc = new TextBlock();
                        text_doc.Text = "(none)";
                        ObjDocumentsPanel.Children.Add(text_doc);
                    }
                }
            }
        }
        public void SetItems(MultiMap <string, PDFDocument> items)
        {
            // Clear our items
            PanelItems.Children.Clear();

            bool alternator = false;

            foreach (string author in items.Keys)
            {
                TextBlock text_author = new TextBlock();
                text_author.ToolTip = text_author.Text = author;

                text_author.FontWeight = FontWeights.Bold;
                PanelItems.Children.Add(text_author);

                List <PDFDocument> pdf_documents_sorted = new List <PDFDocument>(items.Get(author).OrderBy(x => x.YearCombined));
                foreach (PDFDocument pdf_document in pdf_documents_sorted)
                {
                    TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Features.SimilarAuthor_OpenDoc);
                    PanelItems.Children.Add(text_doc);
                }
            }

            if (0 == PanelItems.Children.Count)
            {
                TextBlock text_doc = new TextBlock();
                text_doc.Text = "None in this library.";
                PanelItems.Children.Add(text_doc);
            }
        }
Exemple #4
0
        private void AttachEvents(TreeViewItem tvi, PDFDocument pdf_document)
        {
            string prefix =
                pdf_document.ReadingStage
                + " - "
                + (String.IsNullOrEmpty(pdf_document.BibTex) ? "NoBibTeX" : "HasBibTeX")
                + " - "
                + (!pdf_document.DocumentExists ? "NoPDF" : "HasPDF")
                + " - "
            ;

            tvi.Header              = ListFormattingTools.GetPDFDocumentDescription(pdf_document, prefix);
            tvi.Tag                 = pdf_document;
            tvi.MouseRightButtonUp += tvi_MouseRightButtonUp;
        }
        private void word_connector_ContextChanged_BACKGROUND_PopulateRecommendations(List <PDFDocument> context_pdf_documents)
        {
            // Out with the old...
            ObjRecommendedCitationsList.Children.Clear();

            // In with the new
            bool added_recommendation = false;
            bool alternator           = false;

            foreach (PDFDocument pdf_document in context_pdf_documents)
            {
                added_recommendation = true;

                TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, null, RecommendedCitationsMouseDown);
                ObjRecommendedCitationsList.Children.Add(text_doc);
            }

            ObjGridNoRecommendationsInstructions.Visibility = added_recommendation ? Visibility.Collapsed : Visibility.Visible;
        }
        private void RenderDuplicates(List <PDFDocument> duplicate_pdf_documents)
        {
            bool alternator = false;

            foreach (PDFDocument duplicate_pdf_document in duplicate_pdf_documents)
            {
                TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(duplicate_pdf_document, ref alternator, Features.DuplicateDetection_OpenDoc);
                DocsPanel.Children.Add(text_doc);
            }

            // If the panel is empty, put NONE
            if (0 == DocsPanel.Children.Count)
            {
                DocsPanel.Visibility = Visibility.Collapsed;
            }
            else
            {
                DocsPanel.Visibility = Visibility.Visible;
            }
        }
Exemple #7
0
        private void ReSearch(PDFDocument doc, string query)
        {
            int MAX_DOCUMENTS = 20;

            if (null == doc)
            {
                return;
            }

            if (!String.IsNullOrEmpty(query))
            {
                List <IndexResult> matches = doc.LibraryRef.Xlibrary.LibraryIndex.GetFingerprintsForQuery(query);

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    List <TextBlock> text_blocks = new List <TextBlock>();
                    bool alternator = false;
                    for (int i = 0; i < MAX_DOCUMENTS && i < matches.Count; ++i)
                    {
                        PDFDocument pdf_document = doc.LibraryRef.Xlibrary.GetDocumentByFingerprint(matches[i].fingerprint);
                        if (null == pdf_document || pdf_document.Deleted)
                        {
                            continue;
                        }

                        string prefix        = String.Format("{0:0%} - ", matches[i].score);
                        TextBlock text_block = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, null, MouseButtonEventHandler, prefix, null);
                        text_blocks.Add(text_block);
                    }

                    ObjPDFDocuments.ItemsSource = text_blocks;
                    if (0 < text_blocks.Count)
                    {
                        ObjPDFDocuments.SelectedIndex = 0;
                    }
                });
            }
        }
        void ExpeditionPaperSimilarsControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // Clear the old
            ObjPapers.Children.Clear();
            TxtPleaseRunExpedition.Visibility = Visibility.Visible;

            AugmentedBindable <PDFDocument> pdf_document_bindable = DataContext as AugmentedBindable <PDFDocument>;

            if (null == pdf_document_bindable)
            {
                return;
            }

            PDFDocument pdf_document = pdf_document_bindable.Underlying;
            List <ExpeditionPaperSuggestions.Result> results = ExpeditionPaperSuggestions.GetRelevantOthers(pdf_document, NumberOfRelevantPapersToDisplay);

            foreach (ExpeditionPaperSuggestions.Result result in results)
            {
                // Do we have specific event handling logic?
                MouseButtonEventHandler mouse_down_event_handler = null;
                if (null != PDFDocumentSelected)
                {
                    mouse_down_event_handler = DocumentDocumentPressed_MouseButtonEventHandler;
                }

                string doc_percentage = String.Format("{0:N0}%", 100 * result.relevance);

                bool      alternator = false;
                TextBlock text_doc   =
                    ShowRelevancePercentage
                        ? ListFormattingTools.GetDocumentTextBlock(result.pdf_document, ref alternator, Features.Expedition_TopicDocument, mouse_down_event_handler, doc_percentage + " - ")
                        : ListFormattingTools.GetDocumentTextBlock(result.pdf_document, ref alternator, Features.Expedition_TopicDocument, mouse_down_event_handler, null);
                ObjPapers.Children.Add(text_doc);
            }

            TxtPleaseRunExpedition.Visibility = Visibility.Collapsed;
        }
        internal static void PopulatePanelWithCitations(StackPanel panel, PDFDocument parent_pdf_document, List <Citation> citations, Feature feature, string prefix = "", bool should_add_none_indicator = true)
        {
            string           fingerprint_parent = parent_pdf_document.Fingerprint;
            WebLibraryDetail web_library_detail = parent_pdf_document.LibraryRef;

            panel.Children.Clear();

            List <PDFDocument> pdf_documents = new List <PDFDocument>();

            foreach (var citation in citations)
            {
                string fingerprint = null;
                if (0 != fingerprint_parent.CompareTo(citation.fingerprint_inbound))
                {
                    fingerprint = citation.fingerprint_inbound;
                }
                if (0 != fingerprint_parent.CompareTo(citation.fingerprint_outbound))
                {
                    fingerprint = citation.fingerprint_outbound;
                }

                if (null == fingerprint)
                {
                    continue;
                }

                PDFDocument pdf_document = web_library_detail.Xlibrary.GetDocumentByFingerprint(fingerprint);

                if (null == pdf_document)
                {
                    continue;
                }

                if (pdf_document.Deleted)
                {
                    continue;
                }

                pdf_documents.Add(pdf_document);
            }

            List <PDFDocument> pdf_documents_sorted = new List <PDFDocument>(pdf_documents.OrderBy(x => x.YearCombined));
            bool alternator = false;

            foreach (PDFDocument pdf_document in pdf_documents_sorted)
            {
                TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Features.Citations_OpenDoc, null, prefix);
                panel.Children.Add(text_doc);
            }

            // If the panel is empty, put NONE
            if (should_add_none_indicator)
            {
                if (0 == pdf_documents_sorted.Count)
                {
                    TextBlock text_doc = new TextBlock();
                    text_doc.Text = "(none)";
                    panel.Children.Add(text_doc);
                }
            }
        }
        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);
                    }
                }
            }
        }
Exemple #11
0
        public void SpecifyPaperSet(GoogleScholarScrapePaperSet gssps)
        {
            DocsPanel.Children.Clear();

            {
                // Add the header
                StackPanel         sp    = new StackPanel();
                HyperlinkTextBlock tb_gs = new HyperlinkTextBlock();
                tb_gs.HorizontalAlignment = HorizontalAlignment.Center;
                tb_gs.Text       = "Go to GoogleScholar";
                tb_gs.FontWeight = FontWeights.Bold;
                tb_gs.Tag        = gssps.Url;
                tb_gs.OnClick   += OpenUrlInTagOfTextBlock;
                sp.Children.Add(tb_gs);
                DocsPanel.Children.Add(sp);
                DocsPanel.Children.Add(new AugmentedSpacer());
            }

            bool alternate = false;

            foreach (var gssp in gssps.Papers)
            {
                StackPanel sp = new StackPanel();

                try
                {
                    string html = gssp.abstract_html;
                    html = html.Replace("<br>", " ");
                    string       xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true);
                    FlowDocument fd   = (FlowDocument)XamlReader.Parse(xaml);
                    RichTextBox  rtb  = new RichTextBox(fd);
                    rtb.Width  = 320;
                    rtb.Height = 200;
                    sp.ToolTip = rtb;
                }
                catch (Exception ex)
                {
                    Logging.Warn(ex, "Problem parsing GS HTML abstract");
                }

                if (null != gssp.source_url)
                {
                    HyperlinkTextBlock tb_title = new HyperlinkTextBlock();
                    tb_title.Text     = gssp.title;
                    tb_title.Tag      = gssp.source_url;
                    tb_title.OnClick += OpenUrlInTagOfTextBlock;
                    sp.Children.Add(tb_title);
                }
                else
                {
                    TextBlock tb_title = new TextBlock();
                    tb_title.Text       = gssp.title;
                    tb_title.FontWeight = FontWeights.Bold;
                    sp.Children.Add(tb_title);
                }

                TextBlock tb_authors = new TextBlock();
                tb_authors.Text = gssp.authors;
                sp.Children.Add(tb_authors);

                TextBlock tb_citedby = new TextBlock();
                tb_citedby.Text = gssp.cited_by_header;
                sp.Children.Add(tb_citedby);

                if (0 < DocsPanel.Children.Count)
                {
                    DocsPanel.Children.Add(new AugmentedSpacer());
                }

                alternate = !alternate;
                ListFormattingTools.AddGlowingHoverEffect(sp);

                DocsPanel.Children.Add(sp);
            }
        }
Exemple #12
0
        private void Refresh_BACKGROUND(WebLibraryDetail primary_library)
        {
            StatusManager.Instance.UpdateStatus("UsedCitations", "Finding used citations...");

            try
            {
                // Get the citations from Word
                List <CitationCluster> citation_clusters = WordConnector.Instance.GetAllCitationClustersFromCurrentDocument();
                Dictionary <string, CSLProcessorBibTeXFinder.MatchingBibTeXRecord> bitex_items = CSLProcessorBibTeXFinder.Find(citation_clusters, primary_library);

                // Catalogue the citations
                List <UsedCitation>    used_citations    = new List <UsedCitation>();
                List <MissingCitation> missing_citations = new List <MissingCitation>();
                foreach (CitationCluster citation_cluster in citation_clusters)
                {
                    foreach (CitationItem citation_item in citation_cluster.citation_items)
                    {
                        CSLProcessorBibTeXFinder.MatchingBibTeXRecord bibtex_record = bitex_items[citation_item.reference_key];
                        if (null != bibtex_record)
                        {
                            PDFDocument pdf_document = bibtex_record.pdf_document;
                            used_citations.Add(new UsedCitation {
                                citation_cluster = citation_cluster, citation_item = citation_item, pdf_document = pdf_document
                            });
                        }
                        else
                        {
                            missing_citations.Add(new MissingCitation {
                                citation_cluster = citation_cluster, citation_item = citation_item
                            });
                        }
                    }
                }

                // Sort them by author
                used_citations.Sort(delegate(UsedCitation p1, UsedCitation p2)
                {
                    return(String.Compare(p1.pdf_document.AuthorsCombined, p2.pdf_document.AuthorsCombined));
                });

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    // Store them for the GUI
                    latest_used_citations    = used_citations;
                    latest_missing_citations = missing_citations;

                    // First set the used citations
                    List <PDFDocument> pdf_documents = new List <PDFDocument>();
                    used_citations.ForEach(o => pdf_documents.Add(o.pdf_document));
                    ObjUsedCitationsCatalog.SetPDFDocuments(pdf_documents);

                    // Then set the missing citations
                    ObjMissingCitationsList.Children.Clear();
                    foreach (MissingCitation missing_citation in missing_citations)
                    {
                        TextBlock text_doc  = new TextBlock();
                        text_doc.Text       = missing_citation.citation_item.reference_key;
                        text_doc.Tag        = missing_citation;
                        text_doc.MouseDown += text_doc_MouseDown;
                        ListFormattingTools.AddGlowingHoverEffect(text_doc);

                        ObjMissingCitationsList.Children.Add(text_doc);
                    }

                    // Only show the missing area if we have missing items...
                    ObjGridMissingCitations.Visibility = (0 < missing_citations.Count) ? Visibility.Visible : Visibility.Collapsed;
                });
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was an exception while looking for used citations.");
                MessageBoxes.Error("There was a problem while looking for used citations.  Are you sure Word is running?");
            }

            StatusManager.Instance.UpdateStatus("UsedCitations", "Found used citations");
        }