public PDFAnnotationNodeEditorControl(NodeControl node_control, PDFAnnotationNodeContent content)
 {
     InitializeComponent();
 }
Exemplo n.º 2
0
        public StringNodeContentEditor(NodeControl node_control, StringNodeContent string_node_content)
        {
            InitializeComponent();

            DataContext = string_node_content.Bindable;
        }
 public PDFTagNodeContentEditor(NodeControl node_control, PDFTagNodeContent pdf_tag_node_content)
 {
     InitializeComponent();
 }
        public PDFDocumentNodeEditorControl(NodeControl node_control, PDFDocumentNodeContent pdf_document_node_content)
        {
            InitializeComponent();

            ObjDocumentMetadataControlsPanel.DataContext = pdf_document_node_content.PDFDocument.Bindable;
        }
Exemplo n.º 5
0
        internal static void AddDocumentsInfluentialInDistribution(NodeControl node_control_, WebLibraryDetail web_library_detail, ExpeditionDataSource eds, float[] tags_distribution)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            ASSERT.Test(eds != null);

            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
            LDAAnalysis lda = eds.LDAAnalysis;

            float[,] density_of_topics_in_docs = lda.DensityOfTopicsInDocuments;

            double[] biases = new double[lda.NUM_DOCS];
            for (int doc = 0; doc < lda.NUM_DOCS; ++doc)
            {
                double bias_num_squared = 0;
                double bias_den_doc     = 0;
                double bias_den_tags    = 0;

                for (int topic = 0; topic < lda.NUM_TOPICS; ++topic)
                {
                    bias_num_squared += density_of_topics_in_docs[doc, topic] * tags_distribution[topic];
                    bias_den_doc     += density_of_topics_in_docs[doc, topic] * density_of_topics_in_docs[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> [lda.NUM_DOCS];
            for (int doc = 0; doc < lda.NUM_DOCS; ++doc)
            {
                references_outbound[doc] = new List <int>();

                string      fingerprint  = eds.docs[doc];
                PDFDocument pdf_document = web_library_detail.Xlibrary.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[lda.NUM_DOCS];
            double[] pageranks_next    = new double[lda.NUM_DOCS];

            // Initialise
            for (int doc = 0; doc < lda.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 < lda.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 < lda.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 < lda.NUM_DOCS; ++doc)
                {
                    total += pageranks_next[doc];
                }
                if (0 < total)
                {
                    for (int doc = 0; doc < lda.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[lda.NUM_DOCS];
            for (int doc = 0; doc < lda.NUM_DOCS; ++doc)
            {
                docs[doc] = doc;
            }
            Array.Sort(pageranks_current, docs);
            Array.Reverse(pageranks_current);
            Array.Reverse(docs);

            WPFDoEvents.InvokeInUIThread(() =>
            {
                // 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 = 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);
                    }
                }
            });
        }