コード例 #1
0
ファイル: TestManifest.cs プロジェクト: GTuritto/BrightstarDB
 private static void ProcessIncludes(Graph g)
 {
     var includeTriple =
         g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")).
             FirstOrDefault();
     while(includeTriple != null) {
         if (includeTriple.Object.NodeType == NodeType.Blank)
         {
             ProcessList(includeTriple.Object, g, ProcessInclude);
         }
         else
         {
             ProcessInclude(includeTriple.Object, g);
         }
         g.Retract(includeTriple);
         includeTriple = g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")).
             FirstOrDefault();
     }
 }
コード例 #2
0
        public static void Main(String[] args)
        {
            StreamWriter output  = new StreamWriter("AllegroGraphTest.txt");
            Console.SetOut(output);
            try
            {
                Console.WriteLine("## AllegroGraph Test");
                Console.WriteLine();

                //Load the Graph we want to use as a Test
                Graph g = new Graph();
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");
                Console.WriteLine("Test Graph contains the following Triples:");
                ShowGraph(g);
                Console.WriteLine();

                //Load another Graph
                Graph h = new Graph();
                h.BaseUri = new Uri("http://example.org/test");
                Notation3Parser n3parser = new Notation3Parser();
                n3parser.Load(h, "test.n3");
                Console.WriteLine("Second Test Graph contains the following Triples:");
                ShowGraph(h);
                Console.WriteLine();

                Console.WriteLine("Trying to create a test store in the test catalog");
                AllegroGraphConnector agraph = new AllegroGraphConnector("http://localhost:9875/", "test", "test");
                Console.WriteLine("Store Created OK");
                Console.WriteLine();

                Console.WriteLine("Trying to add data to the Store");
                agraph.SaveGraph(g);
                agraph.SaveGraph(h);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                Console.WriteLine("Trying to load data from the Store");
                Graph i = new Graph();
                agraph.LoadGraph(i, String.Empty);
                ShowGraph(i);
                Console.WriteLine();
                i = new Graph();
                agraph.LoadGraph(i, new Uri("http://example.org/test"));
                ShowGraph(i);
                Console.WriteLine("Loaded OK");
                Console.WriteLine();

                Console.WriteLine("Trying to update data in the Store");
                List<Triple> toRemove = g.GetTriplesWithPredicate(g.CreateUriNode("rdf:type")).ToList();
                Triple toAdd = new Triple(g.CreateUriNode(new Uri("http://example.org/")), g.CreateUriNode("rdf:type"), g.CreateLiteralNode("Added Triple Test"));
                agraph.UpdateGraph(String.Empty, new List<Triple>() { toAdd }, toRemove);
                Console.WriteLine("Updated OK");
                Console.WriteLine();

                Console.WriteLine("Trying a SPARQL ASK query against the store");
                Object results = agraph.Query("ASK WHERE {?s ?p ?o}");
                Console.WriteLine("Got results OK");
                ShowResults(results);
                Console.WriteLine();

                Console.WriteLine("Trying a SPARQL SELECT query against the store");
                results = agraph.Query("SELECT * WHERE {?s ?p ?o}");
                Console.WriteLine("Got results OK");
                ShowResults(results);
                Console.WriteLine();

            }
            catch (RdfStorageException storeEx)
            {
                reportError(output, "RDF Storage Error", storeEx);
            }
            catch (RdfParseException parseEx)
            {
                reportError(output, "RDF Parsing Error", parseEx);
            }
            catch (RdfQueryException queryEx)
            {
                reportError(output, "RDF Query Error", queryEx);
            }
            catch (RdfException rdfEx)
            {
                reportError(output, "RDF Error", rdfEx);
            }
            catch (WebException webEx)
            {
                reportError(output, "HTTP Error", webEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Error", ex);
            }
            finally
            {
                output.Close();
            }
        }