SemWeb.MemoryStore

SemWeb : SemWeb Namespace
MemoryStore Class

A graph of statements held in memory.

[System.Reflection.DefaultMember("Item")] public class MemoryStore : Store, System.Collections.Generic.IEnumerable<SemWeb.Statement>

#### Remarks

The MemoryStore is the main storage mechanism for small amounts of data.

Although the MemoryStore inherits from Store, which can be used to group multiple data sources together, it is illegal to call AddSource on a MemoryStore.

Here are some examples of using a MemoryStore:

C# Example
    // Load data from mydata.rdf file
    MemoryStore store = new MemoryStore(new RdfXmlReader("mydata.rdf"));

    // Add some statements
    store.Add(new Statement("http://www.mysite.com", "http://purl.org/dc/elements/1.1/title", (Literal)"My Web Site"));
    store.Add(new Statement("http://www.mysite.com", "http://purl.org/dc/elements/1.1/description",
         (Literal)"My site is all about me."));

    // You can also use Entity and Literal objects
    Entity othersite = new Entity("http://www.anothersite.com");
    Entity dctitle = new Entity("http://purl.org/dc/elements/1.1/title");
    store.Add(new Statement(othersite, dctitle, new Literal("Create a literal object."));

    // Get the statements back by looping through the store
    foreach (Statement statement in store) {
        Console.WriteLine(statement);
    }

    // Or by streaming them to a StatementSink
    using (StatementSink sink = new N3Writer(Console.Out))
        store.Write(sink);

    // You can get statements back selectively by filtering.  This just gets
    // statements about othersite.
    using (StatementSink sink = new N3Writer(Console.Out))
        store.Select(new Statement(othersite, null, null), sink);

    // And there are some utility functions like this:
    foreach (Resource res in store.SelectObjects(othersite, dctitle)) {
        if (res is Literal) // might also be an Entity
            Console.WriteLine("Other site's title: " + ((Literal)res).Value);
    }

## Members

See Also: Inherited members from Store.

### Constructors

MemoryStore () Creates a new empty MemoryStore.
MemoryStore (Statement[]) Creates a MemoryStore initialized with the given array of statements.
MemoryStore (StatementSource) Creates a new MemoryStore and reads the data from a StatementSource, which might be a SemWeb.RdfReader, for instance.

### Properties

DataSources [read-only] | System.Collections.Generic.IList<SemWeb.SelectableSource> . To be added. (Inherited from Store.)
Distinct [read-only] | bool . Gets whether the store returns only distinct statments from Select calls. (Inherited from Store.)
Item [int] [read-only] default property | Statement . Returns a statement in the store by index.
StatementCount [read-only] | int . Gets the number of statements in the store. (Inherited from Store.)

### Methods

| Add (Statement) Adds a statement to the store. (Inherited from Store.)
| AddReasoner (SemWeb.Inference.Reasoner) Adds inferencing capabilities to the Select and Query methods of this Store. (Inherited from Store.)
| AddSource (SelectableSource) Adds a data source to this store. (Inherited from Store.)
| AddSource (SelectableSource, string) Adds a named data source to this store. (Inherited from Store.)
| Clear () Clears the contents of the store. (Inherited from Store.)
| Contains (Resource) : bool Tests whether the store contains any statements that mention the given resource. (Inherited from Store.)
| Contains (Statement) : bool Returns whether the store contains a statement, or any statement that matches the template. (Inherited from Store.)
| Dispose () Releases any external resources associated with the Store. (Inherited from Store.)
| GetBNodeFromPersistentId (string) : BNode To be added. (Inherited from Store.)
| GetEntities () : Entity[] Returns an array of all entities mentioned in the store. (Inherited from Store.)
| GetEntitiesOfType (Entity) : Entity[] Returns an array of all entities in the store whose type is known to be the given type. (Inherited from Store.)
| GetMetas () : Entity[] Returns an array of all entities used in the Meta field of any statement in the store. (Inherited from Store.)
| GetPersistentBNodeId (BNode) : string To be added. (Inherited from Store.)
| GetPredicates () : Entity[] Returns an array of all predicates mentioned in the store. (Inherited from Store.)
| Import (StatementSource) Batch copies the contents of a StatementSource into the ModifyableSource contained in the store. (Inherited from Store.)
| MetaQuery (Statement[], SemWeb.Query.QueryOptions) : SemWeb.Query.MetaQueryResult Tests the querying capabilities of the store. (Inherited from Store.)
| Query (Statement[]) : System.Collections.Generic.ICollection<SemWeb.Query.VariableBindings> Queries the data sources in the Store and returns the resulting variable bindings. (Inherited from Store.)
| Query (Statement[], SemWeb.Query.QueryOptions, SemWeb.Query.QueryResultSink) Queries the store with a simple graph match query. (Inherited from Store.)
| Remove (Statement) Removes statements from the store. (Inherited from Store.)
| RemoveAll (Statement[]) Removes all statements matching an array of templates. (Inherited from Store.)
| Replace (Entity, Entity) Replaces all occurences of one Entity with another Entity. (Inherited from Store.)
| Replace (Statement, Statement) Replaces a single statement with another statement. (Inherited from Store.)
| Select (SelectFilter) : SelectResult Retuns a SemWeb.SelectResult object that represents the result of the corresponding select call with a StatementSink. (Inherited from Store.)
| Select (Statement) : SelectResult Retuns a SemWeb.SelectResult object that represents the result of matching a statement template against the store. (Inherited from Store.)
| Select (StatementSink) Streams all statements in this store into a StatementSink. (Inherited from Store.)
| Select (SelectFilter, StatementSink) Queries the story for matching statements, with advanced options, and writes the statements to a SemWeb.StatementSink. (Inherited from Store.)
| Select (Statement, StatementSink) Queries the story for matching statements, and writes the statements to a SemWeb.StatementSink. (Inherited from Store.)
| SelectObjects (Entity, Entity) : Resource[] Finds all objects in statements with the given subject and predicate. (Inherited from Store.)
| SelectSubjects (Entity, Resource) : Entity[] Finds all subjects in statements with the given predicate and object. (Inherited from Store.)
| ToArray () : Statement[] Returns the contents of the store as an array of Statements.
| Write (System.IO.TextWriter) Writes the contents of the store to a stream in N3 format. (Inherited from Store.)

## Member Details

### MemoryStore Constructor

public MemoryStore ()

Creates a new empty MemoryStore.

#### Remarks

None.

### MemoryStore Constructor

public MemoryStore (StatementSource source)

Creates a new MemoryStore and reads the data from a StatementSource, which might be a SemWeb.RdfReader, for instance.

#### Parameters

source
  A StatementSource, the contents of which are read into the memory store.

#### Remarks

None.

### ToArray Method

public Statement[] ToArray ()

Returns the contents of the store as an array of Statements.

#### Returns

An array of Statements that make up the contents of the store.

#### Remarks

None.

### Item Property

public Statement this [int index] { get; }

This is the default property for this class.

Returns a statement in the store by index.

#### Parameters

index
  The 0-based index to a statement in the store.

#### Value

A SemWeb.Statement.

#### Remarks

None.

### MemoryStore Constructor

public MemoryStore (Statement[] statements)

Creates a MemoryStore initialized with the given array of statements.

#### Parameters

statements
  An array of statements.

#### Remarks

The statements in the array are added to the MemoryStore on creation.