Ejemplo n.º 1
0
        static public TreeNode BuildTree(ICollection <string> rawInput, ICollection <string> toIgnore)
        {
            Dictionary <string, List <string> > groupsMap = new Dictionary <string, List <string> >();

            groupsMap = StringSets.BuildMap(rawInput, toIgnore, 3);
            return(BuildTree(groupsMap, rawInput));
        }
Ejemplo n.º 2
0
        public static ICollection <string> GetContent(CategoryTreeNode settings, Category cat)//, ICollection<string> allNames)
        {
            //Category cat = node.Tag as Category;
            ICollection <string> allNames = settings.mAllEntries;

            ICollection <string> collection = new List <string>();

            if (cat.Rules.Count > 0)
            {
                ((List <string>)collection).AddRange(allNames);

                foreach (StringRule sr in cat.Rules)
                {
                    collection = StringSets.ApplyRule(sr, collection);
                }
            }

            foreach (string e in cat.Entries)
            {
                collection.Add(e);
            }

            return(collection);
        }
Ejemplo n.º 3
0
        static public TreeNode BuildTree(Dictionary <string, List <string> > groupsMap, ICollection <string> originalList)
        {
            int minCount = 3;

            TreeNode root = new TreeNode();

            root.Text = "ALL";

            List <string> topLevel    = new List <string>();
            List <string> usedGroups  = new List <string>();
            List <string> usedEntries = new List <string>();

            List <Pair <int, string> > sizes = new List <Pair <int, string> >();

            Dictionary <string, List <string> > .Enumerator it2 = groupsMap.GetEnumerator();
            while (it2.MoveNext())
            {
                sizes.Add(new Pair <int, string>(it2.Current.Value.Count, it2.Current.Key));
            }
            sizes.Sort(compareIntString);

            List <string> toIgnore = new List <string>();

            foreach (Pair <int, string> pair in sizes)
            {
                string thisGroup = pair.Value;
                if (usedGroups.Contains(thisGroup))
                {
                    continue;
                }

                //TreeNode n = new TreeNode();
                //n.Text = thisGroup;
                //root.Nodes.Add(n);

                toIgnore.Clear();
                toIgnore.Add(thisGroup);
                List <string> values = groupsMap[thisGroup];

                Dictionary <string, List <string> > moreSubStrings = StringSets.BuildMap(values, toIgnore, 3);
                //add substrings ...
                Dictionary <string, List <string> > .Enumerator it3 = moreSubStrings.GetEnumerator();
                while (it3.MoveNext())
                {
                    string subGroup = it3.Current.Key;
                    if (usedGroups.Contains(subGroup))
                    {
                        continue;
                    }

                    if (!groupsMap.ContainsKey(subGroup) || Set.IsSubset <string>(groupsMap[subGroup], it3.Current.Value) == false)
                    {
                        continue;
                    }

                    //TreeNode n2 = new TreeNode();
                    //n2.Text = subGroup;
                    //n.Nodes.Add(n2);

                    usedGroups.Add(subGroup);
                }

                usedGroups.Add(thisGroup);
                topLevel.Add(thisGroup);
            }

            //sizes.Sort( new delegate Comparison<Pair<int,string>>(Pair<int,string> a, Pair<int,string> b){ return    } );

            topLevel.Sort();

            foreach (string s in topLevel)
            {
                TreeNode n = new TreeNode();
                n.Text = s;
                foreach (string subEntry in groupsMap[s])
                {
                    TreeNode n2 = new TreeNode();
                    n2.Text = subEntry;
                    n2.Tag  = subEntry;
                    n.Nodes.Add(n2);

                    usedEntries.Add(subEntry);
                }
                root.Nodes.Add(n);
            }

            TreeNode unsorted = new TreeNode();

            unsorted.Text = "UNSORTED";
            foreach (string s in originalList)
            {
                if (usedEntries.Contains(s) == false)
                {
                    TreeNode n2 = new TreeNode();
                    n2.Text = s;
                    n2.Tag  = s;
                    unsorted.Nodes.Add(n2);
                }
            }
            root.Nodes.Add(unsorted);

            return(root);
        }