Example #1
0
        private PatternTree Combine2Patterns(PatternTree px, PatternTree py, Depth depth)
        {
            var preList = px.CombinePreorderRepresentation(py);
            var child   = PatternTree.Create(preList, false, MiningParams);

            PatternsExtended.AddPattern(child);
            var curDepth = depth + 1;

            while (--curDepth >= 0)
            {
                if (!px.ContainsDepth(curDepth) || !py.ContainsDepth(curDepth))
                {
                    continue;
                }

                foreach (TreeOccSet tSet in px[curDepth].GetTreeSet())
                {
                    if (!py.ContainsTreeAtDepth(curDepth, tSet.TreeId))
                    {
                        continue;
                    }
                    foreach (RootOcc root in tSet.GetRootSet())
                    {
                        if (!py.ContainsRootIndex(curDepth, tSet.TreeId, root.RootIndex))
                        {
                            continue;
                        }

                        var xOcc = px.GetOccurrence(curDepth, tSet.TreeId, root.RootIndex);
                        var yOcc = py.GetFirstOccAfterSpecifiedIndex(xOcc.Depth, xOcc.TreeId, xOcc.RootIndex, xOcc.RightMostIndex);

                        if (yOcc == null)
                        {
                            continue;
                        }

                        child.AddOccurrence(xOcc.Combine(yOcc));
                    }
                }
            }

            if (!child.IsFrequent)
            {
                return(null);
            }

            PatternsFrequent.AddFrequentPattern(child);

            child.Father = px;
            child.Mother = py;

            px.CheckMatch(child);
            py.CheckMatch(child);

            return(child);
        }
Example #2
0
        void ScanP1P2(ITreeNode tn, ref Depth maxDepth)
        {
            if (maxDepth <= tn.Depth)
            {
                maxDepth = tn.Depth;
            }

            var treeId = tn.Tree.TreeId;

            var preList1P    = new[] { tn.Symbol, MiningParams.BackTrackSymbol };
            var patternKey1P = preList1P.ToPreorderString(MiningParams.Separator);

            if (!OnePatterns.ContainsKey(patternKey1P))
            {
                var onePt = PatternTree.Create(preList1P, false, MiningParams);
                PatternsExtended.AddPattern(onePt);
                OnePatterns.Add(onePt.PreorderString, onePt);
            }

            OnePatterns[patternKey1P].AddOccurrence(OccInduced.Create(treeId, tn.Depth, new[] { tn.PreorderIndex }));

            if (tn.Children == null)
            {
                return;
            }

            foreach (var child in tn.Children)
            {// Scan for 2-patterns, and each child implies an existence of right-most 2-occurrence.
                var preList2P    = new[] { tn.Symbol, child.Symbol, MiningParams.BackTrackSymbol, MiningParams.BackTrackSymbol };
                var patternKey2P = preList2P.ToPreorderString(MiningParams.Separator);

                if (!TwoPatterns.ContainsKey(patternKey2P))
                {
                    var twoPt = PatternTree.Create(preList2P, true, MiningParams);
                    PatternsExtended.AddPattern(twoPt);
                    TwoPatterns.Add(twoPt.PreorderString, twoPt);
                }

                var occ = OccInduced.Create(treeId, tn.Depth, new[] { tn.PreorderIndex, child.PreorderIndex });
                if (child.IsLeaf)
                {
                    occ.AbleToConnect = false;
                }

                TwoPatterns[patternKey2P].AddOccurrence(occ);

                ScanP1P2(child, ref maxDepth);
            }
        }
Example #3
0
        private void ConnectTwoPatterns(PatternTree f2, PatternTree fpt, Depth depth)
        {
            if (f2.Size != 2)
            {
                throw new InvalidOperationException("The connect pattern must be 2-pattern.");
            }

            var preList = f2.ConnectPreorderRepresentation(fpt);
            var child   = PatternTree.Create(preList, true, MiningParams);

            PatternsExtended.AddPattern(child);

            var depthC = depth + 1; // Depth of connect

            while (--depthC >= 0)
            {
                if (!f2.ContainsDepth(depthC))
                {
                    continue;
                }
                var depthTbc = depthC + 1; // Depth of to be connected
                if (!fpt.ContainsDepth(depthTbc))
                {
                    continue;
                }

                foreach (TreeOccSet tSet in f2[depthC].GetTreeSet())
                {
                    if (!fpt.ContainsTreeAtDepth(depthTbc, tSet.TreeId))
                    {
                        continue;
                    }

                    foreach (RootOcc root in tSet.GetRootSet())
                    {
                        foreach (IOccurrence f2Occ in root.GetRightMostSet())
                        {
                            if (!fpt[depthTbc][tSet.TreeId].RootSet.ContainsKey(f2Occ.SecondIndex))
                            {
                                continue;
                            }

                            var newOcc = f2Occ.Connect(fpt[depthTbc][tSet.TreeId][f2Occ.SecondIndex].FirstOcc);
                            child.AddOccurrence(newOcc);
                        }
                    }
                }
            }

            if (!child.IsFrequent)
            {
                return;
            }
            PatternsFrequent.AddFrequentPattern(child);

            child.Father = f2;
            child.Mother = fpt;

            f2.CheckMatch(child);
            fpt.CheckMatch(child);
        }