public static void Main(string[] args) { Graph g = new Graph(); Graph h = new Graph(); UriLoader.Load(g, new Uri("http://nottm.ecs.soton.ac.uk/AllAboutThatWeb/profiles/exports/14")); UriLoader.Load(h, new Uri("http://nottm.ecs.soton.ac.uk/AllAboutThatWeb/profiles/14")); //Output to GraphViz GraphVizGenerator gvizgen = new GraphVizGenerator("png"); gvizgen.Generate(g, "Triple.png", false); gvizgen.Generate(h, "AATTriple.png", false); GraphVizWriter gvizwriter = new GraphVizWriter(); gvizwriter.Save(g, "Triple.dot"); gvizwriter.Save(h, "AATTriple.dot"); }
/// <summary> /// Generates GraphViz Output for the given Graph. /// </summary> /// <param name="g">Graph to generated GraphViz Output for.</param> /// <param name="filename">File you wish to save the Output to.</param> /// <param name="open">Whether you want to open the Output in the default application (according to OS settings) for the filetype after it is Created.</param> public void Generate(IGraph g, String filename, bool open) { // Prepare the Process ProcessStartInfo start = new ProcessStartInfo(); if (!_graphvizdir.Equals(String.Empty)) { start.FileName = _graphvizdir + "dot.exe"; } else { start.FileName = "dot.exe"; } start.Arguments = "-T" + _format; start.UseShellExecute = false; start.RedirectStandardInput = true; start.RedirectStandardOutput = true; // Prepare the GraphVizWriter and Streams GraphVizWriter gvzwriter = new GraphVizWriter(); using (BinaryWriter writer = new BinaryWriter(new FileStream(filename, FileMode.Create))) { // Start the Process Process gvz = new Process(); gvz.StartInfo = start; gvz.Start(); // Write to the Standard Input gvzwriter.Save(g, gvz.StandardInput); // Read the Standard Output byte[] buffer = new byte[4096]; using (BinaryReader reader = new BinaryReader(gvz.StandardOutput.BaseStream)) { while (true) { int read = reader.Read(buffer, 0, buffer.Length); if (read == 0) { break; } writer.Write(buffer, 0, read); } reader.Close(); } writer.Close(); gvz.Close(); } // Open if requested if (open) { Process.Start(filename); } }
public void WritingGraphViz1() { Skip.IfNot(TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseGraphViz), "Test Config marks GraphViz as unavailable, test cannot be run"); Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); GraphVizWriter writer = new GraphVizWriter(); writer.Save(g, "WritingGraphViz1.dot"); }
public static void Main(string[] args) { //Create a new Empty Graph Graph g = new Graph(); //Define Namespaces g.NamespaceMap.AddNamespace("pets", new Uri("http://example.org/pets")); //Create Uri Nodes IUriNode dog, fido, rob, owner, name, species, breed, lab; dog = g.CreateUriNode("pets:Dog"); fido = g.CreateUriNode("pets:abc123"); rob = g.CreateUriNode("pets:def456"); owner = g.CreateUriNode("pets:hasOwner"); name = g.CreateUriNode("pets:hasName"); species = g.CreateUriNode("pets:isAnimal"); breed = g.CreateUriNode("pets:isBreed"); lab = g.CreateUriNode("pets:Labrador"); //Assert Triples g.Assert(new Triple(fido, species, dog)); g.Assert(new Triple(fido, owner, rob)); g.Assert(new Triple(fido, name, g.CreateLiteralNode("Fido"))); g.Assert(new Triple(rob, name, g.CreateLiteralNode("Rob"))); g.Assert(new Triple(fido, breed, lab)); //Attempt to output GraphViz try { Console.WriteLine("Writing GraphViz DOT file graph_building_example2.dot"); GraphVizWriter gvzwriter = new GraphVizWriter(); gvzwriter.Save(g, "graph_building_example2.dot"); Console.WriteLine("Creating a PNG got this Graph called graph_building_example2.png"); GraphVizGenerator gvzgen = new GraphVizGenerator("svg", "C:\\Program Files (x86)\\Graphviz2.20\\bin"); gvzgen.Format = "png"; gvzgen.Generate(g, "graph_building_example2.png", false); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
/// <summary> /// Generates GraphViz Output for the given Graph /// </summary> /// <param name="g">Graph to generated GraphViz Output for</param> /// <param name="filename">File you wish to save the Output to</param> /// <param name="open">Whether you want to open the Output in the default application (according to OS settings) for the filetype after it is Created</param> public void Generate(IGraph g, String filename, bool open) { //Prepare the Process ProcessStartInfo start = new ProcessStartInfo(); if (!_graphvizdir.Equals(String.Empty)) { start.FileName = this._graphvizdir + "dot.exe"; } else { start.FileName = "dot.exe"; } start.Arguments = "-T" + this._format; start.UseShellExecute = false; start.RedirectStandardInput = true; start.RedirectStandardOutput = true; //Prepare the GraphVizWriter and Streams GraphVizWriter gvzwriter = new GraphVizWriter(); BinaryWriter output = new BinaryWriter(new FileStream(filename, FileMode.Create)); //Start the Process Process gvz = new Process(); gvz.StartInfo = start; gvz.Start(); //Write to the Standard Input gvzwriter.Save(g, gvz.StandardInput); //Read the Standard Output Tools.StreamCopy(gvz.StandardOutput.BaseStream, output.BaseStream); output.Close(); gvz.Close(); //Open if requested if (open) { Process.Start(filename); } }
private void btnVisualise_Click(object sender, EventArgs e) { if (this.txtFile.Text.Equals(String.Empty)) { MessageBox.Show("You must enter a filename you wish to visualise the Graph to", "Filename Required", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { switch (Path.GetExtension(this.txtFile.Text)) { case ".dot": case "dot": GraphVizWriter dotwriter = new GraphVizWriter(); dotwriter.Save(this._g, this.txtFile.Text); break; case ".png": case "png": GraphVizGenerator pnggenerator = new GraphVizGenerator("png"); pnggenerator.Generate(this._g, this.txtFile.Text, true); break; case ".svg": case "svg": default: GraphVizGenerator svggenerator = new GraphVizGenerator("svg"); svggenerator.Generate(this._g, this.txtFile.Text, true); break; } } catch (Exception ex) { MessageBox.Show("An Error occurred while trying to visualise the selected Graph:\n" + ex.Message, "Visualisation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.DialogResult = DialogResult.OK; this.Close(); } }
public void GraphCreation1() { //Create a new Empty Graph Graph g = new Graph(); Assert.IsNotNull(g); //Define Namespaces g.NamespaceMap.AddNamespace("vds", new Uri("http://www.vdesign-studios.com/dotNetRDF#")); g.NamespaceMap.AddNamespace("ecs", new Uri("http://id.ecs.soton.ac.uk/person/")); //Check we set the Namespace OK Assert.IsTrue(g.NamespaceMap.HasNamespace("vds"), "Failed to set a Namespace"); //Set Base Uri g.BaseUri = g.NamespaceMap.GetNamespaceUri("vds"); Assert.IsNotNull(g.BaseUri); Assert.AreEqual(g.NamespaceMap.GetNamespaceUri("vds"), g.BaseUri); //Create Uri Nodes IUriNode rav08r, wh, lac, hcd; rav08r = g.CreateUriNode("ecs:11471"); wh = g.CreateUriNode("ecs:1650"); hcd = g.CreateUriNode("ecs:46"); lac = g.CreateUriNode("ecs:60"); //Create Uri Nodes for some Predicates IUriNode supervises, collaborates, advises, has; supervises = g.CreateUriNode("vds:supervises"); collaborates = g.CreateUriNode("vds:collaborates"); advises = g.CreateUriNode("vds:advises"); has = g.CreateUriNode("vds:has"); //Create some Literal Nodes ILiteralNode singleLine = g.CreateLiteralNode("Some string"); ILiteralNode multiLine = g.CreateLiteralNode("This goes over\n\nseveral\n\nlines"); ILiteralNode french = g.CreateLiteralNode("Bonjour", "fr"); ILiteralNode number = g.CreateLiteralNode("12", new Uri(g.NamespaceMap.GetNamespaceUri("xsd") + "integer")); g.Assert(new Triple(wh, supervises, rav08r)); g.Assert(new Triple(lac, supervises, rav08r)); g.Assert(new Triple(hcd, advises, rav08r)); g.Assert(new Triple(wh, collaborates, lac)); g.Assert(new Triple(wh, collaborates, hcd)); g.Assert(new Triple(lac, collaborates, hcd)); g.Assert(new Triple(rav08r, has, singleLine)); g.Assert(new Triple(rav08r, has, multiLine)); g.Assert(new Triple(rav08r, has, french)); g.Assert(new Triple(rav08r, has, number)); //Now print all the Statements Console.WriteLine("All Statements"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString()); } //Get statements about Rob Vesse Console.WriteLine(); Console.WriteLine("Statements about Rob Vesse"); foreach (Triple t in g.GetTriples(rav08r)) { Console.WriteLine(t.ToString()); } //Get Statements about Collaboration Console.WriteLine(); Console.WriteLine("Statements about Collaboration"); foreach (Triple t in g.GetTriples(collaborates)) { Console.WriteLine(t.ToString()); } //Attempt to output Turtle for this Graph try { Console.WriteLine("Writing Turtle file graph_building_example.ttl"); TurtleWriter ttlwriter = new TurtleWriter(); ttlwriter.Save(g, "graph_building_example.ttl"); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } //Attempt to output GraphViz try { Console.WriteLine("Writing GraphViz DOT file graph_building_example.dot"); GraphVizWriter gvzwriter = new GraphVizWriter(); gvzwriter.Save(g, "graph_building_example.dot"); Console.WriteLine("Attempting Live GraphViz Generation as SVG"); GraphVizGenerator gvzgen = new GraphVizGenerator("svg", "C:\\Program Files (x86)\\Graphviz2.20\\bin"); gvzgen.Generate(g, "graph_building_example.svg", false); Console.WriteLine("Attempting Live GraphViz Generation as PNG"); gvzgen.Format = "png"; gvzgen.Generate(g, "graph_building_example.png", false); } catch (Exception ex) { TestTools.ReportError("Exception using GraphViz", ex, true); } }