Пример #1
0
        private static bool IsInducedMatch(ReadOnlyCollection <NodeSymbol> large,
                                           int currentIndex,
                                           int currentDepth,
                                           int upperBound,
                                           int lowerBound,
                                           ReadOnlyCollection <NodeSymbol> small,
                                           int matchIndex, NodeSymbol backTrack)
        {
            var curDepth = currentDepth;

            for (var l = currentIndex; l < large.Count; l++)
            {
                if (large.Count - l < small.Count - matchIndex)
                {
                    break;                                             // Cannot contain a subtree in this branch
                }
                if (large[l] == backTrack)
                {
                    if (--curDepth < upperBound)
                    {
                        return(false); // End of this branch, no match
                    }
                    continue;          // Continue this branch
                }

                curDepth++; // Reach to a deep depth
                if (large[l] != small[matchIndex] || curDepth > lowerBound)
                {
                    continue;                                                         // this is induced subtree, so cannot over go a node
                }
                // Got an identical and the virtual matched sequent list is increased by one.
                // Try to find a next match in the larger tree with the next node in the smaller tree.
                var offset = 0; // Here 'offset' records the change of depth.
                for (var s = matchIndex + 1; s < small.Count; s++)
                {
                    if (small[s] == backTrack)
                    {
                        if (s == small.Count - 1)
                        {
                            return(true);                     // It is subtree.
                        }
                        offset--;
                        continue;
                    }

                    offset++;
                    var lowerBoundNext = curDepth + offset;// Lower bound is used when induced subtree is the case
                    var upperBoundNext = lowerBoundNext - 1;
                    // Recursively to try to match the next node
                    if (IsInducedMatch(large, l + 1, curDepth, upperBoundNext, lowerBoundNext, small, s, backTrack))
                    {
                        return(true);
                    }
                    break; // Not match, break and try to match in an other branch in the larger tree
                }
            }
            return(false); // Not match found.
        }
Пример #2
0
        private IEnumerable <PatternTree> SelectPatternsOfSameRoot(NodeSymbol symbol, ICollection <PatternTree> fDi, Depth depth)
        {
            var pts = new List <PatternTree>();

            if (fDi == null || fDi.Count <= 0)
            {
                return(pts);
            }

            pts.AddRange(fDi.Where(pt => pt.FirstSymbol == symbol && pt.AbleToBeConnected && pt.ContainsDepth(depth)));

            return(pts);
        }
        static string ToPreorderStringWithIndex(this ITreeNode node, NodeSymbol backTrack)
        {
            //if (node == null) throw new ArgumentNullException("node");
            //if (string.IsNullOrEmpty(backTrack)) throw new ArgumentNullException("backTrack");

            var str = string.Format("{0}[{1}]", node.Symbol, node.PreorderIndex);

            if (node.Children != null && node.Children.Count > 0)
            {
                str = node.Children.Aggregate(str, (current, child) => current + child.ToPreorderStringWithIndex(backTrack));
            }

            return(str + backTrack);
        }
        public static string ToPreorderString(this ITreeNode itn, char separator, NodeSymbol backTrack)
        {
            //if (itn == null) throw new ArgumentNullException("itn");
            //if (string.IsNullOrEmpty(seperator)) throw new ArgumentNullException("separator");
            //if (string.IsNullOrEmpty(backTrack)) throw new ArgumentNullException("backTrack");

            var str = itn.Symbol + separator.ToString(CultureInfo.InvariantCulture);

            if (itn.Children != null && itn.Children.Count > 0)
            {
                str = itn.Children.Aggregate(str, (current, c) => current + c.ToPreorderString(separator, backTrack));
            }

            return(str + backTrack + separator.ToString(CultureInfo.InvariantCulture));
        }
Пример #5
0
        protected MiningParams(MiningParams another)
        {
            subtreeType = another.SubtreeType;

            mineOrdered = another.MineOrdered;

            mineFrequent = another.MineFrequent;
            mineClosed   = another.MineClosed;
            mineMaximal  = another.MineMaximal;

            supportType          = another.SupportType;
            thresholdRoot        = another.ThresholdRoot;
            thresholdTransaction = another.ThresholdTransaction;

            separator       = another.separator;
            backTrackSymbol = string.Copy(another.backTrackSymbol);
        }
        static internal List <string> ToPreorderStringArray(this ITreeNode itn, NodeSymbol backTrack)
        {
            var array = new List <string> {
                itn.Symbol
            };

            if (itn.Children != null && itn.Children.Count > 0)
            {
                foreach (var child in itn.Children)
                {
                    array.AddRange(ToPreorderStringArray(child, backTrack));
                }
            }

            array.Add(backTrack);

            return(array);
        }
        public static T ConvertToTextTree(string treeInString, char separator, NodeSymbol backTrack)
        {
            if (string.IsNullOrEmpty(treeInString))
            {
                throw new ArgumentNullException("treeInString");
            }
            if (string.IsNullOrEmpty(backTrack))
            {
                throw new ArgumentNullException("backTrack");
            }

            var treeInStringArr = treeInString.Split(new[] { separator, ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var tree            = new T {
                BackTrack = backTrack, Separator = separator
            };

            DoConvert(treeInStringArr, tree);

            return(tree);
        }
Пример #8
0
        public MiningParams(
            SubtreeType subtreeType,
            bool mineOrdered,
            bool mineFrequent,
            bool mineClosed,
            bool mineMaximal,
            SupportType supportType,
            int thresholdRoot,
            int thresholdTransaction,
            char separator,
            string backTrackSymbol)
        {
            switch (subtreeType)
            {
            case SubtreeType.Induced:
                this.subtreeType = subtreeType;
                break;

            default:
                throw new NotSupportedException("subtreeType");
            }

            if (string.IsNullOrEmpty(backTrackSymbol))
            {
                throw new ArgumentNullException("backTrackSymbol");
            }

            this.mineOrdered = mineOrdered;

            this.mineFrequent = mineFrequent;
            this.mineClosed   = mineClosed;
            this.mineMaximal  = mineMaximal;

            this.supportType          = supportType;
            this.thresholdRoot        = thresholdRoot;
            this.thresholdTransaction = thresholdTransaction;
            this.separator            = separator;
            this.backTrackSymbol      = string.Copy(backTrackSymbol);
        }
 public bool Equals(NodeSymbol other)
 {
     return(string.Equals(symbol, other.symbol));
 }
Пример #10
0
        public static bool IsInducedSuperPattern(this PatternTree pt, PatternTree largerPt, NodeSymbol backTrack)
        {
            if (pt.Size > largerPt.Size)
            {
                return(false);
            }
            var largeList = largerPt.PreorderRepresentation;
            var smallList = pt.PreorderRepresentation;

            const int upperBound = 1;
            const int lowerBound = int.MaxValue;

            return(IsInducedMatch(largeList, 0, 0, upperBound, lowerBound, smallList, 0, backTrack));
        }
 public TreeComparer(NodeSymbol backTracking)
 {
     BackTracking = backTracking;
 }