SemWeb.Sparql : SemWeb.Query Namespace
SparqlEngine Class

A SPARQL query engine.

public class SparqlEngine : Query


Remarks

This class is based on the engine at http://sparql.sourceforge.net/ by Ryan Levering, version 0.8.

This example runs a SELECT query on a data source and writes the results as XML to standard output.

C# Example
MemoryStore datamodel = new MemoryStore(new RdfXmlReader("rdfdata.rdf"));

string sparqlQuery = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
                           + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
                           + "SELECT * WHERE { ?person rdf:type foaf:Agent . \n"
                           + "?person foaf:name ?name . }";

SparqlEngine query = new SparqlEngine(sparqlQuery);
query.Run(datamodel, Console.Out).  

Although this example sends the results to a stream, the results can be processed programmatically by passing a SemWeb.Query.QueryResultSink instead of a TextWriter.

Members

See Also: Inherited members from Query.

Constructors

Initialized the SPARQL query from a TextReader.
Initializes the SPARQL query from a string.

Fields

AllowPersistBNodes
bool . To be added.

Properties

MimeType
string . Gets or sets the preferred MIME type for the output of the query. (Inherited from Query.)
QueryMeta
SemWeb.Entity . A filter on the Meta value of statements in the target graph considered by the query. (Inherited from Query.)
ReturnLimit
int . The number of bindings to return. (Inherited from Query.)
ReturnStart
int . The index of the first binding to return. (Inherited from Query.)
Type [read-only]
SparqlEngine.QueryType . Gets the type of the query.

Methods

AddExternalFunction (RdfFunction)
Registers an external function that can be used in FILTER clauses.
Ask (SemWeb.SelectableSource) : bool
Executes an ASK query on the given data source and returns the result of the query as a boolean.
Ask (SemWeb.SelectableSource, System.IO.TextWriter)
Executes an ASK query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.
Construct (SemWeb.SelectableSource, SemWeb.StatementSink)
Executes a CONSTRUCT query on the given data source and sends the constructed statements to a StatementSink.
Construct (SemWeb.SelectableSource, System.IO.TextWriter)
Executes a CONSTRUCT query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.
Describe (SemWeb.SelectableSource, SemWeb.StatementSink)
Executes a DESCRIBE query on the given data source and sends the constructed statements to a StatementSink.
Describe (SemWeb.SelectableSource, System.IO.TextWriter)
Executes a DESCRIBE query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.
abstract GetExplanation () : string
Returns a textual explanation of the query. (Inherited from Query.)
GetQueryPrefixes () : SemWeb.NamespaceManager
Gets a NamespaceManager containing all of the PREFIX definitions used in the query.
abstract Run (SemWeb.SelectableSource, QueryResultSink)
Runs the query on a data source, outputting to a QueryResultSink. (Inherited from Query.)
Run (SemWeb.SelectableSource, System.IO.TextWriter)
Runs the query on a data source, outputting to a TextWriter. (Inherited from Query.)
Select (SemWeb.SelectableSource, System.IO.TextWriter)
Executes a SELECT query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.
Select (SemWeb.SelectableSource, QueryResultSink)
Executes a SELECT query on the given data source and sends the resulting variable bindings to a QueryResultSink.

Member Details

SparqlEngine Constructor

public SparqlEngine (string query)

Initializes the SPARQL query from a string.

Parameters

query
The SPARQL query.

Remarks

None.

SparqlEngine Constructor

public SparqlEngine (System.IO.TextReader query)

Initialized the SPARQL query from a TextReader.

Parameters

query
A TextReader containing the SPARQL query.

Remarks

None.

Ask Method

public bool Ask (SemWeb.SelectableSource source)

Executes an ASK query on the given data source and returns the result of the query as a boolean.

Parameters

source
The data source to query.

Returns

A boolean value giving the result of the ASK query.

Remarks

None.

Ask Method

Executes an ASK query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.

Parameters

source
The data source to query.
output
The System.IO.TextWriter to output the results to in the SPARQL Results XML output format.

Remarks


Construct Method

public void Construct (SemWeb.SelectableSource source, SemWeb.StatementSink sink)

Executes a CONSTRUCT query on the given data source and sends the constructed statements to a StatementSink.

Parameters

source
The data source to query.
sink
The SemWeb.StatementSink to send the constructed statements to.

Remarks

None.

Construct Method

public void Construct (SemWeb.SelectableSource source, System.IO.TextWriter output)

Executes a CONSTRUCT query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.

Parameters

source
The data source to query.
output
The System.IO.TextWriter to output the results to in the SPARQL Results XML output format.

Remarks


Describe Method

public void Describe (SemWeb.SelectableSource source, SemWeb.StatementSink sink)

Executes a DESCRIBE query on the given data source and sends the constructed statements to a StatementSink.

Parameters

source
The data source to query.
sink
The SemWeb.StatementSink to send the constructed statements to.

Remarks

None.

Describe Method

public void Describe (SemWeb.SelectableSource source, System.IO.TextWriter output)

Executes a DESCRIBE query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.

Parameters

source
The data source to query.
output
The System.IO.TextWriter to output the results to in the SPARQL Results XML output format.

Remarks


Select Method

public void Select (SemWeb.SelectableSource source, System.IO.TextWriter output)

Executes a SELECT query on the given data source and outputs the result of the query in the SPARQL results format to a TextWriter.

Parameters

source
The data source to query.
output
The System.IO.TextWriter to output the results to in the SPARQL Results XML output format.

Remarks


Select Method

public void Select (SemWeb.SelectableSource source, QueryResultSink sink)

Executes a SELECT query on the given data source and sends the resulting variable bindings to a QueryResultSink.

Parameters

source
The data source to query.
sink
The SemWeb.Query.QueryResultSink to send the resulting variable bindings to.

Remarks

None.

Type Property

public SparqlEngine.QueryType Type { get; }

Gets the type of the query.

Value

The type of the query: SELECT, DESCRIBE, CONSTRUCT, or ASK.

Remarks

None.

AllowPersistBNodes Field

public bool AllowPersistBNodes

To be added.

Remarks

To be added.

AddExternalFunction Method

public void AddExternalFunction (RdfFunction function)

Registers an external function that can be used in FILTER clauses.

Parameters

function
An object implementing an external function.

Remarks

None.

GetQueryPrefixes Method

public SemWeb.NamespaceManager GetQueryPrefixes ()

Gets a NamespaceManager containing all of the PREFIX definitions used in the query.

Returns

A NamespaceManager.

Remarks

None.