RDF API Overview

The RDF API provides a library of .NET classes for working with RDF data. The goal of this document is to provide a broad overview of its design and functionality.

  • Load and store RDF data
  • Query RDF data using SPARQL
  • Federate queries over multiple sources of RDF data
  • Execute and maintain inferences on a set of facts

The RDF API provides many more capabilities; however, this document will focus on the most commonly used functionality.

Statements and Values: The building blocks of a RDF graph.

RDF uses a simple directed graph to model data that is constructed by linking a source node to a destination node using a named arc. The value of the source node is referred as the subject, the destination node as the object and the named arc as the predicate. These three values predicate, subject and value make up a single RDF statement, also commonly referred to as a triple. The RDF API provides a class called Statement that represents a single RDF statement. RDF restricts the values of the predicate and subject to be a valid URI while the object value can be either a valid URI or a literal value.

The table below describes the most common value classes used in the RDF API.

RdfValue The abstract base class for all RDF values.
RdfUri Represents a RDF resource value
RdfLiteral Represents a RDF literal value. This value can be a typed literal and the RdfLiteral class provides convenient conversions to and from native .NET data types.

The RDF API provides many more capabilities; however, this document will focus on the most commonly used functionality.

Data Sources: The basic triple store.

A data source can be thought of as a collection of RDF statements (aka triples). It provides a basic interface for performing the following actions:

  • Adding and removing statements
  • Querying using SPARQL
  • Serialization
  • Delivering notification events when statements are added or removed.

All data sources derive from the abstract base class DataSource. The table below describes the data source classes included in the RDF API.

DataSource The abstract base class for all data sources.
GraphDataSource A data source that contains all fact statements and no inference rules.
InferenceDataSource A data source that supports inference rules. An inference data source is constructed from a set of facts and inference rules. Facts can then be added or removed and the inferences automatically updated.

Nodes: Traversing and modifying resources in a graph.

In the context of the RDF API, a node is defined as all the statements about a subject URI. This should not be confused with graph node when referring to a directed graph. The most common way to get node is by providing the URI value of the subject to a data source object.

The RDF API provides a class RdfNode where each instance represents a single node and provides an interface to:

  • Get a predicate values for the node
  • Get all object values for a predicate
  • Add, remove or replace an object value for a predicate

The RdfNode class can be used to traverse all the connected nodes in an RDF graph by iterating over the predicate and object values of each node encountered.

Queries: Executing SPARQL.

The RDF API fully supports the standardize RDF query language called SPARQL. Queries can be executed by providing a SPARQL string to either a data source or model object.

Results: Working with query results.

When a query is executed on a data source or model object the query results are returned in a table object. The Table class is the base class for all table objects and provides the interface for accessing the values in the rows and columns of the results table. If a table object has exactly three columns then it can be used to construct a new data source object. This provides a convenient mechanism for extracting a subset of data from one data source and adding it to another.

Serialization: Parsing and formatting RDF.

The RDF API provides parser and formatters for the most common RDF serialization standards. All parser and formatter classes derive from the abstract base classes RdfReader and RdfFormatter, respectively. To load serialized RDF data into a data source, the parser class for the appropriate serialization format must be specified when calling the Read method on the data source object. This will load all the statements from the serialized RDF into the data source. To serialize RDF data from a data source, the formatter class for the appropriate serialization formation must be specified when calling the Format method on the data source object.

The table below describes the parser and formatter classes included in the RDF API.

RdfReader The abstract base class for all RDF syntax parsers.
RdfXmlReader Parses RDF data serialized using the RDF/XML syntax.
NTriplesReader Parses RDF data serialized using the NTriples syntax
RdfFormatter The abstract base class for all RDF syntax formatters.
RdfXmlFormatter Formats RDF data using the RDF/XML syntax.
NTriplesFormatter Formats RDF data using the NTriples syntax.

Inference Rules: Dynamically generating statements.

One of the most powerful features of the RDF API is its built in inference engine that allows logic programming style rules to be executed over a set of RDF statements. This allows additional inferred statements to be dynamically generated from a set of facts. As facts are added and removed the inference engine automatically updates all inferred statements. The RDF API inference engine tracks the dependencies of all inferred statements so it can efficiently update just the dependent inferred statements as facts change. The RDF API allows applications to receive notification events when any statements, fact or inferred, changed.

In order to use inference rules you must first create an inference data source object that is an instance of the class InferenceDataSource. An inference data source is created from another data source object that usually contains a set of initial facts in combination with a query that defines a set of inference rules. When constructed all of the rules are applied to the set of facts and the inferred statements are generated and will be maintained for the lifetime of the inference data source object. The inference data source can be queried using SPARQL and supports the same interface used by data sources without inference rules. The main difference is that query results will also contain any inferred statements that match the query conditions. The inference data source object can be used to test whether a statement is a fact or inferred statement.

Models: Creating custom repositories.

In the RDF API, models provide a mechanism for managing one or more named data sources primarily for use within SPARQL queries. Data source objects can be added to a model and associated with a unique name within that model. These data sources can then be referenced by name in a SPARQL query. If multiple data sources are included in a query then the query is federated over all the data sources. The results would be identical to those returned if all the data resided in a single data source. A model also allows an application to provide custom named functions that can be included in a SPARQL query or override the implementation of the standard functions. A model is very useful for implementing a web accessible repository such as a SPARQL endpoint.

The RDF API currently includes a single model class called ClientModel.