private void ParsingStoreHandlerNQuadsImplicitActual()
        {
            this.EnsureTestData("test.nq");

            TripleStore store = new TripleStore();

            NQuadsParser parser = new NQuadsParser();

            parser.Load(store, "test.nq");

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/configuration#")), "Configuration Vocab Graph should have been parsed from Dataset");
            Graph configOrig = new Graph();

            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            IGraph config = store[new Uri("http://www.dotnetrdf.org/configuration#")];

            Assert.AreEqual(configOrig, config, "Configuration Vocab Graphs should have been equal");

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/leviathan#")), "Leviathan Function Library Graph should have been parsed from Dataset");
            Graph lvnOrig = new Graph();

            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            IGraph lvn = store[new Uri("http://www.dotnetrdf.org/leviathan#")];

            Assert.AreEqual(lvnOrig, lvn, "Leviathan Function Library Graphs should have been equal");
        }
Beispiel #2
0
        public void SparqlUpdateTimeout()
        {
            String update = "CREATE GRAPH <http://example.org/1>; LOAD <http://www.dotnetrdf.org/configuration#>; CREATE GRAPH <http://example.org/2>";
            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(update);

            cmds.Timeout = 1;

            TripleStore store = new TripleStore();
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Expected a SparqlUpdateTimeoutException");
            }
            catch (SparqlUpdateTimeoutException timeoutEx)
            {
                TestTools.ReportError("Timeout", timeoutEx);
                Console.WriteLine();
                Console.WriteLine("Execution Time: " + cmds.UpdateExecutionTime.Value.ToString());

                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/1")), "Graph 1 should not exist");
                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/2")), "Graph 2 should not exist");
            }
        }
Beispiel #3
0
        public void ParsingStoreHandlerTriXExplicit()
        {
            this.EnsureTestData("test.xml");

            TripleStore store = new TripleStore();

            TriXParser parser = new TriXParser();

            parser.Load(new StoreHandler(store), "test.xml");

            Assert.IsTrue(store.HasGraph(new Uri("http://graphs/1")), "Configuration Vocab Graph should have been parsed from Dataset");
            Graph configOrig = new Graph();

            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            IGraph config = store[new Uri("http://graphs/1")];

            Assert.AreEqual(configOrig, config, "Configuration Vocab Graphs should have been equal");

            Assert.IsTrue(store.HasGraph(new Uri("http://graphs/2")), "Leviathan Function Library Graph should have been parsed from Dataset");
            Graph lvnOrig = new Graph();

            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            IGraph lvn = store[new Uri("http://graphs/2")];

            Assert.AreEqual(lvnOrig, lvn, "Leviathan Function Library Graphs should have been equal");
        }
 /// <summary>
 /// Gets a Graph from the Dataset.
 /// </summary>
 /// <param name="graphUri">Graph URI.</param>
 /// <returns></returns>
 /// <remarks>
 /// If the Graph has been modified during the active Transaction the modified version is returned rather than the original version.
 /// </remarks>
 public sealed override IGraph this[Uri graphUri]
 {
     get
     {
         if (graphUri == null)
         {
             if (InternalDefaultGraph != null)
             {
                 return(InternalDefaultGraph);
             }
             else if (_modifiableGraphs.HasGraph(graphUri))
             {
                 return(_modifiableGraphs[graphUri]);
             }
             else
             {
                 return(GetGraphInternal(null));
             }
         }
         else if (_modifiableGraphs.HasGraph(graphUri))
         {
             return(_modifiableGraphs[graphUri]);
         }
         else
         {
             return(GetGraphInternal(graphUri));
         }
     }
 }
 /// <summary>
 /// Removes model from the store.
 /// </summary>
 /// <param name="uri">Uri of the model which is to be removed.</param>
 public override void RemoveModel(Uri uri)
 {
     if (_store.HasGraph(uri))
     {
         _store.Remove(uri);
     }
 }
        private bool AreEqual(TripleStore expected, TripleStore actual)
        {
            if (expected.Graphs.Count != actual.Graphs.Count)
            {
                Console.WriteLine("Expected " + expected.Graphs.Count + " graphs but got " + actual.Graphs.Count);
                return(false);
            }

            foreach (Uri u in expected.Graphs.GraphUris)
            {
                if (!actual.HasGraph(u))
                {
                    Console.WriteLine("Expected Graph " + VDS.RDF.Extensions.ToSafeString(u) + " missing");
                    return(false);
                }
                GraphDiffReport diff = expected[u].Difference(actual[u]);
                if (!diff.AreEqual)
                {
                    Console.WriteLine("Expected Graph " + VDS.RDF.Extensions.ToSafeString(u) + " not as expected");
                    TestTools.ShowDifferences(diff);
                    return(false);
                }
            }

            return(true);
        }
        public void JsonLdParserTests(string inputPath, string contextPath, string expectedOutputPath, string baseIri,
                                      string processorMode, string expandContextPath, bool compactArrays)
        {
            var processorOptions = MakeProcessorOptions(inputPath, baseIri, processorMode, expandContextPath,
                                                        compactArrays);
            var contextJson    = contextPath == null ? null : File.ReadAllText(contextPath);
            var contextElement = contextJson == null ? null : JToken.Parse(contextJson);
            var nqParser       = new NQuadsParser(NQuadsSyntax.Rdf11);
            var expectedStore  = new TripleStore();

            nqParser.Load(expectedStore, expectedOutputPath);
            FixStringLiterals(expectedStore);
            var jsonldParser = new JsonLdParser(processorOptions);
            var actualStore  = new TripleStore();

            jsonldParser.Load(actualStore, inputPath);
            Assert.True(expectedStore.Graphs.Count.Equals(actualStore.Graphs.Count),
                        $"Test failed for input {Path.GetFileName(inputPath)}.\r\nActual graph count {actualStore.Graphs.Count} does not match expected graph count {expectedStore.Graphs.Count}.");
            foreach (var expectGraph in expectedStore.Graphs)
            {
                Assert.True(actualStore.HasGraph(expectGraph.BaseUri),
                            $"Test failed for input {Path.GetFileName(inputPath)}.\r\nCould not find expected graph {expectGraph.BaseUri}");
                var actualGraph  = actualStore.Graphs[expectGraph.BaseUri];
                var bNodeMapping = new Dictionary <INode, INode>();
                var graphsEqual  = actualGraph.Equals(expectGraph, out bNodeMapping);
                if (!graphsEqual)
                {
                    var    ser           = new NQuadsWriter();
                    string expectedLines = MakeNQuadsList(expectedStore);
                    string actualLines   = MakeNQuadsList(actualStore);
                    Assert.True(graphsEqual,
                                $"Test failed for input {Path.GetFileName(inputPath)}.\r\nGraph {expectGraph.BaseUri} differs in actual output from expected output.\r\nExpected:\r\n{expectedLines}\r\nActual:\r\n{actualLines}");
                }
            }
        }
        public void GraphCollectionBasic1()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            store.Add(g);

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreEqual(g, store[g.BaseUri], "Graphs should be equal");
        }
        internal static void ExtractTestData(string name, out IGraph testGraph, out bool failure, out IGraph dataGraph, out IGraph shapesGraph)
        {
            testGraph = store[new Uri(baseUri, name)];

            var entries        = testGraph.GetTriplesWithPredicate(mf_entries).Single().Object;
            var entry          = testGraph.GetListItems(entries).Single();
            var action         = testGraph.GetTriplesWithSubjectPredicate(entry, mf_action).Single().Object;
            var dataGraphUri   = ((IUriNode)testGraph.GetTriplesWithSubjectPredicate(action, sht_dataGraph).Single().Object).Uri;
            var shapesGraphUri = ((IUriNode)testGraph.GetTriplesWithSubjectPredicate(action, sht_shapesGraph).Single().Object).Uri;
            var result         = testGraph.GetTriplesWithSubjectPredicate(entry, mf_result).Single().Object;

            failure = result.Equals(sht_Failure);

            store.HasGraph(dataGraphUri);
            dataGraph = store[dataGraphUri];

            store.HasGraph(shapesGraphUri);
            shapesGraph = store[shapesGraphUri];
        }
        public void GraphCollectionDiskDemand1()
        {
            TripleStore store = new TripleStore(new DiskDemandGraphCollection());
            Graph       g     = new Graph();

            g.LoadFromFile("InferenceTest.ttl");
            g.BaseUri = new Uri("file:///" + Path.GetFullPath("InferenceTest.ttl"));

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreEqual(g, store[g.BaseUri], "Graphs should be equal");
        }
        public void GraphCollectionBasic2()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

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

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreEqual(g, store[g.BaseUri], "Graphs should be equal");
        }
        public void GraphCollectionWebDemand1()
        {
            TripleStore store = new TripleStore(new WebDemandGraphCollection());
            Graph       g     = new Graph();
            Uri         u     = new Uri("http://www.dotnetrdf.org/configuration#");

            g.LoadFromUri(u);
            g.BaseUri = u;

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreEqual(g, store[g.BaseUri], "Graphs should be equal");
        }
        /// <summary>
        /// Loads a Graph from the Dataset with the given Handler.
        /// </summary>
        /// <param name="handler">RDF Handler.</param>
        /// <param name="graphUri">URI of the Graph to load.</param>
        public override void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;

            if (graphUri == null)
            {
                if (_store.HasGraph(graphUri))
                {
                    g = _store[graphUri];
                }
            }
            else if (_store.HasGraph(graphUri))
            {
                g = _store[graphUri];
            }

            if (g == null)
            {
                return;
            }
            handler.Apply(g);
        }
 /// <summary>
 /// Gets a Graph from the dataset
 /// </summary>
 /// <param name="graphUri">Graph URI</param>
 /// <returns></returns>
 public override IGraph this[Uri graphUri]
 {
     get
     {
         if (graphUri == null)
         {
             if (DefaultGraphUris.Any())
             {
                 if (DefaultGraphUris.Count() == 1)
                 {
                     return(new Graph(new QuadDatasetTripleCollection(this, DefaultGraphUris.First())));
                 }
                 else
                 {
                     IEnumerable <IGraph> gs = (from u in DefaultGraphUris
                                                select new Graph(new QuadDatasetTripleCollection(this, u))).OfType <IGraph>();
                     return(new UnionGraph(gs.First(), gs.Skip(1)));
                 }
             }
             else if (_modifiableGraphs.HasGraph(graphUri))
             {
                 return(_modifiableGraphs[graphUri]);
             }
             else
             {
                 return(GetGraphInternal(null));
             }
         }
         else if (_modifiableGraphs.HasGraph(graphUri))
         {
             return(_modifiableGraphs[graphUri]);
         }
         else
         {
             return(GetGraphInternal(graphUri));
         }
     }
 }
        private void ParsingStoreHandlerNQuadsImplicitActual()
        {
            this.EnsureTestData("test.nq");

            TripleStore store = new TripleStore();
            StreamParams ps = new StreamParams("test.nq", Encoding.ASCII);

            NQuadsParser parser = new NQuadsParser();
            parser.Load(store, ps);

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/configuration#")), "Configuration Vocab Graph should have been parsed from Dataset");
            Graph configOrig = new Graph();
            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            IGraph config = store.Graph(new Uri("http://www.dotnetrdf.org/configuration#"));
            Assert.AreEqual(configOrig, config, "Configuration Vocab Graphs should have been equal");

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/leviathan#")), "Leviathan Function Library Graph should have been parsed from Dataset");
            Graph lvnOrig = new Graph();
            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");
            IGraph lvn = store.Graph(new Uri("http://www.dotnetrdf.org/leviathan#"));
            Assert.AreEqual(lvnOrig, lvn, "Leviathan Function Library Graphs should have been equal");

        }
        public void SparqlUpdateTimeout()
        {
            String update = "CREATE GRAPH <http://example.org/1>; LOAD <http://www.dotnetrdf.org/configuration#>; CREATE GRAPH <http://example.org/2>";
            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(update);
            cmds.Timeout = 1;

            TripleStore store = new TripleStore();
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Expected a SparqlUpdateTimeoutException");
            }
            catch (SparqlUpdateTimeoutException timeoutEx)
            {
                TestTools.ReportError("Timeout", timeoutEx, false);
                Console.WriteLine();
                Console.WriteLine("Execution Time: " + cmds.UpdateExecutionTime.Value.ToString());

                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/1")), "Graph 1 should not exist");
                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/2")), "Graph 2 should not exist");

            }
        }
        public void GraphCollectionDiskDemand2()
        {
            //Test that on-demand loading does not kick in for pre-existing graphs
            TripleStore store = new TripleStore(new DiskDemandGraphCollection());

            Graph g = new Graph();

            g.LoadFromFile("InferenceTest.ttl");
            g.BaseUri = new Uri("file:///" + Path.GetFullPath("InferenceTest.ttl"));

            Graph empty = new Graph();

            empty.BaseUri = g.BaseUri;
            store.Add(empty);

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreNotEqual(g, store[g.BaseUri], "Graphs should not be equal");
        }
        private void TestWriter(IStoreWriter writer, IStoreReader reader, bool useMultiThreaded, int compressionLevel)
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            store.Add(g);
            g = new Graph();
            g.LoadFromFile("resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/graph");
            store.Add(g);
            g = new Graph();
            g.LoadFromFile(@"resources\cyrillic.rdf");
            g.BaseUri = new Uri("http://example.org/cyrillic");
            store.Add(g);

            if (writer is ICompressingWriter)
            {
                ((ICompressingWriter)writer).CompressionLevel = compressionLevel;
            }
#if !NETCOREAPP2_0
            if (writer is IMultiThreadedWriter)
            {
                ((IMultiThreadedWriter)writer).UseMultiThreadedWriting = useMultiThreaded;
            }
#endif
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            writer.Save(store, strWriter);

            Console.WriteLine(strWriter.ToString());

            Assert.NotEqual(strWriter.ToString(), String.Empty);

            TripleStore store2 = new TripleStore();
            reader.Load(store2, new System.IO.StringReader(strWriter.ToString()));

            foreach (IGraph graph in store.Graphs)
            {
                Assert.True(store2.HasGraph(graph.BaseUri), "Parsed Stored should have contained serialized graph");
                Assert.Equal(graph, store2[graph.BaseUri]);
            }
        }
        public void GraphCollectionWebDemand2()
        {
            //Test that on-demand loading does not kick in for pre-existing graphs
            TripleStore store = new TripleStore(new WebDemandGraphCollection());

            Graph g = new Graph();
            Uri   u = new Uri("http://www.dotnetrdf.org/configuration#");

            g.LoadFromUri(u);
            g.BaseUri = u;

            Graph empty = new Graph();

            empty.BaseUri = g.BaseUri;
            store.Add(empty);

            Assert.IsTrue(store.HasGraph(g.BaseUri), "Graph Collection should contain the Graph");
            Assert.AreNotEqual(g, store[g.BaseUri], "Graphs should not be equal");
        }
        private void TestWriter(IStoreWriter writer, IStoreReader reader, bool useMultiThreaded, int compressionLevel)
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            store.Add(g);
            g = new Graph();
            g.LoadFromFile("InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/graph");
            store.Add(g);

            if (writer is ICompressingWriter)
            {
                ((ICompressingWriter)writer).CompressionLevel = compressionLevel;
            }
            if (writer is IMultiThreadedWriter)
            {
                ((IMultiThreadedWriter)writer).UseMultiThreadedWriting = useMultiThreaded;
            }
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            writer.Save(store, strWriter);

            Console.WriteLine(strWriter.ToString());

            Assert.IsFalse(strWriter.ToString().Equals(String.Empty));

            TripleStore store2 = new TripleStore();

            reader.Load(store2, new System.IO.StringReader(strWriter.ToString()));

            foreach (IGraph graph in store.Graphs)
            {
                Assert.IsTrue(store2.HasGraph(graph.BaseUri), "Parsed Stored should have contained serialized graph");
                Assert.AreEqual(graph, store2[graph.BaseUri], "Parsed Graph should be equal to original graph");
            }
        }
Beispiel #21
0
        public void SparqlUpdateMoveCommand3()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

            IGraph h = new Graph();

            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store.HasGraph(null) ? store[null] : null;
            h = store[new Uri("http://example.org/destination")];
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsFalse(g == null, "Default Graph should still exist");
            Assert.IsTrue(g.IsEmpty, "Source Graph (the Default Graph) should be Empty");

            Graph orig = new Graph();

            FileLoader.Load(orig, "InferenceTest.ttl");
            Assert.AreEqual(orig, h, "Destination Graph should be equal to the original contents of the Source Graph");
        }
Beispiel #22
0
        public void SparqlUpdateMoveCommand2()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();

            FileLoader.Load(h, "resources\\Turtle.ttl");
            h.BaseUri = null;

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

            Assert.NotEqual(g, h);

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE GRAPH <http://example.org/source> TO DEFAULT");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store.HasGraph(new Uri("http://example.org/source")) ? store[new Uri("http://example.org/source")] : null;
            h = store[null];
            Assert.False(h.IsEmpty, "Destination Graph should not be empty");
            Assert.True(g == null || g.IsEmpty, "Source Graph should be Deleted/Empty");

            Graph orig = new Graph();

            FileLoader.Load(orig, "resources\\InferenceTest.ttl");
            Assert.Equal(orig, h);
        }
Beispiel #23
0
 public void ThenTheBaseURIIsLoaded()
 {
     graph2.BaseUri   = new Uri("file:///" + Path.GetFullPath("resources\\InferenceTest.ttl"));
     isthesecondadded = triplestore2.HasGraph(graph2.BaseUri);
 }
Beispiel #24
0
 public bool ContainsModel(Uri uri)
 {
     return(_store.HasGraph(uri));
 }
 /**
  * Checks whether the repository is ready to use, e.g. it contains the genesis Block.
  *
  * @return <code>true</code> if the repository is ready to use, <code>false</code> otherwise
  */
 public bool IsReadyToUse()
 {
     return(_repository.HasGraph(new Uri(_chainGraphIri)));
 }
Beispiel #26
0
 public void ThenAddedToStrore()
 {
     triplestore.Add(graph);
     isadded = triplestore.HasGraph(graph.BaseUri);
 }
Beispiel #27
0
        public void SparqlUpdateMoveCommand3()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

            IGraph h = new Graph();
            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();
            store.Add(g);
            store.Add(h);

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.HasGraph(null) ? store.Graph(null) : null;
            h = store.Graph(new Uri("http://example.org/destination"));
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsFalse(g == null, "Default Graph should still exist");
            Assert.IsTrue(g.IsEmpty, "Source Graph (the Default Graph) should be Empty");

            Graph orig = new Graph();
            FileLoader.Load(orig, "InferenceTest.ttl");
            Assert.AreEqual(orig, h, "Destination Graph should be equal to the original contents of the Source Graph");
        }