Ejemplo n.º 1
0
        public void ParsingUsingGraphHandlerExplicitTest(String tempFile, IRdfReader parser, bool nsCheck)
        {
            Graph g = new Graph();

            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile(tempFile);

            Graph        h       = new Graph();
            GraphHandler handler = new GraphHandler(h);

            parser.Load(handler, tempFile);

            NTriplesFormatter formatter = new NTriplesFormatter();

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

            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.True(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.False(h.IsEmpty, "Graph should not be empty");
            if (nsCheck)
            {
                Assert.True(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            }
            Assert.Equal(g, h);
        }
Ejemplo n.º 2
0
        public void ParsingGraphHandlerExplicitMerging()
        {
            Graph g = new Graph();

            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile("graph_handler_tests_temp.ttl");

            Graph        h       = new Graph();
            GraphHandler handler = new GraphHandler(h);

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "graph_handler_tests_temp.ttl");

            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.True(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.False(h.IsEmpty, "Graph should not be empty");
            Assert.True(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.Equal(g, h);

            parser.Load(handler, "graph_handler_tests_temp.ttl");
            Assert.Equal(g.Triples.Count + 2, h.Triples.Count);
            Assert.NotEqual(g, h);

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples.Where(x => !x.IsGroundTriple))
            {
                Console.WriteLine(t.ToString(formatter));
            }
        }
Ejemplo n.º 3
0
        public void ParsingGraphHandlerExplicitMerging()
        {
            Graph g = new Graph();

            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile("temp.ttl");

            Graph        h       = new Graph();
            GraphHandler handler = new GraphHandler(h);

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");

            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.IsFalse(h.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.AreEqual(g, h, "Graphs should be equal");

            parser.Load(handler, "temp.ttl");
            Assert.AreEqual(g.Triples.Count + 2, h.Triples.Count, "Triples count should now be 2 higher due to the merge which will have replicated the 2 triples containing Blank Nodes");
            Assert.AreNotEqual(g, h, "Graphs should no longer be equal");

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples.Where(x => !x.IsGroundTriple))
            {
                Console.WriteLine(t.ToString(formatter));
            }
        }
        public void ParsingUriLoaderGraphHandlerExplicit()
        {
            Graph g = new Graph();
            GraphHandler handler = new GraphHandler(g);
            UriLoader.Load(handler, new Uri("http://www.dotnetrdf.org/configuration#"));

            TestTools.ShowGraph(g);
            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
        public void ParsingFileLoaderGraphHandlerExplicitTurtle()
        {
            EnsureTestData("temp.ttl");
            Graph g = new Graph();
            GraphHandler handler = new GraphHandler(g);
            FileLoader.Load(handler, "temp.ttl");

            TestTools.ShowGraph(g);
            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
Ejemplo n.º 6
0
        public void ParsingFileLoaderGraphHandlerExplicitTurtle()
        {
            Graph        g       = new Graph();
            GraphHandler handler = new GraphHandler(g);

            FileLoader.Load(handler, TestDataFile);

            TestTools.ShowGraph(g);
            Assert.False(g.IsEmpty, "Graph should not be empty");
        }
        public void ParsingUriLoaderGraphHandlerExplicit()
        {
            Graph        g       = new Graph();
            GraphHandler handler = new GraphHandler(g);

            UriLoader.Load(handler, new Uri("http://www.dotnetrdf.org/configuration#"));

            TestTools.ShowGraph(g);
            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
Ejemplo n.º 8
0
        private static IGraph Load(string source)
        {
            var result           = new Graph();
            var graphHandler     = new GraphHandler(result);
            var strippingHandler = new StripStringHandler(graphHandler);
            var parser           = new NTriplesParser();

            using (var reader = new StringReader(source))
            {
                parser.Load(strippingHandler, reader);
            }

            return(result);
        }
Ejemplo n.º 9
0
        public void ParsingGraphHandlerExplicitInitialBaseUri()
        {
            Graph g = new Graph();

            g.BaseUri = new Uri("http://example.org/");

            String       fragment = "<subject> <predicate> <object> .";
            TurtleParser parser   = new TurtleParser();
            GraphHandler handler  = new GraphHandler(g);

            parser.Load(handler, new StringReader(fragment));

            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.Equal(1, g.Triples.Count);
        }
Ejemplo n.º 10
0
        public void ParsingMultiHandlerGraphAndNull()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            NullHandler handler2 = new NullHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "multi_handler_tests_temp.ttl");
        }
Ejemplo n.º 11
0
        public void ParsingMultiHandlerGraphWithFactory()
        {
            EnsureTestData();

            Graph        g = new Graph();
            GraphHandler h = new GraphHandler(g);

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { h }, g);

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "multi_handler_tests_temp.ttl");

            Assert.Same(g, g.Triples.First().Graph);
        }
Ejemplo n.º 12
0
        public void ParsingChainedHandlerGraphAndNull()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            NullHandler handler2 = new NullHandler();

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");
        }
Ejemplo n.º 13
0
        public void ParsingChainedHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, handler2.Count, "Expected Counts to be the same");
        }
Ejemplo n.º 14
0
        public void ParsingMultiHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "multi_handler_tests_temp.ttl");

            Assert.Equal(g.Triples.Count, handler2.Count);
        }
Ejemplo n.º 15
0
        public void ParsingFileLoaderGraphHandlerExplicitTurtle()
        {
            Graph        g       = new Graph();
            GraphHandler handler = new GraphHandler(g);

#if PORTABLE
            using (var input = File.OpenRead(TestDataFile))
            {
                StreamLoader.Load(handler, TestDataFile, input);
            }
#else
            FileLoader.Load(handler, TestDataFile);
#endif

            TestTools.ShowGraph(g);
            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
Ejemplo n.º 16
0
        public void ParsingMultiHandlerTwoGraphs()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler handler1 = new GraphHandler(g);
            GraphHandler handler2 = new GraphHandler(h);

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Expected same number of Triples");
            Assert.AreEqual(g, h, "Expected Graphs to be equal");
        }
Ejemplo n.º 17
0
        public void ParsingChainedHandlerTwoGraphs()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler handler1 = new GraphHandler(g);
            GraphHandler handler2 = new GraphHandler(h);

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "chained_handler_tests_temp.ttl");

            Assert.Equal(g.Triples.Count, h.Triples.Count);
            Assert.Equal(g, h);
        }
Ejemplo n.º 18
0
        public void ParsingChainedHandlerTwoGraphs()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler handler1 = new GraphHandler(g);
            GraphHandler handler2 = new GraphHandler(h);

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Expected same number of Triples");
            Assert.AreEqual(g, h, "Expected Graphs to be equal");
        }
Ejemplo n.º 19
0
        public void ParsingMultiHandlerGraphAndPaging()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler handler1 = new GraphHandler(g);
            PagingHandler handler2 = new PagingHandler(new GraphHandler(h), 100);

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(101, g.Triples.Count, "Triples should have been limited to 101 (1st Graph)");
            Assert.AreEqual(100, h.Triples.Count, "Triples should have been limited to 100 (2nd Graph)");
            Assert.AreNotEqual(g.Triples.Count, h.Triples.Count, "Expected different number of Triples");
            Assert.AreNotEqual(g, h, "Expected Graphs to not be equal");
        }
Ejemplo n.º 20
0
        public void ParsingMultiHandlerGraphAndPaging()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler  handler1 = new GraphHandler(g);
            PagingHandler handler2 = new PagingHandler(new GraphHandler(h), 100);

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "multi_handler_tests_temp.ttl");

            Assert.Equal(101, g.Triples.Count);
            Assert.Equal(100, h.Triples.Count);
            Assert.NotEqual(g.Triples.Count, h.Triples.Count);
            Assert.NotEqual(g, h);
        }
Ejemplo n.º 21
0
        public void ParsingChainedHandlerGraphAndPaging()
        {
            EnsureTestData();

            Graph g = new Graph();
            Graph h = new Graph();

            GraphHandler  handler1 = new GraphHandler(g);
            PagingHandler handler2 = new PagingHandler(new GraphHandler(h), 100);

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(101, g.Triples.Count, "Triples should have been limited to 101 (1st Graph)");
            Assert.AreEqual(100, h.Triples.Count, "Triples should have been limited to 100 (2nd Graph)");
            Assert.AreNotEqual(g.Triples.Count, h.Triples.Count, "Expected different number of Triples");
            Assert.AreNotEqual(g, h, "Expected Graphs to not be equal");
        }
Ejemplo n.º 22
0
        public void ParsingUsingGraphHandlerExplicitTest(String tempFile, IRdfReader parser, bool nsCheck)
        {
            Graph g = new Graph();
            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile(tempFile);

            Graph h = new Graph();
            GraphHandler handler = new GraphHandler(h);
            parser.Load(handler, tempFile);

            NTriplesFormatter formatter = new NTriplesFormatter();
            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.IsFalse(h.IsEmpty, "Graph should not be empty");
            if (nsCheck) Assert.IsTrue(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.AreEqual(g, h, "Graphs should be equal");
        }
Ejemplo n.º 23
0
        public void ParsingMultiHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph g = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, handler2.Count, "Expected Counts to be the same");
 
        }
Ejemplo n.º 24
0
        public void ParsingMultiHandlerBadInstantiation4()
        {
            GraphHandler h = new GraphHandler(new Graph());

            Assert.Throws <ArgumentNullException>(() => new MultiHandler(new IRdfHandler[] { h }, null));
        }
Ejemplo n.º 25
0
 public void ParsingMultiHandlerBadInstantiation3()
 {
     GraphHandler h = new GraphHandler(new Graph());
     MultiHandler handler = new MultiHandler(new IRdfHandler[] { h, h });
 }
Ejemplo n.º 26
0
        public void ParsingGraphHandlerExplicitMerging()
        {
            Graph g = new Graph();
            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile("temp.ttl");

            Graph h = new Graph();
            GraphHandler handler = new GraphHandler(h);

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");

            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.IsFalse(h.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace");
            Assert.AreEqual(g, h, "Graphs should be equal");

            parser.Load(handler, "temp.ttl");
            Assert.AreEqual(g.Triples.Count + 2, h.Triples.Count, "Triples count should now be 2 higher due to the merge which will have replicated the 2 triples containing Blank Nodes");
            Assert.AreNotEqual(g, h, "Graphs should no longer be equal");

            NTriplesFormatter formatter = new NTriplesFormatter();
            foreach (Triple t in h.Triples.Where(x => !x.IsGroundTriple))
            {
                Console.WriteLine(t.ToString(formatter));
            }
        }
Ejemplo n.º 27
0
        public void ParsingGraphHandlerExplicitInitialBaseUri()
        {
            Graph g = new Graph();
            g.BaseUri = new Uri("http://example.org/");

            String fragment = "<subject> <predicate> <object> .";
            TurtleParser parser = new TurtleParser();
            GraphHandler handler = new GraphHandler(g);
            parser.Load(handler, new StringReader(fragment));

            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
            Assert.AreEqual(1, g.Triples.Count, "Expected 1 Triple to be parsed");
        }
Ejemplo n.º 28
0
        public void ParsingChainedHandlerBadInstantiation3()
        {
            GraphHandler h = new GraphHandler(new Graph());

            Assert.Throws <ArgumentException>(() => new ChainedHandler(new IRdfHandler[] { h, h }));
        }
Ejemplo n.º 29
0
 public void ParsingMultiHandlerBadInstantiation3()
 {
     GraphHandler h       = new GraphHandler(new Graph());
     MultiHandler handler = new MultiHandler(new IRdfHandler[] { h, h });
 }
Ejemplo n.º 30
0
        public void ParsingMultiHandlerGraphAndNull()
        {
            EnsureTestData();

            Graph g = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            NullHandler handler2 = new NullHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");
        }
Ejemplo n.º 31
0
 public void ParsingChainedHandlerBadInstantiation3()
 {
     GraphHandler   h       = new GraphHandler(new Graph());
     ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { h, h });
 }