protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFDocumentNodeContentControl::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.SafeExec(() =>
            {
                if (dispose_count == 0)
                {
                    library_index_hover_popup?.Dispose();
                }
                library_index_hover_popup = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                ToolTip = "";
            });

            WPFDoEvents.SafeExec(() =>
            {
                node_control = null;
                pdf_document_node_content = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                DataContextChanged -= PDFDocumentNodeContentControl_DataContextChanged;
                DataContext         = null;
            });

            ++dispose_count;
        }
示例#2
0
        public PDFDocumentNodeContentControl(NodeControl node_control, PDFDocumentNodeContent pdf_document_node_content)
        {
            InitializeComponent();

            this.node_control = node_control;
            this.pdf_document_node_content = pdf_document_node_content;

            this.DataContextChanged += PDFDocumentNodeContentControl_DataContextChanged;
            this.DataContext         = pdf_document_node_content.PDFDocument.Bindable;

            this.Focusable = true;

            this.ImageIcon.Source = Icons.GetAppIcon(Icons.BrainstormDocument);

            ImageIcon.Opacity       = 0.5;
            ImageIcon.Width         = NodeThemes.image_width;
            TextBorder.CornerRadius = NodeThemes.corner_radius;
            TextBorder.Background   = NodeThemes.background_brush;

            TextTitle.FontWeight      = FontWeights.Bold;
            TextPublication.FontStyle = FontStyles.Italic;

            this.MouseDoubleClick += DocumentNodeContentControl_MouseDoubleClick;
            this.ToolTip           = "";
            this.ToolTipClosing   += PDFDocumentNodeContentControl_ToolTipClosing;
            this.ToolTipOpening   += PDFDocumentNodeContentControl_ToolTipOpening;
        }
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFDocumentNodeContentControl::Dispose({0}) @{1}", disposing, dispose_count);

            try
            {
                // Get rid of managed resources
                if (dispose_count == 0)
                {
                    library_index_hover_popup?.Dispose();
                }
                library_index_hover_popup = null;

                ToolTip = "";

                node_control = null;
                pdf_document_node_content = null;

                DataContextChanged -= PDFDocumentNodeContentControl_DataContextChanged;
                DataContext         = null;
            }
            catch (Exception ex)
            {
                Logging.Error(ex);
            }

            ++dispose_count;
        }
示例#4
0
        private static void ExpandCitationsOutbound(PDFDocument doc, NodeControl node_control)
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_CitationsOutbound);
            ASSERT.Test(doc != null);

            if (doc != null)
            {
                List <Citation> citations = doc.PDFDocumentCitationManager.GetOutboundCitations();

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

                    foreach (var citation in citations)
                    {
                        // NB: We assume the citations are from the same library!!
                        PDFDocumentNodeContent content = new PDFDocumentNodeContent(citation.fingerprint_inbound, doc.LibraryRef.Id);
                        if (!content.PDFDocument.Deleted)
                        {
                            NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
                        }
                    }
                });
            }
        }
示例#5
0
        internal static void AddDocumentsSimilarToDistribution(NodeControl node_control_, WebLibraryDetail web_library_detail, ExpeditionDataSource eds, float[] tags_distribution)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            ASSERT.Test(eds != null);

            // Get the most similar PDFDocuments
            int[] doc_ids = LDAAnalysisTools.GetDocumentsSimilarToDistribution(eds.LDAAnalysis, tags_distribution);

            WPFDoEvents.InvokeInUIThread(() =>
            {
                WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

                for (int i = 0; i < 10 && i < doc_ids.Length; ++i)
                {
                    int doc_id         = doc_ids[i];
                    string fingerprint = eds.docs[doc_id];

                    PDFDocument pdf_document = web_library_detail.Xlibrary.GetDocumentByFingerprint(fingerprint);
                    if (null == pdf_document)
                    {
                        Logging.Warn("Couldn't find similar document with fingerprint {0}", fingerprint);
                    }
                    else
                    {
                        PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
                        NodeControlAddingByKeyboard.AddChildToNodeControl(node_control_, content, false);
                    }
                }
            });
        }
示例#6
0
        public void ExpandDocuments()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Tag_Documents);

            List <PDFDocument> pdf_documents = pdf_tag_node_content.Library.GetDocumentsByTag(pdf_tag_node_content.Tag);

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
                NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
            }
        }
示例#7
0
        private void ExpandRelevants()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_Similars);

            List <ExpeditionPaperSuggestions.Result> results = ExpeditionPaperSuggestions.GetRelevantOthers(pdf_document_node_content.PDFDocument, 10);

            foreach (ExpeditionPaperSuggestions.Result result in results)
            {
                PDFDocumentNodeContent content = new PDFDocumentNodeContent(result.pdf_document.Fingerprint, result.pdf_document.Library.WebLibraryDetail.Id);
                NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
            }
        }
示例#8
0
        private void ExpandDocuments()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Author_Documents);

            List <PDFDocument> pdf_documents = SimilarAuthors.GetDocumentsBySameAuthorsSurnameAndInitial(pdf_author_node_content.LibraryRef, pdf_author_node_content.Surname, pdf_author_node_content.Initial);

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
                NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
            }
        }
示例#9
0
        public void ExpandDocuments()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_AutoTag_Documents);

            WebLibraryDetail web_library_detail = WebLibraryManager.Instance.GetLibrary(pdf_auto_tag_node_content.LibraryId);

            HashSet <string>   document_fingerprints = web_library_detail.Xlibrary.AITagManager.AITags.GetDocumentsWithTag(pdf_auto_tag_node_content.Tag);
            List <PDFDocument> pdf_documents         = web_library_detail.Xlibrary.GetDocumentByFingerprints(document_fingerprints);

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
                NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
            }
        }
示例#10
0
        private void ExpandCitationsInbound()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_CitationsInbound);

            List <Citation> citations = pdf_document_node_content.PDFDocument.PDFDocumentCitationManager.GetInboundCitations();

            foreach (var citation in citations)
            {
                PDFDocumentNodeContent content = new PDFDocumentNodeContent(citation.fingerprint_outbound, pdf_document_node_content.PDFDocument.Library.WebLibraryDetail.Id);
                if (!content.PDFDocument.Deleted)
                {
                    NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
                }
            }
        }
示例#11
0
        public override bool Equals(object obj)
        {
            PDFDocumentNodeContent other = obj as PDFDocumentNodeContent;

            if (null == other)
            {
                return(false);
            }

            if (this.document_fingerprint != other.document_fingerprint)
            {
                return(false);
            }
            if (this.library_fingerprint != other.library_fingerprint)
            {
                return(false);
            }

            return(true);
        }
        internal static void AddDocumentsSimilarToDistribution(NodeControl node_control_, Library library, ExpeditionDataSource eds, float[] tags_distribution)
        {
            // Get the most similar PDFDocuments
            int[] doc_ids = LDAAnalysisTools.GetDocumentsSimilarToDistribution(eds.LDAAnalysis, tags_distribution);

            for (int i = 0; i < 10 && i < doc_ids.Length; ++i)
            {
                int    doc_id      = doc_ids[i];
                string fingerprint = eds.docs[doc_id];

                PDFDocument pdf_document = library.GetDocumentByFingerprint(fingerprint);
                if (null == pdf_document)
                {
                    Logging.Warn("Couldn't find similar document with fingerprint {0}", fingerprint);
                }
                else
                {
                    PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
                    NodeControlAddingByKeyboard.AddChildToNodeControl(node_control_, content, false);
                }
            }
        }
示例#13
0
        private static void ExpandRelevants(PDFDocument doc, NodeControl node_control)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            ASSERT.Test(doc != null);

            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_Similars);

            if (doc != null)
            {
                List <ExpeditionPaperSuggestions.Result> results = ExpeditionPaperSuggestions.GetRelevantOthers(doc, 10);

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

                    foreach (ExpeditionPaperSuggestions.Result result in results)
                    {
                        PDFDocumentNodeContent content = new PDFDocumentNodeContent(result.pdf_document.Fingerprint, result.pdf_document.LibraryRef.Id);
                        NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
                    }
                });
            }
        }
        internal static void AddDocumentsInfluentialInDistribution(NodeControl node_control_, Library library, ExpeditionDataSource eds, float[] tags_distribution)
        {
            Logging.Info("+Performing ThemedPageRank on {0} documents", eds.LDAAnalysis.NUM_DOCS);

            // We have the distribution of the topic in tags_distribution

            // Create an array for the document biases
            // Fill the array using the dot product of the document distribution dotted with the topic distribution - then normalise
            double[] biases = new double[eds.LDAAnalysis.NUM_DOCS];
            for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
            {
                double bias_num_squared = 0;
                double bias_den_doc     = 0;
                double bias_den_tags    = 0;

                for (int topic = 0; topic < eds.LDAAnalysis.NUM_TOPICS; ++topic)
                {
                    bias_num_squared += eds.LDAAnalysis.DensityOfTopicsInDocuments[doc, topic] * tags_distribution[topic];
                    bias_den_doc     += eds.LDAAnalysis.DensityOfTopicsInDocuments[doc, topic] * eds.LDAAnalysis.DensityOfTopicsInDocuments[doc, topic];
                    bias_den_tags    += tags_distribution[topic] * tags_distribution[topic];
                }

                biases[doc] = bias_num_squared / (Math.Sqrt(bias_den_doc) * Math.Sqrt(bias_den_tags));
            }

            // Then build up a matrix FROM each document -
            List <int>[] references_outbound = new List <int> [eds.LDAAnalysis.NUM_DOCS];
            for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
            {
                references_outbound[doc] = new List <int>();

                string      fingerprint  = eds.docs[doc];
                PDFDocument pdf_document = library.GetDocumentByFingerprint(fingerprint);
                if (null == pdf_document)
                {
                    Logging.Warn("ThemeExplorer::AddInInfluential: Cannot find document anymore for fingerprint {0}", fingerprint);
                }
                else
                {
                    List <Citation> citations_outbound = pdf_document.PDFDocumentCitationManager.GetOutboundCitations();
                    foreach (Citation citation in citations_outbound)
                    {
                        string fingerprint_inbound = citation.fingerprint_inbound;
                        if (eds.docs_index.ContainsKey(fingerprint_inbound))
                        {
                            int doc_inbound = eds.docs_index[fingerprint_inbound];
                            references_outbound[doc].Add(doc_inbound);
                        }
                    }
                }
            }

            // Space for the pageranks
            double[] pageranks_current = new double[eds.LDAAnalysis.NUM_DOCS];
            double[] pageranks_next    = new double[eds.LDAAnalysis.NUM_DOCS];

            // Initialise
            for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
            {
                pageranks_current[doc] = biases[doc];
            }

            // Iterate
            int NUM_ITERATIONS = 20;

            for (int iteration = 0; iteration < NUM_ITERATIONS; ++iteration)
            {
                Logging.Info("Performing ThemedPageRank iteration {0}", iteration);

                // Spread out the activation pageranks
                for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
                {
                    foreach (int doc_inbound in references_outbound[doc])
                    {
                        pageranks_next[doc_inbound] += biases[doc] / references_outbound[doc].Count;
                    }
                }

                // Mix the spread out pageranks with the initial bias pageranks
                double ALPHA = 0.5;
                for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
                {
                    pageranks_next[doc] = (1 - ALPHA) * pageranks_next[doc] + ALPHA * biases[doc];
                }

                // Normalise the next pageranks
                double total = 0;
                for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
                {
                    total += pageranks_next[doc];
                }
                if (0 < total)
                {
                    for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
                    {
                        pageranks_next[doc] /= total;
                    }
                }

                // Switch in the next pageranks because we will overwrite them
                double[] pageranks_temp = pageranks_current;
                pageranks_current = pageranks_next;
                pageranks_next    = pageranks_temp;
            }

            // Sort the pageranks, descending
            int[] docs = new int[eds.LDAAnalysis.NUM_DOCS];
            for (int doc = 0; doc < eds.LDAAnalysis.NUM_DOCS; ++doc)
            {
                docs[doc] = doc;
            }
            Array.Sort(pageranks_current, docs);
            Array.Reverse(pageranks_current);
            Array.Reverse(docs);

            // Make the nodes
            for (int doc = 0; doc < 10 && doc < docs.Length; ++doc)
            {
                int    doc_id      = docs[doc];
                string fingerprint = eds.docs[doc_id];

                PDFDocument pdf_document = library.GetDocumentByFingerprint(fingerprint);
                if (null == pdf_document)
                {
                    Logging.Warn("Couldn't find similar document with fingerprint {0}", fingerprint);
                }
                else
                {
                    PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
                    NodeControlAddingByKeyboard.AddChildToNodeControl(node_control_, content, false);
                }
            }
        }
        public PDFDocumentNodeEditorControl(NodeControl node_control, PDFDocumentNodeContent pdf_document_node_content)
        {
            InitializeComponent();

            ObjDocumentMetadataControlsPanel.DataContext = pdf_document_node_content.PDFDocument.Bindable;
        }