/// <summary> /// Run the tutorial. /// </summary> public void Run() { var NGraph = new NGraph(); NGraph.OnVertexAdded.OnNotification += msg => Console.WriteLine("direct: " + msg); NGraph.OnVertexAdded.OnError += (sender, ex) => Console.WriteLine("direct: " + ex); NGraph.OnVertexAdded.OnCompleted += (sender, msg) => Console.WriteLine("direct: " + msg); var Logger1 = new StringLogger(); NGraph.OnVertexAdded. SendTo(Logger1); var Logger2 = new StringLogger2(); NGraph.OnVertexAdded. NFilter(msg => !msg.Contains("edge")). SendTo(Logger2.ImATarget); Task.Factory.StartNew(() => NGraph.OnVertexAdded.ToIEnumerable().ForEach(str => Console.WriteLine("magic!!! " + str))); NGraph.Shoot("Hello vertex!"); Console.WriteLine(); NGraph.Shoot("Hello edge!"); var graph = GraphFactory.CreateGenericPropertyGraph_WithStringIds("graph01"); var graphlogger = new GraphLogger <String, Int64, String, String, Object, String, Int64, String, String, Object, String, Int64, String, String, Object, String, Int64, String, String, Object>(); graph.OnVertexAddition.OnVoting += (g, vertex, vote) => { if (vertex.Id == "0") { vote.Deny(); } }; graph.OnVertexAddition.SendTo(graphlogger.NewVertexAdded); graph.OnVertexAddition.NewFuncArrow((g, v) => "vertex '" + v.Id + "' on graph '" + g.Id + "' added!").SendTo(Logger1); Task.Factory.StartNew(() => graph.OnVertexAddition.NewFuncArrow((g, v) => v).ToIEnumerable().ForEach(v => Console.WriteLine("It's magic a vertex... " + v.Id))); //graph.OnVertexAdded2.NewFuncArrow((g, v) => v).AsTask(v => v.ToIEnumerable().ForEach(v2 => Console.WriteLine("It's magic23 a vertex... " + v2.Id))); graph.AddVertex(v => v.SetProperty("hello", "world 1!")); graph.AddVertex(v => v.SetProperty("hello", "world 2!")); while (true) { Thread.Sleep(100); } }
/// <summary> /// Run the tutorial. /// </summary> public void Run() { graph = GraphFactory.CreateGenericPropertyGraph_WithStringIds("Vanaheimr graph processing stack"); var IlliasCommons = AddProject("Illias Commons"); var Eunomia = AddProject("Eunomia"); var Blueprints = AddProject("Blueprints", IlliasCommons, Eunomia); while (true) { Thread.Sleep(100); } }
/// <summary> /// Run the tutorial. /// </summary> public void Run() { // Create a new simple property graph var graph = GraphFactory.CreateGenericPropertyGraph_WithStringIds("TagExample"); var graphSchema = graph.StrictSchemaGraph("TagExampleSchema", "The graph schema of the TagExample graph"); // Add tags var _good = graph.AddVertex("good", isTag); var _funny = graph.AddVertex("funny", isTag); // Add Users var _Alice = graph.AddVertex("Alice", "User"); var _Bob = graph.AddVertex("Bob", "User"); // Add websites var _cnn = graph.AddVertex("CNN", isWebsite, v => v.SetProperty(Url, "http://cnn.com")); var _xkcd = graph.AddVertex("xkcd", isWebsite, v => v.SetProperty(Url, "http://xkcd.com")); var _onion = graph.AddVertex("onion", isWebsite, v => v.SetProperty(Url, "http://theonion.com")); // Add edges using the semantic web style (s, p, o) var _edge1 = graph.AddEdge(_cnn, isTaggedWith, _good); var _edge2 = graph.AddEdge(_xkcd, isTaggedWith, _good); var _edge3 = graph.AddEdge(_xkcd, isTaggedWith, _funny); var _edge4 = graph.AddEdge(_onion, isTaggedWith, _funny); var _edge5 = graph.AddEdge(_Alice, likes, _xkcd); var _edge6 = graph.AddEdge(_Alice, likes, _Bob); // Find out which tags xkcd is tagged with _xkcd. // The xkcd vertex OutEdges(isTaggedWith). // Get all outedges with label "isTaggedWith" InV(). // Get the incoming vertices of the edges Ids(). // Get all vertex Ids ForEach(Tag => Console.WriteLine(Tag)); // List tagged sites graph.VerticesByLabel(isWebsite). ForEach(v => Console.WriteLine("{0}\t=> {1}", v.Id, v.OutDegree(isTaggedWith))); // List tagged sites using LINQ var _WebList = from Website in graph.VerticesByLabel(isWebsite) select new { Name = Website.Id, Count = Website.OutDegree(isTaggedWith) }; foreach (var _Site in _WebList) { Console.WriteLine("{0}\t=> {1}", _Site.Name, _Site.Count); } Console.WriteLine(); Console.WriteLine("Used vertex labels: "); Console.WriteLine(" " + graphSchema.Vertices().Ids().Cast <String>().Aggregate((a, b) => a + ", " + b)); Console.WriteLine(); Console.WriteLine("Used edge labels: "); graphSchema.Edges().ForEach(e => { Console.WriteLine(" " + e.Id + ": " + e.SetGet(GraphSchemaHandling.AlternativeUsage).Cast <String>().Aggregate((a, b) => a + ", " + b)); }); }
/// <summary> /// Run the tutorial. /// </summary> public void Run() { var g1 = DemoGraphFactory.Create(); var g2 = g1.AsReadOnly(); using (var GraphServer = new BifrostHTTPServer(new IPPort(8080), (id, descr, init) => GraphFactory.CreateGenericPropertyGraph_WithStringIds(id, descr, () => new VetoVote(), init)) { ServerName = "Vanaheimr Bifrost HTTP Server v0.1" } as IBifrostHTTPServer) { GraphServer.CreateNewGraph("123", "The first graph"); var graph = GraphServer.CreateNewGraph("512", "demo graph", g => g.SetProperty(GraphDBOntology.Description.Suffix, "the second graph").SetProperty("hello", "world!").SetProperty("graphs", "are cool!")); var a1 = graph.ContainsKey("hello"); var a2 = graph.ContainsKey("world!"); var a3 = graph.ContainsKey("graphs"); var a4 = graph.ContainsKey("are cool!"); var a5 = graph.ContainsKey(GraphDBOntology.Description.Suffix); var c1 = graph.ContainsValue(123UL); var t = false; graph.UseProperty("Id", success => t = true); var ii = "i = " + t; var b1 = graph.Contains("Id", 123UL); var b2 = graph is IProperties <String, Object>; var aa = graph.GetProperties(null); var deleted3 = graph.Remove().ToList(); var deleted1 = graph.Remove("hello"); // --------------------------------------------------------------- var v1 = graph.AddVertex(v => v.SetProperty("Name", "Vertex1")); var v2 = graph.AddVertex(v => v.SetProperty("Name", "Vertex2")); var e1 = graph.AddEdge(v1, v2, "knows", e => e.SetProperty("Name", "Edge1")); var allV = graph.Vertices().ToList(); var allE = graph.Edges().ToList(); // --------------------------------------------------------------- //var HTTPClient1 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080)); //var _request1 = HTTPClient1.GET("/").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3"). // SetProtocolVersion(HTTPVersion.HTTP_1_1). // SetUserAgent("Hermod HTTP Client v0.1"). // SetConnection("keep-alive"). // AddAccept(HTTPContentType.JSON_UTF8, 1); //HTTPClient1.Execute(_request1, response => Console.WriteLine(response.Content.ToUTF8String())); //// --------------------------------------------------------------- //var HTTPClient2 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080)); //var _request2 = HTTPClient2.GET("/123/description").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3"). // SetProtocolVersion(HTTPVersion.HTTP_1_1). // SetUserAgent("Hermod HTTP Client v0.1"). // SetConnection("keep-alive"). // AddAccept(HTTPContentType.JSON_UTF8, 1); //HTTPClient2.Execute(_request2, response => Console.WriteLine(response.Content.ToUTF8String())); // --------------------------------------------------------------- //#if !__MonoCS__ // var JavaScriptEngine = new Jurassic.ScriptEngine(); // //Console.WriteLine(engine.Evaluate("5 * 10 + 2")); // //engine.SetGlobalValue("interop", 15); // //engine.ExecuteFile(@"c:\test.js"); // //engine.Evaluate("interop = interop + 5"); // //Console.WriteLine(engine.GetGlobalValue<int>("interop")); // JavaScriptEngine.Evaluate("function VertexFilter(vertex) { return vertex.Name == 'Vertex1' }"); // foreach (var Vertex in graph.Vertices()) // { // //engine.SetGlobalValue("vertex", new JSPropertyVertex(_vv, engine)); // //engine.SetGlobalFunction("test", new Func<int, int, int>((a, b) => a + b)); // //Console.WriteLine(engine.Evaluate<int>("test(5, 6)")); // //engine.Evaluate("var yesorno = vertex.Id > 1"); // //var Id = engine.GetGlobalValue ("vertex.Id"); // //var yesorno = engine.GetGlobalValue<Boolean>("yesorno"); // if (JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(Vertex, JavaScriptEngine))) // Console.WriteLine(Vertex.Id); // } // var aaa = from V2 // in graph.Vertices() // where JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(V2, JavaScriptEngine)) // select V2; // var aaaa = aaa.ToList(); // var GraphClient = new RemotePropertyGraph(IPv4Address.Parse("127.0.0.1"), new IPPort(8080)) { Id = 512 }; // Console.WriteLine(GraphClient.Description); // //foreach (var V3 in GraphClient.Vertices()) // // Console.WriteLine(V3.Id); //#endif while (true) { Thread.Sleep(100); } } }