Ejemplo n.º 1
0
        public void StorageVirtuosoBlankNodeInsert()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                Graph  g = new Graph();
                Triple t = new Triple(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(UriFactory.Create("http://example.org/object")));

                manager.UpdateGraph("http://localhost/insertBNodeTest", t.AsEnumerable(), null);

                Object results = manager.Query("ASK WHERE { GRAPH <http://localhost/insertBNodeTest> { ?s a <http:///example.org/object> } }");
                if (results is SparqlResultSet)
                {
                    TestTools.ShowResults(results);
                    Assert.IsTrue(((SparqlResultSet)results).Result, "Expected a true result");
                }
                else
                {
                    Assert.Fail("Didn't get a SPARQL Result Set as expected");
                }
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        private Uri ReadQuadFormat(TextReader reader, Uri graph, RdfSerializationFormat format, bool update)
        {
            using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString()))
            {
                using (VDS.RDF.ThreadSafeTripleStore store = new VDS.RDF.ThreadSafeTripleStore())
                {
                    VDS.RDF.Parsing.TriGParser parser = new TriGParser();

                    parser.Load(store, reader);

                    foreach (var g in store.Graphs)
                    {
                        if (update)
                        {
                            manager.UpdateGraph(g.BaseUri, g.Triples, new Triple[] { });
                        }
                        else
                        {
                            manager.SaveGraph(g);
                        }
                    }
                }
            }

            return(graph);
        }
Ejemplo n.º 3
0
        public void StorageVirtuosoBlankNodeDelete()
        {
            //First ensure data is present in the store
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                manager.DeleteGraph("http://localhost/deleteBNodeTest");
                Graph  g = new Graph();
                Triple t = new Triple(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(UriFactory.Create("http://example.org/object")));
                g.Assert(t);

                manager.UpdateGraph("http://localhost/deleteBNodeTest", t.AsEnumerable(), null);

                Object results = manager.Query("ASK WHERE { GRAPH <http://localhost/deleteBNodeTest> { ?s a <http://example.org/object> } }");
                if (results is SparqlResultSet)
                {
                    TestTools.ShowResults(results);
                    Assert.IsTrue(((SparqlResultSet)results).Result, "Expected a true result");

                    //Now we've ensured data is present we can first load the graph and then try to delete the given triple
                    Graph h = new Graph();
                    manager.LoadGraph(h, "http://localhost/deleteBNodeTest");
                    Assert.AreEqual(g, h, "Graphs should be equal");

                    //Then we can go ahead and delete the triples from this graph
                    manager.UpdateGraph("http://localhost/deleteBNodeTest", null, h.Triples);
                    Graph i = new Graph();
                    manager.LoadGraph(i, "http://localhost/deleteBNodeTest");
                    Assert.IsTrue(i.IsEmpty, "Graph should be empty");
                    Assert.AreNotEqual(h, i);
                    Assert.AreNotEqual(g, i);
                }
                else
                {
                    Assert.Fail("Didn't get a SPARQL Result Set as expected");
                }
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        public void StorageVirtuosoUpdateGraph()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Make some Triples to add to the Graph
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/");
                g.NamespaceMap.AddNamespace(String.Empty, g.BaseUri);

                List <Triple> additions = new List <Triple>();
                additions.Add(new Triple(g.CreateUriNode(":seven"), g.CreateUriNode("rdf:type"), g.CreateUriNode(":addedTriple")));
                List <Triple> removals = new List <Triple>();
                removals.Add(new Triple(g.CreateUriNode(":five"), g.CreateUriNode(":property"), g.CreateUriNode(":value")));

                //Try to Update
                manager.UpdateGraph(g.BaseUri, additions, removals);

                Console.WriteLine("Updated OK");

                //Retrieve to see what's in the Graph
                Graph h = new Graph();
                manager.LoadGraph(h, g.BaseUri);

                Console.WriteLine("Retrieved OK");
                Console.WriteLine("Graph contents are:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Assert.IsTrue(h.Triples.Contains(additions[0]), "Added Triple should be in the retrieved Graph");
                Assert.IsFalse(h.Triples.Contains(removals[0]), "Removed Triple should not be in the retrieved Graph");
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
        private Uri ReadTripleFormat(TextReader reader, Uri graphUri, RdfSerializationFormat format, bool update)
        {
            using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString()))
            {
                using (VDS.RDF.Graph graph = new VDS.RDF.Graph())
                {
                    dotNetRDFStore.TryParse(reader, graph, format);

                    graph.BaseUri = graphUri;

                    if (update)
                    {
                        manager.UpdateGraph(graphUri, graph.Triples, new Triple[] { });
                    }
                    else
                    {
                        manager.SaveGraph(graph);
                    }
                }
            }

            return(graphUri);
        }