// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        private void ApplyTagsDistribution(DistributionUseDelegate distribution_use)
        {
            // Get the distribution for the themes
            string tags = theme_node_content.Underlying.Tags;

            string[] tags_array = tags.Split('\n');

            string  library_fingerprint = theme_node_content.Underlying.library_fingerprint;
            Library library             = WebLibraryManager.Instance.GetLibrary(library_fingerprint);

            if (null == library)
            {
                Logging.Warn("Unable to locate library " + library_fingerprint);
                return;
            }

            if (null == library.ExpeditionManager || null == library.ExpeditionManager.ExpeditionDataSource)
            {
                Logging.Warn("Expedition has not been run for library '{0}'.", library.WebLibraryDetail.Title);
                return;
            }

            ExpeditionDataSource eds = library.ExpeditionManager.ExpeditionDataSource;

            float[] tags_distribution       = new float[eds.LDAAnalysis.NUM_TOPICS];
            int     tags_distribution_denom = 0;

            foreach (string tag in tags_array)
            {
                if (eds.words_index.ContainsKey(tag))
                {
                    ++tags_distribution_denom;

                    int tag_id = eds.words_index[tag];
                    for (int topic_i = 0; topic_i < eds.LDAAnalysis.NUM_TOPICS; ++topic_i)
                    {
                        tags_distribution[topic_i] += eds.LDAAnalysis.PseudoDensityOfTopicsInWords[tag_id, topic_i];
                    }
                }
                else
                {
                    Logging.Warn("Ignoring tag {0} which we don't recognise.", tag);
                }
            }

            if (0 < tags_distribution_denom)
            {
                // Normalise the tags distribution
                for (int topic_i = 0; topic_i < eds.LDAAnalysis.NUM_TOPICS; ++topic_i)
                {
                    tags_distribution[topic_i] /= tags_distribution_denom;
                }
            }

            distribution_use(node_control, library, eds, tags_distribution);
        }
Beispiel #2
0
        // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        private void ApplyTagsDistribution(DistributionUseDelegate distribution_use)
        {
            WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

            // Get the distribution for the themes
            string tags = theme_node_content.Underlying.Tags;

            string[] tags_array = tags.Split('\n');

            string library_fingerprint = theme_node_content.Underlying.library_fingerprint;

            SafeThreadPool.QueueUserWorkItem(o =>
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

                WebLibraryDetail web_library_detail = WebLibraryManager.Instance.GetLibrary(library_fingerprint);
                if (null == web_library_detail)
                {
                    Logging.Warn("Unable to locate library " + library_fingerprint);
                    return;
                }

                ExpeditionDataSource eds = web_library_detail.Xlibrary?.ExpeditionManager?.ExpeditionDataSource;
                if (null != eds)
                {
                    LDAAnalysis lda = eds.LDAAnalysis;

                    float[] tags_distribution   = new float[lda.NUM_TOPICS];
                    int tags_distribution_denom = 0;
                    foreach (string tag in tags_array)
                    {
                        if (eds.words_index.ContainsKey(tag))
                        {
                            ++tags_distribution_denom;

                            int tag_id = eds.words_index[tag];
                            for (int topic_i = 0; topic_i < lda.NUM_TOPICS; ++topic_i)
                            {
                                tags_distribution[topic_i] += lda.PseudoDensityOfTopicsInWords[tag_id, topic_i];
                            }
                        }
                        else
                        {
                            Logging.Warn("Ignoring tag {0} which we don't recognise.", tag);
                        }
                    }

                    if (0 < tags_distribution_denom)
                    {
                        // Normalise the tags distribution
                        for (int topic_i = 0; topic_i < lda.NUM_TOPICS; ++topic_i)
                        {
                            tags_distribution[topic_i] /= tags_distribution_denom;
                        }
                    }

                    distribution_use(node_control, web_library_detail, eds, tags_distribution);
                }
                else
                {
                    Logging.Warn("Expedition has not been run for library '{0}'.", web_library_detail.Title);
                }
            });
        }