Exemplo n.º 1
0
        public List <JunctionPoint <T> > ExplodeByParentJunctions()
        {
            List <JunctionPoint <T> > output = new List <JunctionPoint <T> >();

            ListDictionary <T, T> splits = items.SplitByParentJunction(2);

            if (splits.Any())
            {
                foreach (var pair in splits)
                {
                    JunctionPoint <T> newJunction = new JunctionPoint <T>();
                    newJunction.Learn(this);
                    newJunction.items    = pair.Value;
                    newJunction.rootItem = pair.Key;
                    //newJunction.ProcessItems(pair.Key);
                    output.Add(newJunction);
                }
            }
            else
            {
                output.Add(this);
                if (this.rootItem == null)
                {
                    var item = items.FirstOrDefault();
                    if (item != null)
                    {
                        item = item.parent as T;
                    }
                    rootItem = item;
                }
                //this.ProcessItems(item);
            }

            return(output);
        }
Exemplo n.º 2
0
 public void Learn(JunctionPoint <T> source)
 {
     XPathRoot             = source.XPathRoot;
     Signature             = source.Signature;
     JunctionSize          = source.JunctionSize;
     JunctionSizeFrequency = source.JunctionSizeFrequency;
     type = source.type;
 }
        /// <summary>
        /// Gets sets of graph nodes (<see cref="JunctionPoint{T}"/>) with same junction signature (sequence of child names)
        /// </summary>
        /// <param name="MinFrequency">The minimum frequency - minimal number of same-child-count occurances, before signature comparison</param>
        /// <param name="MinJunctionSize">Minimal number of child nodes - size of the junction.</param>
        /// <param name="DescendingByFreq">Result set will be given i descending order by frequency</param>
        /// <param name="TrimTemplateItems">The <see cref="RecordTemplate"/> in <see cref="JunctionPoint{T}.Template"/> will contain <see cref="RecordTemplateItem"/>s targeting only first-level child, not leafs</param>
        /// <returns></returns>
        public List <JunctionPoint <T> > GetJunctionBlocks(Int32 MinFrequency, Int32 MinJunctionSize, Boolean DescendingByFreq, Boolean TrimTemplateItems)
        {
            Dictionary <int, List <int> > freqBinByJunctions = JunctionCounter.GetFrequencyBins();

            List <Int32> freqList = freqBinByJunctions.Keys.ToList();

            if (DescendingByFreq)
            {
                freqList = freqList.OrderByDescending(x => x).ToList();
            }


            Dictionary <String, List <T> >          signatureDictionary      = new Dictionary <string, List <T> >();
            Dictionary <String, JunctionPoint <T> > signatureBlockDictionary = new Dictionary <string, JunctionPoint <T> >();

            foreach (Int32 f in freqList)
            {
                if (f > MinFrequency)
                {
                    List <T> junstionsAtFreq = JunctionCounter.GetInstances(freqBinByJunctions[f]);

                    foreach (T jn in junstionsAtFreq)
                    {
                        var childNames = jn.getChildNames();
                        if (childNames.Count < MinJunctionSize)
                        {
                            continue;
                        }

                        String childLineSignature = childNames.toCsvInLine("_").Replace("[", "").Replace("]", "");
                        if (!childLineSignature.isNullOrEmpty())
                        {
                            if (!signatureDictionary.ContainsKey(childLineSignature))
                            {
                                signatureDictionary.Add(childLineSignature, new List <T>());
                                JunctionPoint <T> junctionBlock = new JunctionPoint <T>()
                                {
                                    JunctionSizeFrequency = f
                                };
                                signatureBlockDictionary.Add(childLineSignature, junctionBlock);
                            }
                            signatureDictionary[childLineSignature].Add(jn);
                        }
                    }
                }
            }



            List <JunctionPoint <T> > junctionBlocks = new List <JunctionPoint <T> >();

            foreach (var pair in signatureDictionary)
            {
                JunctionPoint <T> jp = signatureBlockDictionary[pair.Key];
                jp.Signature = pair.Key;
                jp.items.AddRange(pair.Value);

                var jps = jp.ExplodeByParentJunctions();



                //if (jp.items.Count == 0) continue;



                //jp.Template = new RecordTemplate();

                //jp.Template.SubXPath = item.name;

                //jp.type = JunctionPointType.BranchToLeafs;

                //jp.XPathRoot = jp.items.Select(x => x.path).GetCommonPathRoot();



                //foreach (graphWrapNode<LeafNodeDictionaryEntry> child in item.GetChildren()) {

                //    RecordTemplateItem r_item = new RecordTemplateItem();

                //    if (child.IsBranchToLeaf())
                //    {

                //    } else
                //    {
                //        jp.type = JunctionPointType.DeepJunctionPoint;
                //        break;
                //    }

                //    if (child.item != null)
                //    {
                //        r_item.Category = child.item.Category;
                //    }

                //    if (TrimTemplateItems)
                //    {
                //        r_item.SubXPath = child.name;
                //    } else
                //    {
                //        r_item.SubXPath = child.path.GetRelativeXPath(item.path);
                //    }

                //    jp.Template.items.Add(r_item);
                //}

                //jp.Level = item.level;



                //jp.Signature = pair.Key;

                //jp.JunctionSize = jp.items.First().GetChildren().Count;

                foreach (var jpi in jps)
                {
                    jpi.ProcessItems(null, TrimTemplateItems);
                    junctionBlocks.Add(jpi);
                }

                if (jps.Count > 1)
                {
                }
            }


            return(junctionBlocks);
        }