Esempio 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();
                }
            }
        }
Esempio n. 2
0
        public void StorageVirtuosoNativeUpdate()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                Assert.IsNotNull(manager);

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

                Object result = null;
                Console.WriteLine("Now we'll delete a Triple");

                //Try a DELETE DATA
                manager.Update("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");

                Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll add the Triple back again");

                //Try a INSERT DATA
                manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");

                Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Esempio 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();
                }
            }
        }
Esempio n. 4
0
        public void StorageVirtuosoQueryRegex()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                //Create the Test Graph
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/VirtuosoRegexTest");
                INode subj1 = g.CreateUriNode(new Uri("http://example.org/one"));
                INode subj2 = g.CreateUriNode(new Uri("http://example.org/two"));
                INode pred  = g.CreateUriNode(new Uri("http://example.org/predicate"));
                INode obj1  = g.CreateLiteralNode("search term");
                INode obj2  = g.CreateLiteralNode("no term");
                g.Assert(subj1, pred, obj1);
                g.Assert(subj2, pred, obj2);
                manager.SaveGraph(g);

                Graph h = new Graph();
                manager.LoadGraph(h, g.BaseUri);
                Assert.AreEqual(g, h, "Graphs should be equal");

                String          query   = "SELECT * FROM <" + g.BaseUri.ToString() + "> WHERE { ?s ?p ?o . FILTER(REGEX(STR(?o), 'search', 'i')) }";
                SparqlResultSet results = manager.Query(query) as SparqlResultSet;
                if (results == null)
                {
                    Assert.Fail("Did not get a Result Set as expected");
                }
                Console.WriteLine("Results obtained via VirtuosoManager.Query()");
                TestTools.ShowResults(results);
                Assert.AreEqual(1, results.Count);

                SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://localhost:8890/sparql"));
                SparqlResultSet      results2 = endpoint.QueryWithResultSet(query);
                Console.WriteLine("Results obtained via SparqlRemoteEndpoint.QueryWithResultSet()");
                TestTools.ShowResults(results2);
                Assert.AreEqual(1, results2.Count);
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Esempio n. 5
0
        public void StorageVirtuosoBadQuery()
        {
            VirtuosoManager virtuoso = VirtuosoTest.GetConnection();

            try
            {
                virtuoso.Query("Bad query");
                Assert.Fail("Expected an error");
            }
            catch
            {
                //Expected so can be ignored
                Assert.IsFalse(virtuoso.HasOpenConnection, "Connection should be closed");
                Assert.IsFalse(virtuoso.HasActiveTransaction, "Should be no active transaction");
            }
            finally
            {
                virtuoso.Dispose();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// overload of Execute query
        /// </summary>
        /// <param name="input">the query text as string</param>
        /// <returns></returns>
        public static SparqlResultSet ExecuteQueryWithString(string input)
        {
            //list to hold the results
            SparqlResultSet resultSet = new SparqlResultSet();

            try
            {
                //just in cas someone didn't open the connection
                if (!isConnectionStarted)
                {
                    startConnection();
                }

                //making the query
                Object result = manager.Query(input);
                //Object result = manager.ExecuteQuery(input);
                resultSet = (SparqlResultSet)result;
            }
            catch {
            }
            return(resultSet);
        }
Esempio n. 7
0
        public void StorageVirtuosoNativeQueryBifContains2()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                Assert.IsNotNull(manager);

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

                Object result = null;

                //Try a CONSTRUCT query
                result = manager.Query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?o bif:contains 'example' }");
                CheckQueryResult(result, false);
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Esempio n. 8
0
        public void StorageVirtuosoNativeQueryAndUpdate()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            VirtuosoManager   manager   = VirtuosoTest.GetConnection();

            try
            {
                Assert.IsNotNull(manager);

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

                Object result = null;

                Console.WriteLine("ASKing if there's any Triples");

                //Try an ASK query
                result = manager.Query("ASK {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("CONSTRUCTing a Graph");

                //Try a CONSTRUCT
                result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, false);

                Console.WriteLine("DESCRIBEing a resource");

                //Try a DESCRIBE
                result = manager.Query("DESCRIBE <http://example.org/one>");
                CheckQueryResult(result, false);

                //Try another DESCRIBE
                result = manager.Query("DESCRIBE <http://example.org/noSuchThing>");
                CheckQueryResult(result, false);

                Console.WriteLine("SELECTing the same Graph");

                //Try a SELECT query
                result = manager.Query("SELECT * FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("SELECTing the same Graph using Project Expressions");

                //Try a SELECT query
                result = manager.Query("SELECT (?s AS ?Subject) (?P as ?Predicate) (?o AS ?Object) FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll delete a Triple");

                //Try a DELETE DATA
                manager.Update("DELETE DATA { GRAPH <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".} }");
                Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll add the Triple back again");

                //Try a INSERT DATA
                manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");
                Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("DESCRIBE things which are classes");

                //Try a DESCRIBE
                result = manager.Query("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?s WHERE {?s a rdfs:Class} LIMIT 1");
                CheckQueryResult(result, false);

                Console.WriteLine("Another CONSTRUCT");

                //Try a CONSTRUCT
                result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, false);

                Console.WriteLine("COUNT subjects");

                //Try a SELECT using an aggregate function
                result = manager.Query("SELECT COUNT(?s) FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("AVG integer objects");

                //Try another SELECT using an aggregate function
                result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3.org/2001/XMLSchema#integer>)}");
                CheckQueryResult(result, true);

                Console.WriteLine("AVG decimal objects");

                //Try yet another SELECT using an aggregate function
                result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3c.org/2001/XMLSchema#decimal>)}");
                CheckQueryResult(result, true);
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }