예제 #1
0
        public void StorageTalisStoreQuery()
        {
            try
            {
                //Get the Talis Connection
                TalisPlatformConnector talis = new TalisPlatformConnector("rvesse-dev1", "rvesse", "4kn478wj");
                Assert.IsNotNull(talis);
                
                //Create a Talis Triple Store
                TalisTripleStore store = new TalisTripleStore(talis);

                //Try a SELECT *
                String selectAll = "SELECT * {?s ?p ?o}";
                Object results = store.ExecuteQuery(selectAll);
                Assert.IsNotNull(results, "Expected some kind of results from the Query");
                TestTools.ShowResults(results);
                Console.WriteLine("SELECT query OK");
                Console.WriteLine();

                //Try a DESCRIBE
                String describe = "DESCRIBE <http://example.org/vehicles/FordFiesta>";
                results = store.ExecuteQuery(describe);
                Assert.IsNotNull(results, "Expected some kind of results from the Query");
                TestTools.ShowResults(results);
                Console.WriteLine("DESCRIBE query OK");
                Console.WriteLine();

                //Try an ASK
                String ask = "ASK {?s ?p ?o}";
                results = store.ExecuteQuery(ask);
                Assert.IsNotNull(results, "Expected some kind of results from the Query");
                TestTools.ShowResults(results);
                Console.WriteLine("ASK query OK");
                Console.WriteLine();

                //Try another ASK
                ask = "ASK {?s <http://example.org/nosuchthing> ?o}";
                results = store.ExecuteQuery(ask);
                Assert.IsNotNull(results, "Expected some kind of results from the Query");
                TestTools.ShowResults(results);
                Console.WriteLine("ASK query OK");
                Console.WriteLine();

            }
            catch (TalisException talisEx)
            {
                TestTools.ReportError("Talis Error", talisEx, true);
            }
            catch (RdfParseException parseEx)
            {
                TestTools.ReportError("Parsing Error", parseEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
        public void InteropSemWebNativeStore()
        {
            //Get the Talis Connection
            TalisPlatformConnector talis = new TalisPlatformConnector("rvesse-dev1", "rvesse", "4kn478wj");
            Assert.IsNotNull(talis);

            //Create a Talis Triple Store
            TalisTripleStore store = new TalisTripleStore(talis);

            //Create the Native Store Source
            NativeStoreSource source = new NativeStoreSource(store);

            Console.WriteLine("All Statements in the Store");
            source.Select(new SemWebConsolePrinter());
            Console.WriteLine();

            Console.Write("Does a FordFiesta exist in the Store? ");
            Console.WriteLine(source.Contains(new Entity("http://example.org/vehicles/FordFiesta")));
            Console.WriteLine();

            Console.Write("Does a Monkey exist in the Store? ");
            Console.WriteLine(source.Contains(new Entity("http://example.org/Monkey")));
            Console.WriteLine();

            Console.Write("Do any Cars exist in the Store? ");
            Statement cars = new Statement(null, new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car"));
            Console.WriteLine(source.Contains(cars));
            Console.WriteLine();

            Console.Write("Do any Gorillas exist in the Store?");
            Statement gorillas = new Statement(null, new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/Gorilla"));
            Console.WriteLine(source.Contains(gorillas));
            Console.WriteLine();

            Console.WriteLine("What Cars exists in the Store?");
            source.Select(new Statement(null, new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")), new SemWebConsolePrinter());
            Console.WriteLine();

            Console.WriteLine("Cars are their Speeds from the Store?");
            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();
        }