示例#1
0
        public void GraphEquality()
        {
            try
            {
                Console.WriteLine("Going to get two copies of a Graph from DBPedia and compare");
                Console.WriteLine("Using the DBPedia Graph for Barack Obama");

                Graph g      = new Graph();
                Graph h      = new Graph();
                Uri   target = new Uri("http://dbpedia.org/resource/Barack_Obama");

                VDS.RDF.Parsing.UriLoader.Load(g, target);
                Console.WriteLine("Loaded first copy OK - " + g.Triples.Count + " Triples");
                VDS.RDF.Parsing.UriLoader.Load(h, target);
                Console.WriteLine("Loaded second copy OK - " + h.Triples.Count + " Triples");

                //Should have same Base Uri
                Assert.AreEqual(g.BaseUri, h.BaseUri, "Should have the same Base URI after being loaded from the same URI via the URILoader");

                //Do equality check
                Console.WriteLine("Checking the Equality of the Graphs");
                //TestTools.CompareGraphs(g, h, true);
                Dictionary <INode, INode> mapping;
                bool equals = g.Equals(h, out mapping);
                Assert.IsTrue(equals, "Graphs should have been equal");
                if (mapping != null)
                {
                    Console.WriteLine("Blank Node Mapping was:");
                    foreach (KeyValuePair <INode, INode> pair in mapping)
                    {
                        Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
                    }
                }
                Console.WriteLine();

                //Get a third graph of something different
                Console.WriteLine("Going to get a third Graph of something different and check it is non-equal");
                Uri   target2 = new Uri("http://dbpedia.org/resource/Nottingham");
                Graph i       = new Graph();
                VDS.RDF.Parsing.UriLoader.Load(i, target2);

                //Should have different Base URIs and be non-equal
                Assert.AreNotEqual(g.BaseUri, i.BaseUri, "Graphs retrieved from different URIs via the URILoader should have different Base URIs");
                Assert.AreNotEqual(h.BaseUri, i.BaseUri, "Graphs retrieved from different URIs via the URILoader should have different Base URIs");
                Assert.IsFalse(g.Equals(i));
                Assert.IsFalse(h.Equals(i));
                //TestTools.CompareGraphs(g, i, false);
                //TestTools.CompareGraphs(h, i, false);
            }
            catch (WebException webEx)
            {
                TestTools.ReportError("Web Exception", webEx);
                Console.WriteLine();
                Console.WriteLine("Unable to retrieve the Graphs from the Web successfully!");
                Assert.Inconclusive();
            }
            catch (RdfParseException parseEx)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        public void GraphEquality()
        {
            Skip.IfNot(TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseRemoteParsing), "Test Config marks Remote Parsing as unavailable, test cannot be run");

            try
            {
                Options.UriLoaderCaching = false;
                Console.WriteLine("Going to get two copies of a Graph from DBPedia and compare");
                Console.WriteLine("Using the DBPedia Graph for Barack Obama");

                Graph g      = new Graph();
                Graph h      = new Graph();
                Uri   target = new Uri("http://dbpedia.org/resource/Barack_Obama");

                VDS.RDF.Parsing.UriLoader.Load(g, target);
                Console.WriteLine("Loaded first copy OK - " + g.Triples.Count + " Triples");
                VDS.RDF.Parsing.UriLoader.Load(h, target);
                Console.WriteLine("Loaded second copy OK - " + h.Triples.Count + " Triples");

                //Should have same Base Uri
                Assert.Equal(g.BaseUri, h.BaseUri);

                //Do equality check
                Console.WriteLine("Checking the Equality of the Graphs");
                //TestTools.CompareGraphs(g, h, true);
                Dictionary <INode, INode> mapping;
                bool equals = g.Equals(h, out mapping);
                Assert.True(equals, "Graphs should have been equal");
                if (mapping != null)
                {
                    Console.WriteLine("Blank Node Mapping was:");
                    foreach (KeyValuePair <INode, INode> pair in mapping)
                    {
                        Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
                    }
                }
                Console.WriteLine();

                //Get a third graph of something different
                Console.WriteLine("Going to get a third Graph of something different and check it is non-equal");
                Uri   target2 = new Uri("http://dbpedia.org/resource/Nottingham");
                Graph i       = new Graph();
                VDS.RDF.Parsing.UriLoader.Load(i, target2);

                //Should have different Base URIs and be non-equal
                Assert.Equal(g.BaseUri, i.BaseUri);
                Assert.Equal(h.BaseUri, i.BaseUri);
                Assert.False(g.Equals(i));
                Assert.False(h.Equals(i));
                //TestTools.CompareGraphs(g, i, false);
                //TestTools.CompareGraphs(h, i, false);
            }
            catch (WebException webEx)
            {
                TestTools.ReportError("Web Exception", webEx);
                Console.WriteLine();
                Console.WriteLine("Unable to retrieve the Graphs from the Web successfully!");
                Skip.If(true, "Unable to retrieve the graphs from the web successfully.");
            }
            finally
            {
                Options.UriLoaderCaching = true;
            }
        }