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

        internal static MultiMapSet <string, string> GetNodeItems(Library library, HashSet <string> parent_fingerprints)
        {
            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                // The category of year
                tags_with_fingerprints.Add(GetYearCategory(pdf_document), pdf_document.Fingerprint);

                // The year itself
                string year_combined = pdf_document.YearCombined;
                if (PDFDocument.UNKNOWN_YEAR != year_combined)
                {
                    tags_with_fingerprints.Add(year_combined, pdf_document.Fingerprint);
                }
            }

            return(tags_with_fingerprints);
        }
Ejemplo n.º 2
0
        // -----------------------------

        internal static MultiMapSet <string, string> GetNodeItems(Library library, HashSet <string> parent_fingerprints)
        {
            Logging.Info("+Getting node items for " + "Authors");

            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                List <NameTools.Name> names = SimilarAuthors.GetAuthorsForPDFDocument(pdf_document);
                foreach (NameTools.Name name in names)
                {
                    tags_with_fingerprints.Add(name.last_name, pdf_document.Fingerprint);
                }
            }

            Logging.Info("-Getting node items");
            return(tags_with_fingerprints);
        }
Ejemplo n.º 3
0
        // -----------------------------

        internal static MultiMapSet <string, string> GetNodeItems(Library library, HashSet <string> parent_fingerprints)
        {
            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                string type = null;
                if (null != pdf_document.BibTexItem)
                {
                    type = pdf_document.BibTexItem.Type;
                }

                tags_with_fingerprints.Add(type ?? "(none)", pdf_document.Fingerprint);
            }

            return(tags_with_fingerprints);
        }
        public static void Test2()
        {
            Library library = WebLibraryManager.Instance.Library_Guest;

            while (!library.LibraryIsLoaded)
            {
                Thread.Sleep(100);
            }

            List <PDFDocument> pdf_documents = library.PDFDocuments;

            HashSet <string>             parent_fingerprints = null;
            MultiMapSet <string, string> map_ratings         = RatingExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_reading_stage   = ReadingStageExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_author          = AuthorExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_year            = YearExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_ai_tag          = AITagExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_tag             = TagExplorerControl.GetNodeItems(library, parent_fingerprints);
            MultiMapSet <string, string> map_publication     = PublicationExplorerControl.GetNodeItems(library, parent_fingerprints);

            MultiMapSet <string, string> map_y_axis = map_tag;
            MultiMapSet <string, string> map_x_axis = map_author;

            PivotResult pivot_result = GeneratePivot(map_y_axis, map_x_axis);
        }
        private void PopulateChart(MultiMapSet <string, string> tags_with_fingerprints)
        {
            int N = 20;

            List <KeyValuePair <string, HashSet <string> > > top_n = tags_with_fingerprints.GetTopN(N);

            List <ChartItem> chart_items = new List <ChartItem>();

            for (int i = 0; i < top_n.Count; ++i)
            {
                if ("(none)" != top_n[i].Key && "<Untagged>" != top_n[i].Key)
                {
                    chart_items.Add(
                        new ChartItem
                    {
                        X       = i,
                        Caption = top_n[i].Key,
                        Count   = top_n[i].Value.Count
                    }
                        );
                }
            }

            ChartSearchTerms.ToolTip = String.Format("Top {0} {1} in your library.", N, description_title);
            ObjChartArea.PrimaryAxis.AxisVisibility   = Visibility.Collapsed;
            ObjChartArea.SecondaryAxis.AxisVisibility = Visibility.Collapsed;

            ObjSeries.DataSource    = chart_items;
            ObjSeries.BindingPathX  = "ID";
            ObjSeries.BindingPathsY = new string[] { "Count" };
        }
Ejemplo n.º 6
0
        public void MultiMapSet_duplicates()
        {
            var personnesParVille = new MultiMapSet <string, string>();

            //Lookup<string, string> personnesParVille = (Lookup<string, string>)new List<Person>().ToLookup(k => k.Ville, v => v.Nom);
            personnesParVille.Add("Paris", "Arthur");
            personnesParVille.Add("Paris", "Arthur");
            personnesParVille.Add("Paris", "Laurent");
            personnesParVille.Add("Paris", "David");
            personnesParVille.Add("Versailles", "Arthur");
            Check.That(personnesParVille.Count).IsEqualTo(2);
            Check.That(personnesParVille["Paris"].Count).IsEqualTo(3);
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(1);

            personnesParVille.Add("Versailles", "Arthur");
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(1);
            Check.That(personnesParVille.Count).IsEqualTo(2);

            personnesParVille.Add("Versailles", "Annabelle");
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(2);
            Check.That(personnesParVille.Count).IsEqualTo(2);

            personnesParVille.Add("Aix", "Françoise");
            Check.That(personnesParVille.Count).IsEqualTo(3);
            Check.That(personnesParVille["Aix"].Count).IsEqualTo(1);
        }
        public static PivotResult GeneratePivot(MultiMapSet <string, string> map_y_axis, MultiMapSet <string, string> map_x_axis)
        {
            List <string> y_keys = new List <string>(map_y_axis.Keys);
            List <string> x_keys = new List <string>(map_x_axis.Keys);

            y_keys.Sort();
            x_keys.Sort();

            List <string>[,] common_fingerprints = new List <string> [y_keys.Count, x_keys.Count];

            StatusManager.Instance.ClearCancelled("LibraryPivot");
            int y_progress = 0;

            Parallel.For(0, y_keys.Count, (y, loop_state) =>
                         //for (int y = 0; y < y_keys.Count; ++y)
            {
                int y_progress_locked = Interlocked.Increment(ref y_progress);

                if (General.HasPercentageJustTicked(y_progress_locked, y_keys.Count))
                {
                    StatusManager.Instance.UpdateStatusBusy("LibraryPivot", "Building library pivot", y_progress_locked, y_keys.Count, true);

                    WPFDoEvents.WaitForUIThreadActivityDone(); // HackityHack

                    if (StatusManager.Instance.IsCancelled("LibraryPivot"))
                    {
                        Logging.Warn("User cancelled library pivot generation");
                        loop_state.Break();
                    }
                }

                string y_key = y_keys[y];
                HashSet <string> y_values = map_y_axis.Get(y_key);

                for (int x = 0; x < x_keys.Count; ++x)
                {
                    string x_key = x_keys[x];
                    HashSet <string> x_values = map_x_axis.Get(x_key);

                    var common_fingerprint = y_values.Intersect(x_values);
                    if (common_fingerprint.Any())
                    {
                        common_fingerprints[y, x] = new List <string>(common_fingerprint);
                    }
                }
            });

            StatusManager.Instance.UpdateStatus("LibraryPivot", "Built library pivot");

            PivotResult pivot_result = new PivotResult();

            pivot_result.y_keys = y_keys;
            pivot_result.x_keys = x_keys;
            pivot_result.common_fingerprints = common_fingerprints;
            return(pivot_result);
        }
        // -----------------------------

        internal static MultiMapSet <string, string> GetNodeItems(Library library, HashSet <string> parent_fingerprints)
        {
            Logging.Info("+Getting node items for " + "Tags");

            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }

            // Load all the annotations upfront so we dont have to go to the database for each PDF
            Dictionary <string, byte[]> library_items_annotations_cache = library.LibraryDB.GetLibraryItemsAsCache(PDFDocumentFileLocations.ANNOTATIONS);

            // Build up the map of PDFs associated with each tag
            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                bool has_tag = false;
                foreach (string tag in TagTools.ConvertTagBundleToTags(pdf_document.Tags))
                {
                    tags_with_fingerprints.Add(tag, pdf_document.Fingerprint);
                    has_tag = true;
                }

                // And check the annotations
                foreach (var pdf_annotation in pdf_document.GetAnnotations(library_items_annotations_cache))
                {
                    if (!pdf_annotation.Deleted)
                    {
                        foreach (string annotation_tag in TagTools.ConvertTagBundleToTags(pdf_annotation.Tags))
                        {
                            tags_with_fingerprints.Add(annotation_tag, pdf_document.Fingerprint);
                            has_tag = true;
                        }
                    }
                }


                if (!has_tag)
                {
                    tags_with_fingerprints.Add(NO_TAG_KEY, pdf_document.Fingerprint);
                }
            }

            Logging.Info("-Getting node items");
            return(tags_with_fingerprints);
        }
        void CmdExport_Click(object sender, RoutedEventArgs e)
        {
            DateTime start_time = DateTime.Now;

            MultiMapSet <string, string> tags_with_fingerprints_ALL = GetNodeItems(this.library, null);
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("------------------------------------------------------------------------");
            sb.AppendFormat("{0} report\r\n", this.description_title);
            sb.AppendLine("------------------------------------------------------------------------");
            sb.AppendLine("Generated by Qiqqa (http://www.qiqqa.com)");
            sb.AppendLine(String.Format("On {0} {1}", start_time.ToLongDateString(), start_time.ToLongTimeString()));
            sb.AppendLine("------------------------------------------------------------------------");

            {
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendFormat("{0}:\r\n", this.description_title);
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendLine();

                foreach (var pair in tags_with_fingerprints_ALL)
                {
                    sb.AppendLine(pair.Key);
                }
            }

            {
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendFormat("{0} with associated fingerprints:\r\n", this.description_title);
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendLine();
                foreach (var pair in tags_with_fingerprints_ALL)
                {
                    foreach (var value in pair.Value)
                    {
                        sb.AppendFormat("{0}\t{1}\r\n", pair.Key, value);
                    }
                }
            }

            string filename = TempFile.GenerateTempFilename("txt");

            File.WriteAllText(filename, sb.ToString());
            Process.Start(filename);
        }
Ejemplo n.º 10
0
        private void CmdExport_Click(object sender, RoutedEventArgs e)
        {
            SafeThreadPool.QueueUserWorkItem(o =>
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

                DateTime start_time = DateTime.Now;

                MultiMapSet <string, string> tags_with_fingerprints_ALL = GetNodeItems(web_library_detail, null);
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendFormat("{0} report\r\n", description_title);
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendLine("Generated by Qiqqa (http://www.qiqqa.com)");
                sb.AppendLine(String.Format("On {0} {1}", start_time.ToLongDateString(), start_time.ToLongTimeString()));
                sb.AppendLine("------------------------------------------------------------------------");

                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendFormat("{0}:\r\n", description_title);
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendLine();

                foreach (var pair in tags_with_fingerprints_ALL)
                {
                    sb.AppendLine(pair.Key);
                }

                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendFormat("{0} with associated fingerprints:\r\n", description_title);
                sb.AppendLine("------------------------------------------------------------------------");
                sb.AppendLine();
                foreach (var pair in tags_with_fingerprints_ALL)
                {
                    foreach (var value in pair.Value)
                    {
                        sb.AppendFormat("{0}\t{1}\r\n", pair.Key, value);
                    }
                }

                string filename = TempFile.GenerateTempFilename("txt");
                File.WriteAllText(filename, sb.ToString());
                Process.Start(filename);
            });
        }
        // -----------------------------

        MultiMapSet <string, string> GetNodeItems(Library library, HashSet <string> parent_fingerprints)
        {
            MultiMapSet <string, string> results = GetNodeItems_STATIC(library, parent_fingerprints);

            // Show the no themes message
            {
                bool have_topics =
                    true &&
                    null != library.ExpeditionManager &&
                    null != library.ExpeditionManager.ExpeditionDataSource &&
                    0 < library.ExpeditionManager.ExpeditionDataSource.LDAAnalysis.NUM_TOPICS
                ;

                TxtNoThemesMessage.Visibility = 0 == results.Count ? Visibility.Visible : Visibility.Collapsed;
            }

            return(results);
        }
        private static MultiMapSet <string, string> GenerateMap_None(Library library, HashSet <string> parent_fingerprints)
        {
            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                tags_with_fingerprints.Add("All", pdf_document.Fingerprint);
            }
            return(tags_with_fingerprints);
        }
        private static MultiMapSet <string, string> GenerateMap_None(Library library, HashSet <string> parent_fingerprints)
        {
            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = library.PDFDocuments;
            }
            else
            {
                pdf_documents = library.GetDocumentByFingerprints(parent_fingerprints);
            }
            Logging.Debug特("LibraryPivotExplorerControl: processing {0} documents from library {1}", pdf_documents.Count, library.WebLibraryDetail.Title);

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                tags_with_fingerprints.Add("All", pdf_document.Fingerprint);
            }
            return(tags_with_fingerprints);
        }
Ejemplo n.º 14
0
        public void LogErrorCheckResult()
        {
            MultiMapSet <string, string> dict = Check();

            if (dict.Count == 0)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("not reset field:\n");
            foreach (KeyValuePair <string, HashSet <string> > pair in dict.GetDictionary())
            {
                sb.Append(pair.Key + ": ");
                foreach (string value in pair.Value)
                {
                    sb.Append(value + ", ");
                }
                sb.Append("\n");
            }
            Log.Error(sb.ToString());
        }
        public static MultiMapSet <string, string> GetNodeItems_STATIC(Library library, HashSet <string> parent_fingerprints)
        {
            MultiMapSet <string, string> results = new MultiMapSet <string, string>();

            try
            {
                // Check that expedition has been run...
                if (null == library.ExpeditionManager || null == library.ExpeditionManager.ExpeditionDataSource)
                {
                    return(results);
                }

                ExpeditionDataSource eds = library.ExpeditionManager.ExpeditionDataSource;
                for (int t = 0; t < eds.LDAAnalysis.NUM_TOPICS; ++t)
                {
                    string topic_name = eds.GetDescriptionForTopic(t, false, "; ");

                    // Show the top % of docs
                    int num_docs = eds.LDAAnalysis.NUM_DOCS / 10;
                    num_docs = Math.Max(num_docs, 3);

                    for (int d = 0; d < eds.LDAAnalysis.NUM_DOCS && d < num_docs; ++d)
                    {
                        PDFDocument pdf_document = library.GetDocumentByFingerprint(eds.docs[eds.LDAAnalysis.DensityOfDocsInTopicsSorted[t][d].doc]);
                        if (null == parent_fingerprints || parent_fingerprints.Contains(pdf_document.Fingerprint))
                        {
                            results.Add(topic_name, pdf_document.Fingerprint);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem while loading the themes for the library explorer.");
            }

            return(results);
        }
Ejemplo n.º 16
0
        public override string ToString()
        {
            StringBuilder          sb        = new StringBuilder();
            Dictionary <Type, int> typeCount = new Dictionary <Type, int>();

            foreach (var kv in this.dictionary)
            {
                typeCount[kv.Key] = kv.Value.Count;
            }

            IOrderedEnumerable <KeyValuePair <Type, int> > orderByDescending = typeCount.OrderByDescending(s => s.Value);

            sb.AppendLine("ObjectPool Count: ");
            foreach (var kv in orderByDescending)
            {
                if (kv.Value == 1)
                {
                    continue;
                }
                sb.AppendLine($"\t{kv.Key.Name}: {kv.Value}");
            }

            MultiMapSet <string, string> dict = Check();

            sb.Append("not reset field:\n");
            foreach (KeyValuePair <string, HashSet <string> > pair in dict.GetDictionary())
            {
                sb.Append(pair.Key + ": ");
                foreach (string value in pair.Value)
                {
                    sb.Append(value + ", ");
                }
                sb.Append("\n");
            }

            return(sb.ToString());
        }
Ejemplo n.º 17
0
        public MultiMapSet <string, string> GetTagsWithDocuments(HashSet <string> documents)
        {
            HashSet <string> relevant_tags = new HashSet <string>();

            foreach (string document in documents)
            {
                relevant_tags.UnionWith(ai_documents_with_tags.Get(document));
            }

            MultiMapSet <string, string> results = new MultiMapSet <string, string>();

            foreach (string relevant_tag in relevant_tags)
            {
                foreach (string relevant_document in ai_tags_with_documents.Get(relevant_tag))
                {
                    if (documents.Contains(relevant_document))
                    {
                        results.Add(relevant_tag, relevant_document);
                    }
                }
            }

            return(results);
        }
Ejemplo n.º 18
0
        private static MultiMapSet <string, string> GenerateMap_None(WebLibraryDetail web_library_detail, HashSet <string> parent_fingerprints)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            List <PDFDocument> pdf_documents = null;

            if (null == parent_fingerprints)
            {
                pdf_documents = web_library_detail.Xlibrary.PDFDocuments;
            }
            else
            {
                pdf_documents = web_library_detail.Xlibrary.GetDocumentByFingerprints(parent_fingerprints);
            }
            Logging.Debug特("LibraryPivotExplorerControl: processing {0} documents from library {1}", pdf_documents.Count, web_library_detail.Title);

            MultiMapSet <string, string> tags_with_fingerprints = new MultiMapSet <string, string>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                tags_with_fingerprints.Add("All", pdf_document.Fingerprint);
            }
            return(tags_with_fingerprints);
        }
Ejemplo n.º 19
0
        public MultiMapSet <string, string> Check()
        {
            MultiMapSet <string, string> dict = new MultiMapSet <string, string>();

            foreach (ComponentQueue queue in this.dictionary.Values)
            {
                foreach (Entity entity in queue.Queue)
                {
                    Type type = entity.GetType();

#if SERVER
                    if (type.IsSubclassOf(typeof(LogDefine)))
                    {
                        continue;
                    }
#endif

                    FieldInfo[] fieldInfos = type.GetFields();
                    foreach (FieldInfo fieldInfo in fieldInfos)
                    {
                        if (fieldInfo.IsLiteral)
                        {
                            continue;
                        }

                        if (fieldInfo.GetCustomAttributes(typeof(NoMemoryCheck)).Count() > 0)
                        {
                            continue;
                        }

                        Type fieldType = fieldInfo.FieldType;
                        if (fieldType == typeof(int))
                        {
                            if ((int)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(uint))
                        {
                            if ((uint)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(long))
                        {
                            if ((long)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(ulong))
                        {
                            if ((ulong)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(short))
                        {
                            if ((short)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(ushort))
                        {
                            if ((ushort)fieldInfo.GetValue(entity) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(float))
                        {
                            if (Math.Abs((float)fieldInfo.GetValue(entity)) > 0.0001)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(double))
                        {
                            if (Math.Abs((double)fieldInfo.GetValue(entity)) > 0.0001)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType == typeof(bool))
                        {
                            if ((bool)fieldInfo.GetValue(entity) != false)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (typeof(ICollection).IsAssignableFrom(fieldType))
                        {
                            object fieldValue = fieldInfo.GetValue(entity);
                            if (fieldValue == null)
                            {
                                continue;
                            }
                            if (((ICollection)fieldValue).Count != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        PropertyInfo propertyInfo = fieldType.GetProperty("Count");
                        if (propertyInfo != null)
                        {
                            if ((int)propertyInfo.GetValue(fieldInfo.GetValue(entity)) != 0)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }

                        if (fieldType.IsClass)
                        {
                            if (fieldInfo.GetValue(entity) != null)
                            {
                                dict.Add(type.Name, fieldInfo.Name);
                            }
                            continue;
                        }
                    }
                }
            }

            return(dict);
        }
Ejemplo n.º 20
0
        private MultiMapSet <string, string> ai_documents_with_tags; // document -> tags

        public AITags()
        {
            timestamp_generated    = DateTime.UtcNow;
            ai_tags_with_documents = new MultiMapSet <string, string>();
            ai_documents_with_tags = new MultiMapSet <string, string>();
        }
        private void PopulateItems()
        {
            bool exclusive  = ObjBooleanAnd.IsChecked ?? true;
            bool is_negated = ObjBooleanNot.IsChecked ?? false;

            MultiMapSet <string, string> tags_with_fingerprints_ALL = GetNodeItems(this.library, null);
            MultiMapSet <string, string> tags_with_fingerprints     = tags_with_fingerprints_ALL;

            // If this is exclusive mode, we want to constrain the list of items in the tree
            if (!is_negated && exclusive && 0 < selected_tags.Count)
            {
                bool             first_set = true;
                HashSet <string> exclusive_fingerprints = new HashSet <string>();
                foreach (string selected_tag in selected_tags)
                {
                    if (first_set)
                    {
                        first_set = false;
                        exclusive_fingerprints.UnionWith(tags_with_fingerprints_ALL.Get(selected_tag));
                    }
                    else
                    {
                        exclusive_fingerprints.IntersectWith(tags_with_fingerprints_ALL.Get(selected_tag));
                    }
                }

                tags_with_fingerprints = GetNodeItems(this.library, exclusive_fingerprints);
            }

            // Filter them by the user filter
            List <string> tags_eligible = null;

            if (!String.IsNullOrEmpty(TxtSearchTermsFilter.Text))
            {
                string   filter_set = TxtSearchTermsFilter.Text.ToLower();
                string[] filters    = filter_set.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < filters.Length; ++i)
                {
                    filters[i] = filters[i].Trim();
                }

                tags_eligible = new List <string>();
                foreach (string tag in tags_with_fingerprints.Keys)
                {
                    string tag_lower = tag.ToLower();
                    foreach (string filter in filters)
                    {
                        if (tag_lower.Contains(filter))
                        {
                            tags_eligible.Add(tag);
                            break;
                        }
                    }
                }
            }
            else
            {
                tags_eligible = new List <string>(tags_with_fingerprints.Keys);
            }

            // Sort the tags
            List <string> tags_sorted = new List <string>(tags_eligible);

            if (ObjSort.IsChecked ?? false)
            {
                tags_sorted.Sort(delegate(string tag1, string tag2)
                {
                    return(tags_with_fingerprints[tag2].Count - tags_with_fingerprints[tag1].Count);
                });
            }
            else
            {
                tags_sorted.Sort();
            }

            // Create the tag list to bind to
            List <GenericLibraryExplorerItem> displayed_items = new List <GenericLibraryExplorerItem>();

            foreach (string tag in tags_sorted)
            {
                GenericLibraryExplorerItem item = new GenericLibraryExplorerItem
                {
                    GenericLibraryExplorerControl = this,
                    library = this.library,

                    tag          = tag,
                    fingerprints = tags_with_fingerprints[tag],

                    OnItemDragOver = this.OnItemDragOver,
                    OnItemDrop     = this.OnItemDrop,
                    OnItemPopup    = this.OnItemPopup,

                    IsSelected = selected_tags.Contains(tag)
                };

                displayed_items.Add(item);
            }

            // Bind baby bind - tag list
            TreeSearchTerms.DataContext = displayed_items;

            // Populate the chart
            PopulateChart(tags_with_fingerprints);

            // Then we have to list the associated documents
            HashSet <string> fingerprints = new HashSet <string>();

            if (0 < selected_tags.Count)
            {
                if (exclusive)
                {
                    bool first_set = true;
                    foreach (string selected_tag in selected_tags)
                    {
                        if (first_set)
                        {
                            fingerprints.UnionWith(tags_with_fingerprints.Get(selected_tag));
                        }
                        else
                        {
                            fingerprints.IntersectWith(tags_with_fingerprints.Get(selected_tag));
                        }
                    }
                }
                else
                {
                    foreach (string selected_tag in selected_tags)
                    {
                        fingerprints.UnionWith(tags_with_fingerprints.Get(selected_tag));
                    }
                }
            }

            // Implement the NEGATION
            if (is_negated && 0 < fingerprints.Count)
            {
                HashSet <string> negated_fingerprints = this.library.GetAllDocumentFingerprints();
                fingerprints = new HashSet <string>(negated_fingerprints.Except(fingerprints));
            }

            // And build a description of them
            // Build up the descriptive span
            Span descriptive_span = new Span();

            if (!String.IsNullOrEmpty(description_title))
            {
                Bold bold = new Bold();
                bold.Inlines.Add(description_title);
                descriptive_span.Inlines.Add(bold);
                descriptive_span.Inlines.Add(": ");
            }
            string separator = exclusive ? " AND " : " OR ";

            if (is_negated)
            {
                descriptive_span.Inlines.Add("NOT [ ");
            }
            descriptive_span.Inlines.Add(StringTools.ConcatenateStrings(selected_tags, separator, 0));
            if (is_negated)
            {
                descriptive_span.Inlines.Add(" ] ");
            }
            descriptive_span.Inlines.Add(" ");
            descriptive_span.Inlines.Add(LibraryFilterHelpers.GetClearImageInline("Clear this filter.", hyperlink_clear_all_OnClick));

            if (null != OnTagSelectionChanged)
            {
                OnTagSelectionChanged(fingerprints, descriptive_span);
            }
        }
Ejemplo n.º 22
0
        private void Regenerate()
        {
            HashSet <string> parent_fingerprints = null;

            if (null != PDFDocuments && 0 < PDFDocuments.Count)
            {
                parent_fingerprints = new HashSet <string>();
                foreach (var pdf_document in PDFDocuments)
                {
                    parent_fingerprints.Add(pdf_document.Fingerprint);
                }
            }

            MultiMapSet <string, string> map_y_axis = LibraryPivotReportBuilder.GenerateAxisMap((string)ObjYAxis.SelectedItem, Library, parent_fingerprints);
            MultiMapSet <string, string> map_x_axis = LibraryPivotReportBuilder.GenerateAxisMap((string)ObjXAxis.SelectedItem, Library, parent_fingerprints);

            LibraryPivotReportBuilder.IdentifierImplementations.IdentifierImplementationDelegate identifier_implementation = LibraryPivotReportBuilder.IdentifierImplementations.GetIdentifierImplementation((string)ObjIdentifier.SelectedItem);

            LibraryPivotReportBuilder.PivotResult pivot_result = LibraryPivotReportBuilder.GeneratePivot(map_y_axis, map_x_axis);

            GridControl ObjGridControl = new GridControl();

            ObjGridControlHolder.Content     = ObjGridControl;
            ObjGridControl.Model.RowCount    = map_y_axis.Count + 2;
            ObjGridControl.Model.ColumnCount = map_x_axis.Count + 2;

            // ROW/COLUMN Titles
            for (int y = 0; y < pivot_result.y_keys.Count; ++y)
            {
                ObjGridControl.Model[y + 1, 0].CellValue     = pivot_result.y_keys[y];
                ObjGridControl.Model[y + 1, 0].CellValueType = typeof(string);
            }
            for (int x = 0; x < pivot_result.x_keys.Count; ++x)
            {
                ObjGridControl.Model[0, x + 1].CellValue     = pivot_result.x_keys[x];
                ObjGridControl.Model[0, x + 1].CellValueType = typeof(string);
            }

            // Grid contents
            StatusManager.Instance.ClearCancelled("LibraryPivot");
            for (int y = 0; y < pivot_result.y_keys.Count; ++y)
            {
                if (General.HasPercentageJustTicked(y, pivot_result.y_keys.Count))
                {
                    StatusManager.Instance.UpdateStatusBusy("LibraryPivot", "Building library pivot grid", y, pivot_result.y_keys.Count, true);

                    WPFDoEvents.WaitForUIThreadActivityDone(); // HackityHack

                    if (StatusManager.Instance.IsCancelled("LibraryPivot"))
                    {
                        Logging.Warn("User cancelled library pivot grid generation");
                        break;
                    }
                }

                for (int x = 0; x < pivot_result.x_keys.Count; ++x)
                {
                    identifier_implementation(Library, pivot_result.common_fingerprints[y, x], ObjGridControl.Model[y + 1, x + 1]);
                }
            }
            StatusManager.Instance.UpdateStatus("LibraryPivot", "Finished library pivot");

            // ROW/COLUMN Totals
            {
                int y_total = 0;
                {
                    for (int y = 0; y < pivot_result.y_keys.Count; ++y)
                    {
                        int total = 0;
                        for (int x = 0; x < pivot_result.x_keys.Count; ++x)
                        {
                            if (null != pivot_result.common_fingerprints[y, x])
                            {
                                total += pivot_result.common_fingerprints[y, x].Count;
                            }
                        }

                        ObjGridControl.Model[y + 1, pivot_result.x_keys.Count + 1].CellValue     = total;
                        ObjGridControl.Model[y + 1, pivot_result.x_keys.Count + 1].CellValueType = typeof(int);

                        y_total += total;
                    }
                }

                int x_total = 0;
                {
                    for (int x = 0; x < pivot_result.x_keys.Count; ++x)
                    {
                        int total = 0;
                        for (int y = 0; y < pivot_result.y_keys.Count; ++y)
                        {
                            if (null != pivot_result.common_fingerprints[y, x])
                            {
                                total += pivot_result.common_fingerprints[y, x].Count;
                            }
                        }

                        ObjGridControl.Model[pivot_result.y_keys.Count + 1, x + 1].CellValue     = total;
                        ObjGridControl.Model[pivot_result.y_keys.Count + 1, x + 1].CellValueType = typeof(int);

                        x_total += total;
                    }
                }

                int common_total = (x_total + y_total) / 2;
                if (common_total != x_total || common_total != y_total)
                {
                    throw new GenericException("X and Y totals do not match?!");
                }
                ObjGridControl.Model[pivot_result.y_keys.Count + 1, pivot_result.x_keys.Count + 1].CellValue     = common_total;
                ObjGridControl.Model[pivot_result.y_keys.Count + 1, pivot_result.x_keys.Count + 1].CellValueType = typeof(int);

                ObjGridControl.Model[0, pivot_result.x_keys.Count + 1].CellValue     = "TOTAL";
                ObjGridControl.Model[0, pivot_result.x_keys.Count + 1].CellValueType = typeof(string);
                ObjGridControl.Model[pivot_result.y_keys.Count + 1, 0].CellValue     = "TOTAL";
                ObjGridControl.Model[pivot_result.y_keys.Count + 1, 0].CellValueType = typeof(string);
            }

            // Store the results for the toolbar buttons
            last_pivot_result   = pivot_result;
            last_ObjGridControl = ObjGridControl;
        }