private static Node<PO.Workers> AddWorkersRootNode(GraphClient client, Node<PO.Root> rootNode) { var nodeRef = client.Create(PO.Workers.Create("Workers"), null, new[]{ new IndexEntry{ Name=NameIndexName, KeyValues=new[]{ new KeyValuePair<string,object>("Name", "Workers") } } }); client.CreateRelationship<PO.Root, Relationships.RelatedToRelationship>(rootNode.Reference, new Relationships.RelatedToRelationship(nodeRef)); var ret = client.Get<PO.Workers>(nodeRef.Id); client.Update<PO.Workers>(ret.Reference, node => { node.SetID(ret.Reference.Id); }); ret = client.Get<PO.Workers>(nodeRef.Id); Debug.Assert(ret.Reference.Id == ret.Data.ID); Debug.Assert(ret.Reference.Id == nodeRef.Id); Debug.Assert(ret.Reference.Id == GetWorkersRootNode(client, rootNode).Reference.Id); return ret; }
private void EnsureRelationshipInDb(Node<Actor> actor, Node<Character> character, GraphClient db) { var rel = actor .Out<Character>(ActorPlayed.TypeKey, i => i.CharacterName == character.Data.CharacterName) .InE() .FirstOrDefault(); if (rel == null) { db.CreateRelationship<Actor, ActorPlayed>(actor.Reference, new ActorPlayed(character.Reference)); } }
static void Main(string[] args) { // Ready the node manager! var nodeManager = new NodeManager(); // Neo4J client, connect to localhost GraphClient client = new GraphClient(new Uri("http://*****:*****@" SELECT DISTINCT Person.FirstName as lhFName, Person.LastName as lhLName, Person.Id as lhId, Person.FacebookId as lhFB, Friend.PersonId rhId, Friend.FacebookId as rhFB, pFriend.FirstName as rhFName,pFriend.LastName as rhLName FROM Person JOIN Friend ON (Friend.PersonId = Person.Id) JOIN Person pFriend ON (pFriend.FacebookId=Friend.FacebookId) "; sqlConnection1.Open(); reader = cmd.ExecuteReader(); // Create graph structure Graph<Person> peopleGraph = new Graph<Person>(new NodeList<Person>()); while (reader.Read()) { // Get left and right nodes in friendships, they certainly exist var left = nodeManager.CreateIfExists((string)reader["lhFB"], client, (string)reader["lhFName"], (string)reader["lhLName"], peopleGraph); var right = nodeManager.CreateIfExists((string)reader["rhFB"], client, (string)reader["rhFName"], (string)reader["rhLName"], peopleGraph); //// Parse the user's first name and last name from Facebook display name. //string parsedFirstName = (string)reader["Display"]; //int index = 0; //foreach (char character in parsedFirstName) { // index++; // if (character == ' ') { // break; // } //} //string parsedLastName = parsedFirstName.Substring(index, parsedFirstName.Length - index); //parsedFirstName = parsedFirstName.Substring(0, index-1); //Dictionary<string, Object> dictRight = nodeManager.CreateIfExists((string)reader["rhFB"], client, parsedFirstName, parsedLastName, peopleGraph); //Object tempRight; //dictRight.TryGetValue("NodeReference", out tempRight); //NodeReference<Person> right = (NodeReference<Person>)tempRight; // Create relationship between left and right client.CreateRelationship(left.NodeReference, new FriendsWith(right.NodeReference)); Person leftPerson = client.Get<Person>(left.NodeReference).Data; Person rightPerson = client.Get<Person>(right.NodeReference).Data; //Object tempLeftNode; //dictLeft.TryGetValue("GraphNode", out tempLeftNode); //GraphNode<Person> leftNode = (GraphNode<Person>)tempLeftNode; //Object tempRightNode; //dictRight.TryGetValue("GraphNode", out tempRightNode); //GraphNode<Person> rightNode = (GraphNode<Person>)tempRightNode; peopleGraph.AddUndirectedEdge(left.GraphNode, right.GraphNode); // Log relationship creation string leftName = leftPerson.FirstName; string rightName = rightPerson.FirstName; Console.WriteLine("Relationship between " + leftName + " and " + rightName + " created."); } sqlConnection1.Close(); // New sql command SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.Text; cmd2.Connection = sqlConnection1; // Query for all people with no friends :( cmd2.CommandText = @"SELECT DISTINCT Person.FacebookId, Person.FirstName, Person.LastName FROM Person"; sqlConnection1.Open(); reader = cmd2.ExecuteReader(); // Create nodes without relationships for all people to fill holes left by original query while (reader.Read()) { nodeManager.CreateIfExists((string)reader["FacebookId"], client, (string)reader["FirstName"], (string)reader["LastName"], peopleGraph); } sqlConnection1.Close(); Console.WriteLine("\n"); Console.WriteLine(BronKerbosch1(new Graph<Person>(new NodeList<Person>()), peopleGraph, new Graph<Person>(new NodeList<Person>()))); }
public Scaffolding() { client = new GraphClient(new Uri("http://localhost:7474/db/data")); client.Connect(); client.CreateIndex("User", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.exact }, IndexFor.Node); // full text node index client.CreateIndex("Module", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); // exact node index //client.CreateIndex("Genre", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); // full text node index // Create Entities // Movies /* Movie swI = new Movie() { Name = "Star Wars: Episode I - The Phantom Menace", Description = "Begins the story of Anakin Skywalker" }; var starWarsEpisodeI = client.Create(swI, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", swI.Name }, { "Description", swI.Description }, { "Id", swI.Id.ToString() } } }); Movie swIV = new Movie() { Name = "Star Wars: Episode IV - A New Hope", Description = "First Starwars movie to debut on the big screen" }; var starWarsEpisodeIV = client.Create(swIV, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", swIV.Name }, { "Description", swIV.Description }, { "Id", swIV.Id.ToString() } } }); Movie indy = new Movie() { Name = "Indiana Jones and the Temple of Doom", Description = "Second movie in the original Indiana Jones trilogy" }; var indianaJonesTempleOfDoom = client.Create(indy, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", indy.Name }, { "Description", indy.Description }, { "Id", indy.Id.ToString() } } }); Movie jp = new Movie() { Name = "Jurassic Park", Description = "First Jurassic park movie" }; var jurassicPark = client.Create(jp, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", jp.Name }, { "Description", jp.Description }, { "Id", jp.Id.ToString() } } }); Movie et = new Movie() { Name = "ET", Description = "ET phone home" }; var ET = client.Create(et, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", et.Name }, { "Description", et.Description }, { "Id", et.Id.ToString() } } }); */ // Directors User lucas = new User() { UserName = "******", Email_ID ="Lucas", Password ="******" }; var georgeLucas = client.Create(lucas, new IRelationshipAllowingParticipantNode<User>[0], new[] { new IndexEntry("User") { { "Name", lucas.UserName }, { "Id", lucas.UserID.ToString() } } }); User spielberg = new User() { UserName = "******", Email_ID = "Lucas", Password = "******" }; var stevenSpielberg = client.Create(spielberg, new IRelationshipAllowingParticipantNode<User>[0], new[] { new IndexEntry("User") { { "Name", spielberg.UserName }, { "Id", spielberg.UserID.ToString() } } }); Module module1 = new Module() { ModuleName = "Module 1" }; var modModule1 = client.Create(module1, new IRelationshipAllowingParticipantNode<Module>[0], new[] { new IndexEntry("Module") { { "Name", module1.ModuleName }, { "Id", module1.ModuleId.ToString() } } }); Module module2 = new Module() { ModuleName = "Module 2" }; var modModule2 = client.Create(module2, new IRelationshipAllowingParticipantNode<Module>[0], new[] { new IndexEntry("Module") { { "Name", module2.ModuleName }, { "Id", module2.ModuleId.ToString() } } }); /* // Genres Genre sf = new Genre() { Name = "Science Fiction" }; var sciFi = client.Create(sf, new IRelationshipAllowingParticipantNode<Genre>[0], new[] { new IndexEntry("Genre") { { "Name", sf.Name }, { "Id", sf.Id.ToString() } } }); Genre adv = new Genre() { Name = "Adventure" }; var adventure = client.Create(adv, new IRelationshipAllowingParticipantNode<Genre>[0], new[] { new IndexEntry("Genre") { { "Name", adv.Name }, { "Id", adv.Id.ToString() } } }); */ // Create Relationships client.CreateRelationship(stevenSpielberg, new HasCompletedRelation(modModule1)); client.CreateRelationship(stevenSpielberg, new HasCompletedRelation(modModule2)); client.CreateRelationship(georgeLucas, new HasCompletedRelation(modModule2)); /* client.CreateRelationship(starWarsEpisodeIV, new PartOf(sciFi)); client.CreateRelationship(indianaJonesTempleOfDoom, new PartOf(adventure)); client.CreateRelationship(jurassicPark, new PartOf(sciFi)); client.CreateRelationship(jurassicPark, new PartOf(adventure)); client.CreateRelationship(ET, new PartOf(sciFi)); client.CreateRelationship(georgeLucas, new Directed(starWarsEpisodeI, new Models.Payloads.Payload() { Comment = "George Lucas' second Star Wars trilogy" })); client.CreateRelationship(georgeLucas, new Directed(starWarsEpisodeIV, new Models.Payloads.Payload() { Comment = "First Starwars movie that George Lucas directed" })); client.CreateRelationship(georgeLucas, new Directed(indianaJonesTempleOfDoom, new Models.Payloads.Payload() { Comment = "Lucas collaborated with Spielberg while filming" })); client.CreateRelationship(stevenSpielberg, new Directed(jurassicPark, new Models.Payloads.Payload() { Comment = "Huge box office success" })); client.CreateRelationship(stevenSpielberg, new Directed(ET, new Models.Payloads.Payload() { Comment = "One of Spielberg's most successful movies" })); */ /* var refA = client.Create(new User() { UserName = "******" }); var refB = client.Create(new Module() { ModuleName = "Module A" }); var refC = client.Create(new Module() { ModuleName = "Module B" }); var refD = client.Create(new User() { UserName = "******" }); // Create relationships client.CreateRelationship(refA, new HasCompletedRelation(refB)); client.CreateRelationship(refA, new HasCompletedRelation(refC)); client.CreateRelationship(refD, new HasCompletedRelation(refC)); //client.CreateRelationship(refC, new HasCompletedRelation(refD) { Reason = "Don't know why : )" }); client.CreateRelationship(refD, new HasCompletedRelation(refA)); */ }
private static Node<PO.Worker> AddWorker(string name, GraphClient Client, Node<PO.Workers>WorkersRootNode) { var workerNodeRef = Client.Create( PO.Worker.Create(name), null, new[] { new IndexEntry { Name = "my_index", KeyValues = new[] { /* new KeyValuePair<string, object>("key", "value"), new KeyValuePair<string, object>("key2", ""), */ new KeyValuePair<string, object>("key3", "value3") } } } ); Client.Update<PO.Worker>(workerNodeRef, node => { node.SetID(workerNodeRef.Id); }); var workersRootNode = WorkersRootNode; var rel = Client.CreateRelationship<PO.Workers, Relationships.HasItemRelationship>( workersRootNode.Reference, new Relationships.HasItemRelationship(workerNodeRef) ); var workerNode = Get(workerNodeRef.Id, Client); return workerNode; }