Exemple #1
0
        static void Main(string[] args)
        {
            Program obj = new Program();

            // Init
            GraphClient client = new GraphClient(new Uri("http://localhost:7474/db/data"));

            client.Connect();

            //Construct Graph
            GraphOfNodes          graphNodes            = obj.getGraphInfo();
            Dictionary <int, int> SubjectIdLevelMapping = obj.getLevelDictionary(graphNodes.LevelNodeDict);

            obj.m_LevelCount = SubjectIdLevelMapping.Keys.Count;
            Dictionary <int, Level> levelDictionary = obj.createLevelObjects();

            //obj.createGraph(graphNodes,SubjectIdLevelMapping, client);

            //Get queries
            obj.createMatrixArrays(client, levelDictionary);
        }
Exemple #2
0
        GraphOfNodes getGraphInfo()
        {
            //string filepath = @"D:\Work\Sample-Protobuffs\Franchise-Perrisk\test\rites_batch0.dat";
            string filepath = @"D:\Work\Sample-Protobuffs\jpty_case.dat";

            PartitionData        PD           = Deserialize(filepath);
            PartitionDataAdpator PDataAdaptor = new PartitionDataAdpator(PD);

            ReferencePrototype refprototype = new ReferencePrototype(PD);
            //long contId = 11324656;
            long contId = 42586728;

            //long contId = 11331;
            refprototype.ReferencePrepare(GraphType.Auto);

            ExposureDataAdaptor expData = PDataAdaptor.GetExposureAdaptor(contId);


            GraphInfo    graphInfo  = GetGraph(GraphType.Auto, expData, new GraphBuildCache(PDataAdaptor));
            GraphOfNodes graphNodes = (GraphOfNodes)graphInfo.Graph;

            graphNodes.AssignLevelToNode();
            return(graphNodes);
        }
Exemple #3
0
        void createGraph(GraphOfNodes graphNodes, Dictionary <int, int> SubjectIdLevelMapping, GraphClient client)
        {
            List <GraphNode> lst_graphNodes = graphNodes.GraphNodes;

            Dictionary <GraphNode, List <GraphNode> > lst_relationships = graphNodes.ParentToChildrenMap;

            if (lst_graphNodes == null || lst_relationships == null)
            {
                return;
            }


            Dictionary <TermNode, NodeReference <Neo4jTermNode> >   m_term_nodes  = new Dictionary <TermNode, NodeReference <Neo4jTermNode> >();
            Dictionary <CoverNode, NodeReference <Neo4jCoverNode> > m_cover_nodes = new Dictionary <CoverNode, NodeReference <Neo4jCoverNode> >();


            //Add Nodes
            foreach (GraphNode node in lst_graphNodes)
            {
                if (node is TermNode)
                {
                    TermNode term_node = (TermNode)node;

                    //term_node.ded;
                    int           id = node.Subject.ID;
                    Neo4jTermNode tn = new Neo4jTermNode();
                    tn.NodeID            = id;
                    tn.NumberOfBuildings = term_node.PrimarySubject.Schedule.ActNumOfBldgs;
                    tn.IsPerRisk         = term_node.IsPerRisk;
                    tn.Level             = SubjectIdLevelMapping[id];

                    if (term_node.Deductibles.GetDedList() != null && term_node.Deductibles.GetDedList().Count != 0)
                    {
                        tn.Deductible = term_node.Deductibles.GetDedList().First().Amount;
                    }

                    if (term_node.Limits.GetLimList() != null && term_node.Limits.GetLimList().Count != 0)
                    {
                        tn.Limit = term_node.Limits.GetLimList().First().Amount;
                    }

                    var ref1 = client.Create(tn);
                    m_term_nodes.Add(term_node, (NodeReference <Neo4jTermNode>)ref1);
                }
                else if (node is CoverNode)
                {
                    CoverNode cover_node = (CoverNode)node;
                    //term_node.ded;
                    string         coverName = cover_node.CoverName;
                    Neo4jCoverNode cn        = new Neo4jCoverNode();
                    cn.Name      = coverName;
                    cn.IsPerRisk = cover_node.IsPerRisk;
                    cn.Level     = SubjectIdLevelMapping[cover_node.Subject.ID];

                    var ref1 = client.Create(cn);
                    m_cover_nodes.Add(cover_node, (NodeReference <Neo4jCoverNode>)ref1);
                }
            }

            //Add relationships
            foreach (KeyValuePair <GraphNode, List <GraphNode> > rel in lst_relationships)
            {
                //Parent is  term Node
                if (rel.Key is TermNode)
                {
                    NodeReference <Neo4jTermNode> parentTermNode;
                    m_term_nodes.TryGetValue(rel.Key as TermNode, out parentTermNode);
                    List <GraphNode> lst_childnodes = rel.Value;
                    foreach (GraphNode child in lst_childnodes)
                    {
                        NodeReference <Neo4jTermNode> childGraphTermNode;
                        m_term_nodes.TryGetValue(child as TermNode, out childGraphTermNode);

                        if (child != null)
                        {
                            client.CreateRelationship <Neo4jTermNode, TermChildRelationship>(parentTermNode, new TermChildRelationship(childGraphTermNode));
                        }
                    }
                }

                //Parent is  Cover Node
                else if (rel.Key is CoverNode)
                {
                    NodeReference <Neo4jCoverNode> parentTermNode;
                    m_cover_nodes.TryGetValue(rel.Key as CoverNode, out parentTermNode);
                    List <GraphNode> lst_childnodes = rel.Value;
                    foreach (GraphNode child in lst_childnodes)
                    {
                        if (child is TermNode)
                        {
                            NodeReference <Neo4jTermNode> childGraphTermNode;
                            m_term_nodes.TryGetValue(child as TermNode, out childGraphTermNode);

                            if (child != null)
                            {
                                client.CreateRelationship <Neo4jCoverNode, CoverChildRelationship>(parentTermNode, new CoverChildRelationship(childGraphTermNode));
                            }
                        }

                        else if (child is CoverNode)
                        {
                            NodeReference <Neo4jCoverNode> childGraphCoverNode;
                            m_cover_nodes.TryGetValue(child as CoverNode, out childGraphCoverNode);

                            if (child != null)
                            {
                                client.CreateRelationship <Neo4jCoverNode, DerivedCoverChildRelationship>(parentTermNode, new DerivedCoverChildRelationship(childGraphCoverNode));
                            }
                        }
                        else
                        {
                            throw new NotSupportedException("Can only handle nodes of type term and cover");
                        }
                    }
                }
            }
            // Create entities
            //var refA = client.Create(new Person() { Name = "Person A" });
            //var refB = client.Create(new Person() { Name = "Person B" });
            //var refC = client.Create(new Person() { Name = "Person C" });
            //var refD = client.Create(new Person() { Name = "Person D" });

            //// Create relationships
            //client.CreateRelationship(refA, new KnowsRelationship(refB));
            //client.CreateRelationship(refB, new KnowsRelationship(refC));
            //client.CreateRelationship(refB, new HatesRelationship(refD), new HatesData("Crazy guy")));
            //client.CreateRelationship(refC, new HatesRelationship(refD), new HatesData("Don't know why...")));
            //client.CreateRelationship(refD, new KnowsRelationship(refA));
        }