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");
        }
        public void WritingGraphViz3()
        {
            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");

            GraphVizGenerator generator = new GraphVizGenerator("png");

            generator.Generate(g, "WritingGraphViz3.png", false);
        }
Beispiel #3
0
        public void WritingGraphViz2()
        {
            if (!TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseGraphViz))
            {
                Assert.Inconclusive("Test Config marks GraphViz as unavailable, test cannot be run");
            }

            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");

            GraphVizGenerator generator = new GraphVizGenerator("svg");

            generator.Generate(g, "WritingGraphViz2.svg", false);
        }
        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);
            }
        }
        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 GraphMerging()
        {
            try
            {
                //Load the Test RDF
                TurtleParser ttlparser = new TurtleParser();
                Graph g = new Graph();
                Graph h = new Graph();
                Assert.IsNotNull(g);
                Assert.IsNotNull(h);
                ttlparser.Load(g, "MergePart1.ttl");
                ttlparser.Load(h, "MergePart2.ttl");

                Console.WriteLine("Merge Test Data Loaded OK");
                Console.WriteLine();

                Console.WriteLine("Graph 1 Contains");
                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine();
                Console.WriteLine("Graph 2 Contains");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine();

                Console.WriteLine("Attempting Graph Merge");
                g.Merge(h);
                Console.WriteLine();

                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Assert.AreEqual(8, g.Triples.Count, "Expected 8 Triples after the Merge");

                //Use a GraphViz Generator to picture this
                Console.WriteLine();
                Console.WriteLine("Visualizing Merged Graph as SVG with GraphViz");
                GraphVizGenerator gvzgen = new GraphVizGenerator("svg");
                gvzgen.Generate(g, "MergeTest.svg", false);
                Console.WriteLine("Visualisation created as MergeTest.svg");

                //Same merge into an Empty Graph
                Console.WriteLine();
                Console.WriteLine("Combining the two Graphs with two Merge operations into an Empty Graph");
                Graph i = new Graph();

                //Need to reload g from disk
                g = new Graph();
                ttlparser.Load(g, "MergePart1.ttl");

                //Do the actual merge
                i.Merge(g);
                i.Merge(h);
                Console.WriteLine();

                foreach (Triple t in i.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Assert.AreEqual(8, i.Triples.Count, "Expected 8 Triples after the Merge");



            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Exception", ex, true);
            }
        }
        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);
            }
        }
Beispiel #8
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("MergeTest.txt");
            try
            {
                //Set Output
                Console.SetOut(output);

                Console.WriteLine("## Merge Test Suite");

                //Load the Test RDF
                TurtleParser ttlparser = new TurtleParser();
                Graph g = new Graph();
                Graph h = new Graph();
                ttlparser.Load(g, "MergePart1.ttl");
                ttlparser.Load(h, "MergePart2.ttl");

                Console.WriteLine("Merge Test Data Loaded OK");
                Console.WriteLine();

                Console.WriteLine("Graph 1 Contains");
                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine();
                Console.WriteLine("Graph 2 Contains");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine();

                Console.WriteLine("Attempting Graph Merge");
                g.Merge(h);
                Console.WriteLine();

                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                //Use a GraphViz Generator to picture this
                Console.WriteLine();
                Console.WriteLine("Visualizing Merged Graph as SVG with GraphViz");
                GraphVizGenerator gvzgen = new GraphVizGenerator("svg");
                gvzgen.Generate(g, "MergeTest.svg", false);
                Console.WriteLine("Visualisation created as MergeTest.svg");

                //Same merge into an Empty Graph
                Console.WriteLine();
                Console.WriteLine("Combining the two Graphs with two Merge operations into an Empty Graph");
                Graph i = new Graph();

                //Need to reload g from disk
                g = new Graph();
                ttlparser.Load(g, "MergePart1.ttl");

                //Do the actual merge
                i.Merge(g);
                i.Merge(h);
                Console.WriteLine();

                foreach (Triple t in i.Triples)
                {
                    Console.WriteLine(t.ToString());
                }


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            output.Close();
        }