Exemplo n.º 1
0
        protected static void AddElement(
            TProgram program, ArgumentNode node, SymbolNode rootNode, HashSet <SymbolNode> visited)
        {
            if (program == null)
            {
                return;
            }

            // creates child symbol node if needed and updates count
            var numChildren = program.Children?.Count ?? 0;

            if (!node.Children.ContainsKey(program.Label))
            {
                node.Children.Add(program.Label, new SymbolNode(program.Label, numChildren, rootNode));
            }
            var symbolNode = node.Children[program.Label];

            if (!visited.Contains(symbolNode))
            {
                symbolNode.Value++;
                visited.Add(symbolNode);
            }

            // recurses through children
            if (program.Children == null || program.Children.Count == 0)
            {
                return;
            }
            for (var i = 0; i < program.Children.Count; i++)
            {
                AddElement((TProgram)program.Children[i], symbolNode.Children[i], rootNode, visited);
            }
        }
Exemplo n.º 2
0
 public SymbolNode(string symbol, int count, SymbolNode rootNode)
 {
     this.Children = new ArgumentNode[count];
     for (var i = 0; i < count; i++)
     {
         this.Children[i] = new ArgumentNode(i, this);
     }
     this.RootNode = rootNode;
     this._symbol  = symbol;
 }
Exemplo n.º 3
0
        private static uint GetCommonCount(SymbolNode node1, SymbolNode node2)
        {
            var commonCount = Math.Min(node1.Value, node2.Value);

            for (var i = 0; i < node1.Children.Length; i++)
            {
                var child1 = node1.Children[i];
                var child2 = node2.Children[i];
                foreach (var symbChild1 in child1.Children)
                {
                    if (child2.Children.ContainsKey(symbChild1.Key))
                    {
                        commonCount += GetCommonCount(symbChild1.Value, child2.Children[symbChild1.Key]);
                    }
                }
            }

            return(commonCount);
        }
Exemplo n.º 4
0
        private static void Prune(SymbolNode node, uint frequencyThreshold)
        {
            if (node.Children.Length == 0)
            {
                return;
            }

            foreach (var child in node.Children)
            {
                var children = child.Children.ToList();
                child.Children.Clear();
                foreach (var symbChild in children)
                {
                    if (symbChild.Value.Value < frequencyThreshold)
                    {
                        continue;
                    }
                    child.Children.Add(symbChild);
                    Prune(symbChild.Value, frequencyThreshold);
                }
            }
        }
Exemplo n.º 5
0
 public ArgumentNode(int index, SymbolNode parent)
 {
     this._index   = index;
     this.Children = new Dictionary <string, SymbolNode>();
     this.Parent   = parent;
 }
Exemplo n.º 6
0
 private static uint GetNodeCount(SymbolNode node)
 {
     return((uint)(node.Value + node.Children.Sum(
                       child => child.Children.Values.Sum(
                           symbChild => GetNodeCount(symbChild)))));
 }
Exemplo n.º 7
0
 /// <inheritdoc />
 public void Clear()
 {
     this.rootNode = null;
 }