SemWeb.Query.Query

SemWeb : SemWeb.Query Namespace
Query Class

A Query is something that returns all of the ways a set of variables may bind to a graph. This is the abstract base class of several query methods.

public abstract class Query

#### Remarks

The SemWeb.Query.GraphMatch class provides a query algorithm to match a graph with variables against another graph.

The SemWeb.Query.Sparql class provides a SPARQL query engine.

## Members

See Also: Inherited members from object.

### Protected Constructors

Query () The protected no-arg constructor used by subclasses.

### Properties

MimeType | string . Gets or sets the preferred MIME type for the output of the query.
QueryMeta | Entity . A filter on the Meta value of statements in the target graph considered by the query.
ReturnLimit | int . The number of bindings to return.
ReturnStart | int . The index of the first binding to return.

### Methods

abstract | GetExplanation () : string Returns a textual explanation of the query.
abstract | Run (SelectableSource, SemWeb.Query.QueryResultSink) Runs the query on a data source, outputting to a QueryResultSink.
| Run (SelectableSource, System.IO.TextWriter) Runs the query on a data source, outputting to a TextWriter.

## Member Details

### Query Constructor

protected Query ()

The protected no-arg constructor used by subclasses.

#### Remarks

None.

### GetExplanation Method

public abstract string GetExplanation ()

Returns a textual explanation of the query.

#### Returns

A textual string describing the query or how the query will be performed.

#### Remarks

This method is provided for debugging or for users to be able to optimize the query based on the information in the returned string.

### ReturnStart Property

public int ReturnStart { set; get; }

The index of the first binding to return.

#### Value

The index of the first binding to return. The value of this property is 1-based.

#### Remarks

The first binding returned is by default the first binding.

### ReturnLimit Property

public int ReturnLimit { set; get; }

The number of bindings to return.

#### Value

The maximum number of bindings to return, or -1 to return all bindings.

#### Remarks

All bindings are returned by default.

### QueryMeta Property

public SemWeb.Entity QueryMeta { set; get; }

A filter on the Meta value of statements in the target graph considered by the query.

#### Value

The value of this property is `null` by default, meaning the Meta field of statements in the target graph is ignored for the purposes of the query. Otherwise, the query is restricted to statements with the given entity as a Meta value.

#### Remarks

None.

### Run Method

public abstract void Run (SemWeb.SelectableSource source, QueryResultSink resultsink)

Runs the query on a data source, outputting to a QueryResultSink.

#### Parameters

source
  The data source to query.
resultsink
  The sink to which each set of variable bindings is written.

#### Remarks

None.

### Run Method

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

Runs the query on a data source, outputting to a TextWriter.

#### Parameters

source
  The data source to query.
output
  The TextWriter to which to write results.

#### Remarks

The normal output format uses the SemWeb.Query.SparqlXmlQuerySink.

### MimeType Property

public virtual string MimeType { set; get; }

Gets or sets the preferred MIME type for the output of the query.

#### Value

The preferred MIME type for the output of the query.

#### Remarks

This propery returns the MIME type of the output that results from calling SemWeb.Query.Run(SemWeb.SelectableSource,System.IO.TextWriter). Output is often in the SPARQL XML Results format, so this property often returns "application/sparql-results+xml".

The SemWeb.Query.SparqlEngine class handles several different types of queries. ASK and SELECT queries return the MIME type above. CONSTRUCT and DESCRIBE queries will be output in RDF/XML format by default, and so this property returns "application/rdf+xml" for those queries.

This property can also be used to change the ouput format of queries, where supported. A MIME type that is not supported or recognized will cause the property setter to throw NotSupportedException. Always catch this exception when setting this property.

The SemWeb.GraphMatch class and SPARQL SELECT and ASK queries with the SemWeb.Query.SparqlEngine class do not support other output formats than SPARQL XML Results.

SPARQL CONSTRUCT and DESCRIBE queries with the SemWeb.Query.SparqlEngine class can be set to output in either RDF/XML or N3 format by setting this property to "application/n3" or any of the values listed in SemWeb.RdfWriter.Create(System.String,System.IO.TextWriter).