public void InteropSemWebInMemoryStoreConversion() { //Set up a Store and load 3 Graphs into it TripleStore store = new TripleStore(); Graph g = new Graph(); FileLoader.Load(g, "InferenceTest.ttl"); store.Add(g); g = new Graph(); FileLoader.Load(g, "Turtle.ttl"); store.Add(g); g = new Graph(); g.Assert(new Triple(g.CreateUriNode(new Uri("http://example.org/#this")), g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), g.CreateUriNode(new Uri("http://example.org/Graph")))); store.Add(g); InMemoryStoreSource source = new InMemoryStoreSource(store); //Put this all into a SemWeb MemoryStore MemoryStore mem = new MemoryStore(); source.Select(mem); SemWebConsolePrinter printer = new SemWebConsolePrinter(); mem.Select(printer); //Read it back into a dotNetRDF TripleStore InMemoryStoreSource source2 = new InMemoryStoreSource(new TripleStore()); mem.Select(source2); //Check the two stores are equivalent IInMemoryQueryableStore store2 = source2.Store; foreach (IGraph graph in store.Graphs) { String baseUri = (graph.BaseUri == null) ? String.Empty : graph.BaseUri.ToString(); Assert.IsTrue(store2.HasGraph(graph.BaseUri), "Second Store has Graph '" + baseUri + "' missing"); Assert.AreEqual(graph, store2.Graph(graph.BaseUri), "Graph '" + baseUri + "' was not the same Graph in both Stores"); } }
public void InteropSemWebInMemoryStoreSource() { MicrosoftSqlStoreManager mssql = new MicrosoftSqlStoreManager("dotnetrdf_experimental", "sa", "20sQl08"); InMemoryStoreSource source = new InMemoryStoreSource(new SqlTripleStore(mssql)); N3Writer writer = new N3Writer(Console.Out); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?type"); Statement template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Variable()); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?car"); template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples for Cars and Planes"); SelectFilter filter = new SelectFilter(); filter.Predicates = new Entity[] { new Entity(RdfSpecsHelper.RdfType) }; filter.Objects = new Entity[] { new Entity("http://example.org/vehicles/Car"), new Entity("http://example.org/vehicles/Plane") }; source.Select(filter, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting the Speeds of all Cards"); Variable car = new Variable("car"); Statement[] pattern = new Statement[] { new Statement(car, new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")), new Statement(car, new Entity("http://example.org/vehicles/Speed"), new Variable("speed")) }; source.Query(pattern, new QueryOptions(), new SemWebResultsConsolePrinter()); Console.WriteLine(); writer.Close(); }