From: Rob V. <rv...@do...> - 2010-03-04 09:34:48
|
Hi Aleksandr You can use the TriplePattern, GraphPattern etc classes to build queries in theory but much of that part of the API has protected constructors and methods to stop people building completely invalid queries. For dynamically building SPARQL queries I've recently added a SparqlParameterizedString class to the source in response to a suggestion from another user. This allows you to build a SPARQL query from a base string in the style of ADO e.g. //Assumes you already have a VirtuosoManager in the variable manager SparqlParameterizedString queryString = new SparqlParameterizedString(); queryString.QueryText = "SELECT * WHERE {?subj a @type ; @prop ?value .}"; queryString.SetUri("type", new Uri("http://example.org/myType")); queryString.SetUri("prop", new Uri("http://example.org/myProperty")); Object results = manager.ExecuteQuery(queryString.ToString()); The parameterized string allows you to insert values into a base query string where the parameters are specified ADO.Net style as @param - there are SetUri(), SetLiteral() and SetBlankNode() methods to insert values as well as a SetParameter() method to insert an existing INode instance into the query. When you call the ToString() method the values for the parameters get inserted into the String with the proper formatting such that the output is a valid SPARQL query string. Would it be helpful to have the ability to insert an entire triple into the string as this could be added if you needed it? This code was added as of revision 635 and will be part of the next release (0.2.1) which should hopefully be out in the next week or so. Hope that helps, Rob Vesse From: Aleksandr A. Zaripov [mailto:za...@tp...] Sent: 04 March 2010 03:46 To: dot...@li... Subject: [dotNetRDF-develop] Building sparql query hi I'm searching for some way to build a sparql query from some objects and execute it against Virtuoso. I found TriplePattern, GraphPattern, Filter, Union etc. in Algebra namespace, but as I understand, there is no way to convert them into query string? С уважением, Зарипов Александр za...@tp... |