<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>developers.sones.de &#187; Connectors</title>
	<atom:link href="http://developers.sones.de/tag/connectors/feed/" rel="self" type="application/rss+xml" />
	<link>http://developers.sones.de</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 01 Sep 2010 16:26:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get a Taste of Graph Databases: InfoGrid, Neo4j and sones GraphDB</title>
		<link>http://developers.sones.de/2010/02/24/get-a-taste-of-graph-databases-infogrid-neo4j-and-sones-graphdb/</link>
		<comments>http://developers.sones.de/2010/02/24/get-a-taste-of-graph-databases-infogrid-neo4j-and-sones-graphdb/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 15:02:35 +0000</pubDate>
		<dc:creator>ahzf</dc:creator>
				<category><![CDATA[Connectors]]></category>
		<category><![CDATA[GraphDB]]></category>
		<category><![CDATA[GraphDSSharp]]></category>

		<guid isPermaLink="false">http://developers.sones.de/?p=650</guid>
		<description><![CDATA[Alex Popescu, author of the well-known MyNoSQL blog recently wrote about a very (very) basic tagging app and its implementation within the InfoGrid and Neo4j graph database systems.
Today we want to pick up the given example and show you an implementation using the sones GraphDB and the GraphDBSharp API:

using System;
using System.Linq;
using System.Collections.Generic;

using sones.GraphDB;
using sones.GraphDB.Structures;
using sones.GraphDB.API.CSharp;
using [...]]]></description>
			<content:encoded><![CDATA[<p>Alex Popescu, author of the well-known <a href="http://nosql.mypopescu.com/">MyNoSQL blog</a> recently wrote about a <a href="http://nosql.mypopescu.com/post/405045629/get-a-taste-of-graph-databases-infogrid-and-neo4j">very (very) basic tagging app</a> and its implementation within the InfoGrid and Neo4j graph database systems.</p>
<p>Today we want to pick up the given example and show you an implementation using the sones GraphDB and the GraphDBSharp API:</p>
<pre class="prettyprint"><code>
using System;
using System.Linq;
using System.Collections.Generic;

using sones.GraphDB;
using sones.GraphDB.Structures;
using sones.GraphDB.API.CSharp;
using sones.GraphDB.API.CSharp.Reflection;
using sones.GraphDB.Connectors.GraphDBREST;
using sones.GraphFS.Connectors.GraphFSCLI;
using sones.GraphDB.Connectors.GraphDBCLI;

namespace TagExample
{

    public class Tag : DBObject {

        // Will inherit an UUID and RevisionID property from DBObject

        [CreateIndex(DBIndexTypes.HashTable)]
        public String Name { get; set; }

        // Backwardedges to the attribute Tags of type Websites
        [BackwardEdge("Tags")]
        public List&lt;Website&gt; TaggedWebsites { get; set; }

        public Tag() { }

    }

    public class Website : DBObject
    {

        // Will inherit an UUID and RevisionID property from DBObject

        [CreateIndex(DBIndexTypes.HashTable)]
        public String Name { get; set; }

        public String URL  { get; set; }

        // Edges to the tags
        public List&lt;Tag&gt; Tags { get; set; }

        public Website() { }

    }

    public class TagExample
    {

        private void CheckResult(QueryResult myQueryResult)
        {
            Console.WriteLine("{0} =&gt; {1}",
                myQueryResult.Query,
                myQueryResult.ResultType);
        }

        private void Run()
        {

            // Create a new in-memory database
            var GDB = new GraphDBSharp()
            {
                DatabaseName        = "TagExampleDB",
                Username            = "Dr.Falken",
                Password            = "Joshua"
                // For persistence use:
                //StorageLocation   = "file://TagExampleDB.fs",
                //StorageLocation   = "net.tcp://127.0.0.1:8000",
            };

            GDB.CreateDatabase(true);

            // Create types tag and website using reflection
            GDB.CreateTypes(CheckResult, new Tag(), new Website());

            // Insert tags
            var _good  = new Tag() { Name = "good"  };
            var _funny = new Tag() { Name = "funny" };
            GDB.Insert(CheckResult, _good, _funny);

            // Insert websites and link them to their tags
            var _cnn   = new Website() {
                            Name = "CNN",
                            URL  = "http://cnn.com/",
                            Tags = new List&lt;Tag&gt;() { _good }
                         };

            var _xkcd  = new Website() {
                            Name = "xkcd",
                            URL  = "http://xkcd.com/",
                            Tags = new List&lt;Tag&gt;() { _good, _funny }
                         };

            var _onion = new Website() {
                            Name = "onion",
                            URL  = "http://theonion.com/",
                            Tags = new List&lt;Tag&gt;() { _funny }
                         };

            GDB.Insert(CheckResult, _cnn, _xkcd, _onion);

            // Find out which tags xkcd is tagged with
            var _xkcdtags = GDB.Query("FROM Website w SELECT w.Tags " +
                                      "WHERE w.Name = 'xkcd' DEPTH 1");
            foreach (var _tag in (List&lt;DBObjectReadout&gt;) _xkcdtags["Tags"])
                Console.WriteLine(_tag["Name"]);

            // List tagged sites
            var _taggedsites = GDB.Query("FROM Website w SELECT w.Name, " +
                                         "Count(w.Tags) AS Counter " +
                                         "WHERE Count(w.Tags)&gt;0");
            foreach (var _sites in (List&lt;DBObjectReadout&gt;) _taggedsites[0])
                Console.WriteLine("{0} =&gt; {1}", _sites["Name"], _sites["Counter"]);

            // Start a REST service on localhost port 9975
            GDB.StartREST(new Uri("http://localhost:9975"));

            // Start the GraphDB command line interface
            GDB.OpenCLI(typeof(ABasicFSCLICommands),
                        typeof(AAdvancedFSCLICommands),
                        typeof(ABasicDBCLICommands),
                        typeof(AAdvancedDBCLICommands));

            GDB.Shutdown();

        }

        public static void Main(string[] myArgs)
        {
            var w = new TagExample();
            w.Run();
        }

    }

}</code></pre>
<p> </p>
<p>The current C# API is already very expressive, but other programming languages might be much more verbose. To avoid writing a lot of code, you can always use our <a href="http://developers.sones.de/documentation/graph-query-language/">Graph Query Lanuage (GQL)</a> which is an optimized <a href="http://en.wikipedia.org/wiki/Domain-specific_language">Domain-specific language (DSL)</a> for creating and manipulating a graph within our database.</p>
<pre class="prettyprint"><code>
  CREATE TYPES
    Tag EXTENDS DBObject
        ATTRIBUTES (String Name)
        BACKWARDEDGES (Website.Tags TaggedWebsites)
        INDICES (Name),
    Website EXTENDS DBObject
        ATTRIBUTES (String Name, String URL, LIST&lt;Tag&gt; Tags)
        INDICES (Name)

  INSERT INTO Tag VALUES (Name = 'good')
  INSERT INTO Tag VALUES (Name = 'funny')

  INSERT INTO Website VALUES
    (Name = 'CNN',
     URL  = 'http://cnn.com/',
     Tags = SETOF (Name = 'good'))

  INSERT INTO Website VALUES
    (Name = 'xkcd',
     URL  = 'http://xkcd.com/',
     Tags = SETOF (Name = 'good', Name = 'funny'))

  INSERT INTO Website VALUES
    (Name = 'onion',
     URL  = 'http://theonion.com/',
     Tags = SETOF (Name = 'funny'))

  // Find out which tags xkcd is tagged with...
  FROM Website w SELECT w.Tags WHERE w.Name = 'xkcd' DEPTH 1
  // Alternative query...
  FROM Tag     t SELECT t.Name WHERE t.TaggedWebsites.Name = 'xkcd'

  // List tagged sites...
  FROM Website w SELECT w.Name, Count(w.Tags) AS Counter WHERE Count(w.Tags)&gt;0
 </code></pre>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://developers.sones.de/2010/02/24/get-a-taste-of-graph-databases-infogrid-neo4j-and-sones-graphdb/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
