Exemple #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);
        }
Exemple #2
0
        internal static bool HasNewConnectOccurrenceAtDepth(this PatternTree p2, PatternTree pt, Depth depth)
        {
            if (p2 == null)
            {
                throw new ArgumentNullException("p2");
            }
            if (!p2.Is2Pattern)
            {
                throw new ArgumentException("The connect pattern must be a 2-pattern.");
            }
            if (pt == null)
            {
                throw new ArgumentNullException("pt");
            }
            if (p2.SecondSymbol != pt.FirstSymbol)
            {
                return(false);
            }

            var depthConnect       = depth;
            var depthToBeConnected = depthConnect + 1;

            if (!p2.ContainsDepth(depthConnect) || !pt.ContainsDepth(depthToBeConnected))
            {
                return(false);
            }

            foreach (TreeOccSet tSet in p2[depthConnect].GetTreeSet())
            {// For every tree that contains p2 at 'depthConnect'
                if (!pt.ContainsTreeAtDepth(depthToBeConnected, tSet.TreeId))
                {
                    continue;
                }
                foreach (RootOcc rSet in tSet.GetRootSet())
                {         // For every root occurrence, check its leaves
                    foreach (IOccurrence iOcc in rSet.GetRightMostSet())
                    {     // checks each leaf, if a leaf of root occurrence of p2 is the root of an occurrence of pt, there might be a new pattern.
                        if (pt[depthToBeConnected][tSet.TreeId].ContainsRootIndex(iOcc.RightMostIndex))
                        { // An occurrence of p2 has a leaf which is the root of an occurrence of pt, a new pattern should be extended.
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        internal static bool HasNewCombineOccurrenceAtDepth(this PatternTree xPattern, PatternTree yPattern, Depth depth)
        {
            if (xPattern == null)
            {
                throw new ArgumentNullException("xPattern");
            }
            if (yPattern == null)
            {
                throw new ArgumentNullException("yPattern");
            }

            if (xPattern.FirstSymbol != yPattern.FirstSymbol)
            {
                return(false);
            }
            if (!xPattern.ContainsDepth(depth) || !yPattern.ContainsDepth(depth))
            {
                return(false);
            }

            foreach (TreeOccSet tree in xPattern[depth].GetTreeSet())
            {
                if (!yPattern.ContainsTreeAtDepth(depth, tree.TreeId))
                {
                    continue;
                }
                foreach (RootOcc rSet in tree.GetRootSet())
                {
                    if (!yPattern[depth][tree.TreeId].ContainsRootIndex(rSet.RootIndex))
                    {
                        continue;
                    }
                    foreach (IOccurrence occY in yPattern[depth][tree.TreeId][rSet.RootIndex].GetRightMostSet())
                    {
                        if (rSet.FirstOcc.RightMostIndex < occY.SecondIndex)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #4
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);
        }