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); } }
/// <summary> /// Creates a new Talis Reader that connects to a Store using the given Connector /// </summary> /// <param name="connector">Connector</param> public TalisReader(TalisPlatformConnector connector) { this._talis = connector; }
/// <summary> /// Tries to load a Generic IO Manager based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { IGenericIOManager manager = null; obj = null; String server, user, pwd, store; bool isAsync; Object temp; INode storeObj; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase), propStore = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore), propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync); switch (targetType.FullName) { case AllegroGraph: //Get the Server, Catalog and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) return false; //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new AllegroGraphConnector(server, catalog, store, user, pwd); } else { manager = new AllegroGraphConnector(server, catalog, store); } break; case DatasetFile: //Get the Filename and whether the loading should be done asynchronously String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile)); if (file == null) return false; file = ConfigurationLoader.ResolvePath(file); isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); manager = new DatasetFileManager(file, isAsync); break; case Dydra: //Get the Account Name and Store String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); if (account == null) return false; store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) return false; //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null) { manager = new DydraConnector(account, store, user); } else { manager = new DydraConnector(account, store); } break; case FourStore: //Get the Server and whether Updates are enabled server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true); manager = new FourStoreConnector(server, enableUpdates); break; case Fuseki: //Get the Server URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; manager = new FusekiConnector(server); break; case InMemory: //Get the Dataset/Store INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset)); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { manager = new InMemoryManager((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { //If no dnr:usingDataset try dnr:usingStore instead storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeObj != null) { temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { manager = new InMemoryManager((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } else { //If no dnr:usingStore either then create a new empty store manager = new InMemoryManager(); } } break; case Joseki: //Get the Query and Update URIs server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath)); if (queryService == null) return false; String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath)); if (updateService == null) { manager = new JosekiConnector(server, queryService); } else { manager = new JosekiConnector(server, queryService, updateService); } break; case ReadOnly: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IGenericIOManager) { manager = new ReadOnlyConnector((IGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface"); } break; case ReadOnlyQueryable: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IQueryableGenericIOManager) { manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface"); } break; case Sesame: case SesameV5: case SesameV6: //Get the Server and Store ID server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) return false; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd }); } else { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store }); } break; case Sparql: //Get the Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri)); //What's the load mode? String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { #if SILVERLIGHT loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false); #else loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); #endif } catch { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint)); if (endpointObj == null) return false; temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode); } else { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { //Are there any Named/Default Graph URIs IEnumerable<Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)) where def.NodeType == NodeType.Uri select ((IUriNode)def).Uri; IEnumerable<Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri)) where named.NodeType == NodeType.Uri select ((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { manager = new SparqlConnector(new SparqlRemoteEndpoint(new Uri(server), defGraphs, namedGraphs), loadMode); } else { manager = new SparqlConnector(new Uri(server), loadMode); } } break; case SparqlHttpProtocol: //Get the Service URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; manager = new SparqlHttpProtocolConnector(new Uri(server)); break; case Stardog: //Get the Server and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) return false; store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) return false; //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); //Get Reasoning Mode StardogReasoningMode reasoning = StardogReasoningMode.None; String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); if (mode != null) { try { reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode); } catch { reasoning = StardogReasoningMode.None; } } if (user != null && pwd != null) { manager = new StardogConnector(server, store, reasoning, user, pwd); } else { manager = new StardogConnector(server, store, reasoning); } break; case Talis: //Get the Store Name and User credentials store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) return false; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new TalisPlatformConnector(store, user, pwd); } else { manager = new TalisPlatformConnector(store); } break; } obj = manager; return (manager != null); }
/// <summary> /// Creates a new Talis Triple Store /// </summary> /// <param name="connector">Connection to a Talis Store</param> public TalisTripleStore(TalisPlatformConnector connector) : base(new GraphCollection()) { this._talis = connector; }
/// <summary> /// Creates a new instance of a Talis Graph which contains the description of the given Uri from the given underlying Talis Store /// </summary> /// <param name="resourceUri">Uri of resource to retrieve a Description of</param> /// <param name="connector">Connection to a Talis Store</param> public TalisGraph(Uri resourceUri, TalisPlatformConnector connector) : base(connector, resourceUri) { this._talis = connector; }
/// <summary> /// Creates a new instance of a Talis Graph which contains the description of the given Uri from the given underlying Talis Store /// </summary> /// <param name="resourceUri">Uri of resource to retrieve a Description of</param> /// <param name="connector">Connection to a Talis Store</param> public TalisGraph(String resourceUri, TalisPlatformConnector connector) : this(new Uri(resourceUri), connector) { }
public static void Main(String[] args) { StreamWriter output = new StreamWriter("TalisTests.txt"); try { Console.SetOut(output); Console.WriteLine("## Talis Platform Tests"); Console.WriteLine(); //Read in our Test Graph Graph g = new Graph(); TurtleParser ttlparser = new TurtleParser(); ttlparser.Load(g, "TalisTest.ttl"); Console.WriteLine("Loaded Test Graph OK"); Console.WriteLine(); //Get the Talis Store TalisPlatformConnector talis = new TalisPlatformConnector("rvesse-dev1", "rvesse", "4kn478wj"); //Attempt to add a Graph Console.WriteLine("# Attempting to add this Graph to the Talis Store"); talis.Add(g); Console.WriteLine("Added the Graph OK"); Console.WriteLine(); //Attempt to get this some data from this Graph back again Console.WriteLine("# Attempting to retrieve some data from this Graph from the Talis Store"); Graph h = new Graph(); talis.Describe(h, TestUri); Console.WriteLine("Retrieved OK"); Console.WriteLine(); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); //Make a Sparql Query for the same stuff Console.WriteLine("# Attempting to retrieve the same data from this Graph from the Talis Store using SPARQL"); Object results = talis.Query("SELECT * {?s ?p ?o . FILTER(?s = <" + TestUri + ">)}"); Console.WriteLine("Retrieved OK"); Console.WriteLine(); //Output the Result if (results is SparqlResultSet) { foreach (SparqlResult result in (SparqlResultSet)results) { Console.WriteLine(result.ToString()); } } else if (results is Graph) { foreach (Triple t in ((Graph)results).Triples) { Console.WriteLine(t.ToString()); } } else { Console.WriteLine("Unexpected Results Object '" + results.GetType().ToString() + "'"); } Console.WriteLine(); //Use a TalisGraph object to do the same thing Console.WriteLine("# Attempting to retrieve the same data again using a TalisGraph object"); TalisGraph i = new TalisGraph(TestUri, talis); Console.WriteLine("Retrieved OK"); Console.WriteLine(); foreach (Triple t in i.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); //Use the same object to Update the Store Console.WriteLine("# Attempting to Update the Talis Store using the TalisGraph object"); if (!i.NamespaceMap.HasNamespace("eg")) { i.NamespaceMap.AddNamespace("eg", new Uri("http://example.org/vehicles/")); } IUriNode spaceVehicle = i.CreateUriNode("eg:SpaceVehicle"); IUriNode subClass = i.CreateUriNode("rdfs:subClassOf"); IUriNode vehicle = i.CreateUriNode("eg:Vehicle"); i.Assert(new Triple(spaceVehicle, subClass, vehicle)); Console.WriteLine("Updated OK"); Console.WriteLine(); //Retrieve that Graph again Console.WriteLine("# Retrieving the same data again to check that the Update was persisted OK"); TalisGraph j = new TalisGraph(new Uri("http://example.org/vehicles/SpaceVehicle"), talis); Console.WriteLine("Retrieved OK"); Console.WriteLine(); foreach (Triple t in j.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); } catch (Exception ex) { HandleError(ex); } finally { output.Close(); } }
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(); }