Skip to content
Weirong Zhu edited this page Sep 22, 2015 · 5 revisions

The First Prajna C# example walk-through

First of all, in VS2015, create a C# Windows Console Application. Please set the solution platform as "x64". Currently, Prajna is x64 only.

Then, install Prajna from Nuget. (For user who builds Prajna from source code directly, please add references to locally built Prajna dlls directly (located in "bin/DebugX64/CoreLib" or "bin/ReleaseX64/CoreLib")

Now, add the following namespaces

using Prajna.Core;
using Prajna.Api.CSharp;
using Prajna.Api.CSharp.Linq;

The next step is to create a cluster object. For this walk-through, assume we use a [local cluster](Local Cluster) with 2 nodes.

Prajna.Core.Environment.Init();
var cluster = new Cluster("local[2]");

Now, we are going to use the cluster to count the number of words of a document.

var corpus = File.ReadAllLines(path-to-text-file);
var count =
    (new DSet<string> { Name = "WordCount", Cluster = cluster })
    .Distribute(corpus)
    .SelectMany(l => l.Split(' '))
    .Count();

Console.WriteLine("Count = {0}", count);

The computation is done via the transformations and actions on a DSet, which represents a distributed dataset.

Finally, clean up the environment,

Prajna.Core.Environment.Cleanup();

More C# Examples

More C# examples can be found here. More will be added over the time.

Documentation

Clone this wiki locally