SemWeb : SemWeb Namespace
RdfReader Class

The base class of types that read statements from streams.

public abstract class RdfReader : StatementSource, IDisposable


Remarks

This is an abstract class. Two subclasses are provided: SemWeb.N3Reader and SemWeb.RdfXmlReader.

SemWeb.RdfReader.LoadFromUri(System.Uri) can be used to load RDF data, in either N3 or XML format, from a web address.

SemWeb.RdfReader.Create(string,string) can be used to create a reader in the factory paradigm.

Members

See Also: Inherited members from object.

Protected Constructors

The protected no-arg constructor used by derived classes.

Properties

BaseUri
string . The base URI for resolving relative URIs found in the stream. If a base URI is provided within the stream, this property may be updated to indicate the base URI found.
Meta
Entity . An entity to assign as the meta entity for statements loaded by this reader.
Namespaces [read-only]
NamespaceManager . Gets the NamespaceManager that contains all of the namespace-prefix mappings used in the input stream.
ReuseEntities
bool . Determines whether the reader must reuse Entity objects that it creates.
Variables [read-only]
System.Collections.Generic.ICollection<SemWeb.Variable> . A list of SemWeb.Variables found in the stream.
Warnings [read-only]
System.Collections.Generic.ICollection<System.String> . Gets a list of warnings generated while parsing the input stream.

Methods

static Create (string, string) : RdfReader
Creates a RdfReader in the factory paradigm for the given file.
static Create (string, System.IO.Stream) : RdfReader
Creates a RdfReader in the factory paradigm for the given Stream.
Dispose ()
Disposes the reader.
static LoadFromUri (Uri) : RdfReader
Loads an RDF document from the Internet.
abstract Select (StatementSink)
Reads the stream into the statement sink.

Protected Methods

AddVariable (Variable)
Adds a Variable to the Variables collection.
OnWarning (string)
Implementors of RdfReader may call this method to indicate a parsing warning.

Member Details

RdfReader Constructor

protected RdfReader ()

The protected no-arg constructor used by derived classes.

Remarks

None.

Dispose Method

public virtual void Dispose ()

Disposes the reader.

Remarks

The resources associated with the reader are freed.

Create Method

public static RdfReader Create (string type, string source)

Creates a RdfReader in the factory paradigm for the given file.

Parameters

type
The stream type.
source
The name of the source stream, as a file name, or "-" for standard input.

Returns

The type of reader returned is given in the following table.

type Reader
"xml", "text/xml", "application/xml", "application/rdf+xml" SemWeb.RdfXmlReader
"n3", "text/n3", "application/n3", "application/turtle", "application/x-turtle" SemWeb.N3Reader

Remarks

None.

Meta Property

public Entity Meta { set; get; }

An entity to assign as the meta entity for statements loaded by this reader.

Value

An entity to use for meta information. Cannot be null.

Remarks

The value of this property is used as the meta argument in calls to the Statement constructor SemWeb.Statement(SemWeb.Entity,SemWeb.Entity,SemWeb.Resource,SemWeb.Entity). The use of SemWeb.Statement.Meta is up to the application.

The default value of this property is SemWeb.Statement.DefaultMeta, which is also the meta value used in the three-arg constructor for SemWeb.Statement. If the meta field is not important for the application, this field should be left unchanged.


BaseUri Property

public string BaseUri { set; get; }

The base URI for resolving relative URIs found in the stream. If a base URI is provided within the stream, this property may be updated to indicate the base URI found.

Value

The base URI for resolving relative URIs found in the stream. May be, and is initially, null.

Remarks

When this property is null, the reader will not correctly resolve relative URIs in the stream. Always set this property before beginning reading when the base URI of the document is known.

OnWarning Method

protected void OnWarning (string message)

Implementors of RdfReader may call this method to indicate a parsing warning.

Parameters

message
A warning message.

Remarks

This is not currently used for anything.

Variables Property

A list of SemWeb.Variables found in the stream.

Value

A list of SemWeb.Variables found in the stream.

Remarks

Not all readers support variables. (N3-formatted RDF does, but XML formatted RDF doesn't.)

Select Method

public abstract void Select (StatementSink sink)

Reads the stream into the statement sink.

Parameters

sink
Each statement found in the stream is added to the statement sink via SemWeb.StatementSink.Add(SemWeb.Statement).

Remarks

User code should call SemWeb.Store.Import(SemWeb.StatementSource) rather than calling this method directly.

ReuseEntities Property

public bool ReuseEntities { set; get; }

Determines whether the reader must reuse Entity objects that it creates.

Value

If false (the default), the reader may create a new Entity object each time an entity is encoutered in the stream. If true, the reader must return the same Entity object each time it encounters a reference to the same entity.

Remarks

Setting this property to true may slow down the performance of the reader, as it may need to consult a hashtable each time a URI is read mapping the URI to an Entity it has previously created.

LoadFromUri Method

public static RdfReader LoadFromUri (Uri webresource)

Loads an RDF document from the Internet.

Parameters

webresource
The URI of the RDF document.

Returns

An RdfReader over the remote document.

Remarks

The document is fetched with System.Net.WebRequest and must be in RDF/XML or Notation3 (NTriples/Turtle/N3) format.

The format of the document is detected as follows. If the document has a mime-type of text/xml, application/xml, application/rss+xml, or application/rdf+xml, the document is treated as an RDF/XML document. If the document has a mime-type of text/rdf+n3, application/n3, application/turtle, or application/x-turtle, the document is treated as a Notation3 document. If the mime-type is not recognized, the document's file name extension is checked. If it is .xml or .rss, it is treated as an RDF/XML document. If it is .n3, .ttl, or .nt, it is treated as a Notation3 document.

If the format could not be determined, a InvalidOperationException is thrown.


Namespaces Property

public NamespaceManager Namespaces { get; }

Gets the NamespaceManager that contains all of the namespace-prefix mappings used in the input stream.

Value

A NamespaceManager that contains all of the namespace-prefix mappings used in the input stream.

Remarks

None.

Warnings Property

Gets a list of warnings generated while parsing the input stream.

Value

A list of warnings generated while parsing the input stream. Each element of the list is a string.

Remarks

None.

AddVariable Method

protected void AddVariable (Variable variable)

Adds a Variable to the Variables collection.

Parameters

variable
A variable.

Remarks

Used by RdfReader implementations to add a variable into the Variables collection.

Create Method

public static RdfReader Create (string type, System.IO.Stream source)

Creates a RdfReader in the factory paradigm for the given Stream.

Parameters

type
The stream type.
source
A stream to read from.

Returns

The type of reader returned is given in the following table.

type Reader
"xml", "text/xml", "application/xml", "application/rdf+xml" SemWeb.RdfXmlReader
"n3", "text/n3", "application/n3", "application/turtle", "application/x-turtle" SemWeb.N3Reader

Remarks

None.