A QueryableSource is a data source that supports a graph-matching query operation.
|
The QueryableSource interface is meant to expose the functionality of simple graph matching over a data source. For instance, the following simple type of query can be answered through the QueryableSource interface:
Example |
?book dc:title ?title . ?book ex:isbn ?isbn. |
In these queries, the QueryableSouce returns all ways to bind variables to values such that for each binding, all the statements in the query with the variables replaced with their values are contained within data source.
The SemWeb.QueryableSource.Query(SemWeb.Statement[],SemWeb.Query.QueryOptions,SemWeb.Query.QueryResultSink) method takes three parameters. The first parameter is the graph, as an array of SemWeb.Statements. For the example above, the array could be created as follows:
C# Example |
Variable book = new Variable(); Variable title = new Variable(); Variable isbn = new Variable(); Statement[] graph = new Statement[] { new Statement(book, DCNS + "title", title), new Statement(book, EXNS + "isbn", isbn) } |
Keep in mind that different SemWeb.Variable instances always represent different variables. Be sure to reuse the same Variable object when you want to use the same variable more than once in the query.
The second argument to Query is a SemWeb.Query.QueryOptions structure which provides additional details on how the query should be executed. No members of that structure are required to be set for a run-of-the-mill query.
The final argument is a SemWeb.Query.QueryResultSink to which each of the bindings are sent as they are computed. All of the results are sent to the sink before the Query method returns.
This interface also has a SemWeb.QueryableSource.MetaQuery(SemWeb.Statement[],SemWeb.Query.QueryOptions) method which is used before invoking the Query method to determine whether the data source can answer the query. Calling MetaQuery is optional; however, Query may throw a NotSupportedException if the query cannot even be processed, something that can be avoided by calling MetaQuery first and checking the return value.
MetaQuery
(Statement[], SemWeb.Query.QueryOptions) This method is used to cheaply get information on how the Query method will execute a query. |
|
Query
(Statement[], SemWeb.Query.QueryOptions, SemWeb.Query.QueryResultSink) Queries the data source with a simple graph pattern containing variables. |
Queries the data source with a simple graph pattern containing variables.
The graph consists of an array of SemWeb.Statements. None of the fields of the statements may be null, as in the Select calls. Rather, wildcards are given as instances of the SemWeb.Variable class. The query's results are all ways the variables can be "bound" (ie. assigned) to resources in the data source such that the graph, with the variables replaced by their values, is found or supported by the data source.
Bear in mind that two instances of the Variable class are never considered equal even if their names are equal. Reuse the same Variable instance object to refer to a variable more than once in the graph.
This method may throw a NotSupportedException if the query cannot even be processed. No other exceptions, besides ArgumentException, will be thrown.
This method is used to cheaply get information on how the Query method will execute a query.