SemWeb : SemWeb.Query Namespace
GraphMatch Class

The GraphMatch class implements an algorithm for determining all of the ways the variables in one graph can be bound to resources in another graph.

public class GraphMatch : Query


Remarks

None.

Members

See Also: Inherited members from Query.

Constructors

Creates an empty GraphMatch object.
Creates a query based on an RDF file.
Creates a query based on a graph in queryModel.

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.)

Methods

AddGraphStatement (SemWeb.Statement)
Adds a statement to the graph pattern (the query).
AddLiteralFilter (SemWeb.Variable, SemWeb.LiteralFilter)
Adds a filter to be applied to literal values that match against a given variable.
abstract GetExplanation () : string
Returns a textual explanation of the query. (Inherited from 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.)
SetDistinguishedVariable (SemWeb.Variable)
Marks a variable as distinguished.
SetVariableRange (SemWeb.Variable, System.Collections.Generic.ICollection<SemWeb.Resource>)
Sets the range of values that the variable's bindings must be drawn from.

Member Details

GraphMatch Constructor

public GraphMatch ()

Creates an empty GraphMatch object.

Remarks

Set up the GraphMatch with calls to SemWeb.Query.GraphMatch.AddEdge(SemWeb.Statement).

GraphMatch Constructor

public GraphMatch (SemWeb.RdfReader query)

Creates a query based on an RDF file.

Parameters

query
An RDF reader (normally a SemWeb.N3Reader) containing the query.

Remarks

The contents of the RDF stream are read. Statements in the stream are passed to SemWeb.Query.GraphMatch.AddEdge(SemWeb.Statement).

All of the anonymous nodes in the stream are considered variables, but only the N3 format allows anonymous nodes to be named variables. Thus the N3 format is recommended. Although variable names are not required by the GraphMatch class, they may be needed by whatever processes the query results.

The following is an example query:

Example
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
?person rdf:type foaf:Agent .
?person foaf:name ?name .

To run this query:

C# Example
Store queryGraph = new MemoryStore(new N3Reader(new StringReader(stringAbove)));
new GraphMatch(queryGraph).Run(targetData, Console.Out);  

GraphMatch Constructor

public GraphMatch (SemWeb.StatementSource queryModel)

Creates a query based on a graph in queryModel.

Parameters

queryModel
A graph that represents the query.

Remarks

None.

AddGraphStatement Method

public void AddGraphStatement (SemWeb.Statement statement)

Adds a statement to the graph pattern (the query).

Parameters

statement
A statement.

Remarks

Keep in mind that distinct instances of the SemWeb.Variable class are treated as separate variables, even if they have the same name.

AddLiteralFilter Method

public void AddLiteralFilter (SemWeb.Variable variable, SemWeb.LiteralFilter filter)

Adds a filter to be applied to literal values that match against a given variable.

Parameters

variable
The variable to apply the filter to.
filter
A filter.

Remarks

None.

SetVariableRange Method

Sets the range of values that the variable's bindings must be drawn from.

Parameters

variable
A variable in the query.
range
A collection of Resources.

Remarks

All bindings for this variable will be in the provided set of resources.

SetDistinguishedVariable Method

public void SetDistinguishedVariable (SemWeb.Variable variable)

Marks a variable as distinguished.

Parameters

variable
A variable in the query.

Remarks

If this method is never called, all variables in the query are returned in the variable bindings. However, once this method is called, only variables distinguished by this method will be included the resulting bindings. This is useful to avoid getting distinct answers on variables that the user does not care about.