Fork me on GitHub

Kategorie: Connectors

We always think about new ways to inte­grate GraphDB into exist­ing envi­ron­ments. And one of those envi­ron­ments our users are work­ing with right now are the sev­eral Enter­prise Ser­vice Busses which are avail­able right now.

One big player in the ESB envi­ron­ment is the Mule Open Source ESB:

Mule is a light­weight enter­prise ser­vice bus (ESB) and inte­gra­tion frame­work. It can han­dle ser­vices and appli­ca­tions using dis­parate trans­port and mes­sag­ing tech­nolo­gies. The plat­form is Java-based, but can bro­ker inter­ac­tions between other plat­forms such as .NET using web ser­vices or sockets.

The archi­tec­ture is a scal­able, highly-distributable object bro­ker that can seam­lessly han­dle inter­ac­tions across legacy sys­tems, in-house appli­ca­tions and almost all mod­ern trans­ports and protocols.”

In order to show how a GraphDB inte­grates into those typ­i­cal ESB envi­ron­ments we cre­ated a small example.

The archi­tec­ture of this exam­ple is like this:

mule-esb

The idea behind this is that an exam­ple Message-WebApp is post­ing a mes­sage to the Mule ESB and then this mes­sage gets trans­formed and in the last con­se­quence con­sumed by a sones REST­ful web­ser­vice hosted by a GraphDB.

You can read more in this tuto­r­ial here and you can down­load the source­code here.

Source 1: http://www.mulesoft.org/
Source 2: https://github.com/sones/sones-mule
Source 3: http://developers.sones.de/wiki/doku.php?id=tutorials:muleexampleapp

Not long ago we showed off the new capa­bil­i­ties of GraphDB 2.1 (to be released at the end of 2011) regard­ing the visu­al­iza­tion of data. Now we extended that capa­bil­i­ties and added another Out­put Plug-In to the Com­mu­nity Edi­tion. It’s called GraphVis.

And you can down­load it now with our source-code pack­age from our GitHub repos­i­tory.

The best way to show-off the new func­tion­al­ity is by lit­er­ally show­ing it:

A good start for the doc­u­men­ta­tion of the new visu­al­iza­tion options is our ever grow­ing wiki.

There is a new exam­ple avail­able for all the devel­op­ers out there who want to start using GraphDB.

This tuto­r­ial describes and shows the sim­plic­ity of set­ting up a GraphDB by using the sones GraphDB Com­mu­ni­tyEdi­tion. It shows  how to cre­ate your own data­base by using the sones GraphDB C# API and how to use GraphDB to cre­ate your own graph scheme (in not one but two dif­fer­ent approaches).

  1. by using GraphDB API Requests
  2. by using GraphQL queries

Beside the tuto­r­ial itself there is source code avail­able here.

If you are using the GraphQL please read our GraphQL Cheat­sheet there you can find the descrip­tion of all avail­able state­ments and some addi­tional examples.

The tuto­r­ial itself will show you how to:

  1. cre­ate user defined types, add struc­tured prop­er­ties, add unknown/schemeless properties
  2. cre­ate out­go­ing and incom­ing edges on a ver­tex type
  3. cre­ate an index on a spec­i­fied prop­erty in 3 dif­fer­ent ways
  4. set con­straints on prop­er­ties (like “unique” and “mandatory”)
  5. set up queries and ana­lyze them
  6. use func­tion and aggre­gates in a query

Source 1: C# TagEx­am­ple Tuto­r­ial
Source 2: C# TagEx­am­ple Source Code

The PHP Client is the lat­est com­mu­ni­ca­tion inter­face to our GraphDB Data­base. The library is very easy to use and include in exist­ing projects. Let’s take a short tour of the fea­tures of the PHP client:
First of all, visit our github repos­i­tory at: http://github.com/sones/sones-phpclient.
There, you can down­load the com­plete pack­age. Included in the php client is a short exam­ple on how to use the library. As part of the sones GraphDB Open Source Edi­tion (OSE) the whole source code is open to test.
The most impor­tant class for your project will be GraphDBClient.php, located in ./source/sones/.
The PHP client sets up a con­nec­tion to a GraphDB REST instance ser­vice based on a given URI. Fur­ther para­me­ter are the cre­den­tials like user­name and pass­word. Sim­ply include it in your project and cre­ate an instance:

Include_once ‘../source/sones/GraphDBClient.php’;

$myGrapgDB­Client = new GraphDBClient.php($myURI, $myUser­name, $myPassword);

After you cre­ate an instance you can insert GraphQL queries to your GraphDB with:

$myRe­sult = $myGrapDBClient->InsertQuery(“Create Ver­tex User Attributes(String Name)”);

This method returns a QueryRe­sult value which con­tains the response of the Data­base in a parsed form. The API han­dles ver­tices, edges and some Meta data.

$myVer­tices = $myResult->getVertices();

Of course in order to have a rep­re­sen­ta­tion of exist­ing sys­tems you cre­ate one instance for each GraphDB.
You can take a look at the Demo Exam­ple, which shows some usage of the library. If you want to test the PHP Client, you’ll need a Data­base. I rec­om­mend the Open Source Edi­tion (OSE) of the GraphDB, located also at github. The Demo Exam­ple uses the OSE, too. Because of that the default para­me­ters for the con­nec­tion are already set. The out­put of the Demo Exam­ple is split in two. On the one hand is the parsed out­put of the data­base, and on the other the source code which was exe­cuted. There is just one addi­tional class which gen­er­ates the visu­al­ized out­put of the GraphDB.

Impor­tant:
If you want to use the DemoEx­am­ple you have to set “max_execution_time” to false (max_execution_time = false) in the php.ini. DemoEx­am­ple inserts many GraphQL state­ments to the GraphDB at the begin­ning in order to store some data. This progress takes a while and over­stepped my max­i­mum exe­cu­tion time and ended with an error. There are also some warn­ings about the ‘include_once’ of some intern classes.
There is some adapted func­tion­al­ity, which could not be imple­mented truth­fully, because of the weak typ­ing dis­ci­pline. There are also some miss­ing fea­tures in the ini­tial release, tra­verse meth­ods, for exam­ple. Have a try!.

Alex Popescu, author of the well-known MyNoSQL blog recently wrote about a very (very) basic tag­ging app and its imple­men­ta­tion within the Info­Grid and Neo4j graph data­base systems.

Today we want to pick up the given exam­ple and show you an imple­men­ta­tion using the sones GraphDB and the GraphDB­Sharp API:

 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 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 Tags { get; set; } public Website() { } } public class TagExample { private void CheckResult(QueryResult myQueryResult) { Console.WriteLine("{0} => {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() { _good } }; var _xkcd = new Website() { Name = "xkcd", URL = "http://xkcd.com/", Tags = new List() { _good, _funny } }; var _onion = new Website() { Name = "onion", URL = "http://theonion.com/", Tags = new List() { _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) _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)>0"); foreach (var _sites in (List) _taggedsites[0]) Console.WriteLine("{0} => {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(); } } } 

 

The cur­rent C# API is already very expres­sive, but other pro­gram­ming lan­guages might be much more ver­bose. To avoid writ­ing a lot of code, you can always use our Graph Query Lan­u­age (GraphQL) which is an opti­mized Domain-specific lan­guage (DSL) for cre­at­ing and manip­u­lat­ing a graph within our database.

 CREATE TYPES Tag EXTENDS DBObject ATTRIBUTES (String Name) BACKWARDEDGES (Website.Tags TaggedWebsites) INDICES (Name), Website EXTENDS DBObject ATTRIBUTES (String Name, String URL, LIST 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)>0 

 

For an eas­ier access to any sones GraphDB instance you can use the our new web based shell. It is based on well-known tech­nolo­gies and libraries like HTML, JavaScript, JQuery and our REST API. You can choose between a text-based out­put for­mat like shown in the fol­low­ing screen shot, a XML out­put for­mat or a JSON out­put format.

WebShell-01-small

The Web­Shell ist Open Source Soft­ware and licensed under the New BSD License.

To get access to your own per­sonal test instance go to the sones home­page and reg­is­ter a new account. When you’re logged in you’re only one click away from access­ing the sones graphDB Web­Shell. You can log in using the given URL and the user­name and password.