コード例 #1
0
        private static void AddCodes(G g, CodeTreeNode treeNode, int label)
        {
            var descendants = treeNode.GetAllDescendants();

            foreach (var descendant in descendants)
            {
                g.AddV(label, descendant.Value.Code).AddP(P.Name, descendant.Value.Name);
            }

            var connectedParent = new HashSet <(string, string)>();

            foreach (var descendant in descendants)
            {
                var vertex = g.V(descendant.Value.Code);

                foreach (var parentCode in descendant.Value.Parents.Select(p => p.Key))
                {
                    var key = (vertex.Id, parentCode);

                    if (!connectedParent.Contains(key))
                    {
                        var parentVertex = g.V(parentCode);

                        vertex.AddE(EL.Child, parentVertex);

                        connectedParent.Add(key);
                    }
                }
            }
        }
コード例 #2
0
        public static CodeTreeNode Build(string json)
        {
            var flatnodes = JsonConvert.DeserializeObject <Koder>(json);

            var          dict     = new Dictionary <string, CodeTreeNode>();
            const string rootCode = "~";

            foreach (var flatnode in flatnodes.Data)
            {
                string code = flatnode.Kode.ToLower();

                if (!dict.TryGetValue(code, out var node))
                {
                    node = new CodeTreeNode
                    {
                        Code = !string.IsNullOrWhiteSpace(code) ? code : rootCode,
                    };

                    foreach (var kvp in flatnode.Tittel)
                    {
                        node.Names.Add(kvp.Key, kvp.Value);
                    }

                    dict.Add(node.Code, node);
                }
            }

            foreach (var flatnode in flatnodes.Data)
            {
                string code   = flatnode.Kode.ToLower();
                string parent = flatnode.Forelder?.ToLower();

                if (!string.IsNullOrWhiteSpace(parent))
                {
                    var node = dict[code];

                    if (!dict.ContainsKey(parent))
                    {
                        // TODO: Log
                        //Console.WriteLine(flatnode.Forelder + " mangler!");
                        continue;
                    }

                    var forelder = dict[parent];

                    if (node.Parents.ContainsKey(forelder.Code))
                    {
                    }

                    node.Parents.Add(forelder.Code, forelder);
                    forelder.Children.Add(node.Code, node);
                }
            }

            return(dict[rootCode]);
        }