コード例 #1
0
ファイル: ParsingTest.cs プロジェクト: roddickchen/NCDK
        public void BasicParseTest()
        {
            string      sig  = "[A]([B])";
            ColoredTree tree = AbstractVertexSignature.Parse(sig);

            Assert.AreEqual(sig, tree.ToString());
        }
コード例 #2
0
ファイル: ParsingTest.cs プロジェクト: roddickchen/NCDK
        public void MultipleLevelsParseTest()
        {
            string      sig  = "[A]([B1]([C])[B2])";
            ColoredTree tree = AbstractVertexSignature.Parse(sig);

            Assert.AreEqual(sig, tree.ToString());
        }
コード例 #3
0
ファイル: ParsingTest.cs プロジェクト: roddickchen/NCDK
        public void EdgeLabelMultipleLevelsParseTest()
        {
            string      sig  = "[A](=[B1]([C])=[B2])";
            ColoredTree tree = AbstractVertexSignature.Parse(sig);

            Console.Out.WriteLine(tree.ToString());
            Assert.AreEqual(sig, tree.ToString());
        }
コード例 #4
0
        public void MakeFromColoredTree(ColoredTree tree)
        {
            this.MakeGraph();
            ColoredTree.Node root = tree.GetRoot();
            this.MakeVertex(root.label);
            this.vertexCount = 1;
            foreach (var child in root.children)
            {
                this.MakeFromColoredTreeNode(root, child, 0);
            }

            // Important! resets so that the builder can be used again
            this.vertexCount = 0;
            colorToVertexIndexMap.Clear();
        }
コード例 #5
0
        public static ColoredTree Parse(string s)
        {
            ColoredTree tree = null;

            ColoredTree.Node parent  = null;
            ColoredTree.Node current = null;
            int    currentHeight     = 1;
            int    color             = -1;
            int    j          = 0;
            int    k          = 0;
            int    l          = 0;
            string edgeSymbol = null;

            for (int i = 0; i < s.Length; i++)
            {
                char c = s[i];
                if (c == AbstractVertexSignature.StartBranchSymbolChar)
                {
                    parent = current;
                    currentHeight++;
                    tree.UpdateHeight(currentHeight);
                    l = i;
                }
                else if (c == AbstractVertexSignature.EndBranchSymbolChar)
                {
                    parent = parent.parent;
                    currentHeight--;
                    l = i;
                }
                else if (c == StartNodeSymbolChar)
                {
                    if (l < i)
                    {
                        edgeSymbol = s.Substring(l + 1, i - (l + 1));
                        l          = i;
                    }
                    j = i + 1;
                }
                else if (c == EndNodeSymbolChar)
                {
                    string ss;
                    if (k < j)
                    {    // no color
                        ss    = s.Substring(j, i - j);
                        color = -1;
                    }
                    else
                    {        // color
                        ss    = s.Substring(j, k - 1 - j);
                        color = int.Parse(s.Substring(k, i - k), NumberFormatInfo.InvariantInfo);
                    }
                    if (tree == null)
                    {
                        tree    = new ColoredTree(ss);
                        parent  = tree.GetRoot();
                        current = tree.GetRoot();
                    }
                    else
                    {
                        if (edgeSymbol == null)
                        {
                            current = tree.MakeNode(
                                ss, parent, currentHeight, color);
                        }
                        else
                        {
                            current = tree.MakeNode(
                                ss, parent, currentHeight, color, edgeSymbol);
                        }
                    }
                    edgeSymbol = null;
                    l          = i;
                }
                else if (c == ',')
                {
                    k = i + 1;
                }
            }
            return(tree);
        }