Ejemplo n.º 1
0
        public void StorageVirtuosoNativeUpdate()
        {
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                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);
            }
            catch (RdfQueryException queryEx)
            {
                TestTools.ReportError("RDF Query Error", queryEx, true);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
Ejemplo n.º 2
0
        public void StorageVirtuosoNativeQuery()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                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("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
                result = manager.Query("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");
                CheckQueryResult(result, true);

                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
                result = manager.Query("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");
                CheckQueryResult(result, true);

                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);
            }
            catch (RdfQueryException queryEx)
            {
                TestTools.ReportError("RDF Query Error", queryEx, true);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }