It has been over a month since Davide,Alessandro and I started working on WikiToLearn:Ratings  for GSoC-2016 and we have already started with Database design . I have already shared my experiences while setting up OrientDB inside  docker in this post. So now let’s take a step further and talk about how we made a sample graph database to represent our project (abstract here). To understand it in a better way , let’s consider the following scenario:

Jon,Jacob and Josh study Physics at a renowned university. One day they came across WikiToLearn  and they were deeply influenced by it’ s philosophy –knowledge only grows if shared. Being roommates they arrived at a collective decision to share their knowledge and author a course on Mechanics under physics  section on WikiToLearn.
So Jon decided to write about Newton Law,Josh about Work and Power . Jacob was busy with his cookery classes so Josh decided to author Pseudo Force for him while he was away.They were very happy with their work and wanted to share their work with all the university students but before that they decided to proof read each other’s work. So while doing it they improvised some of the sections of pages written. Now they came to know that WikiToLearn has this unique feature called Versions. Basically versions are a great way to keep track of the history of changes such that whenever a page is changed a new version is stacked on the top of old one such that it forms a chain of changes and only latest version is accessible to users. So they created versions on each other’s work by reviewing and editing is subsequently. Now when they are done reviewing they vote the page content so that the entire course rating can be generated by the Rating Engine.
Each user has some credibility that will determine the weight carried by his vote.This will be determined by his loyalty to WikiToLearn platform( his activities  like contributions,reviews,days active).Here it is essential to remember that a contributor can’t vote his own work.( 😛 ). So now the work of the editors is over and now it’s up to the Rating Engine to calculate the Reliability of their work.They are waiting with their fingers crossed!

So to model this type of information I basically used OrientDB as a graph database.Let’s see a simple way of doing it.

Vertices and Edges:

So in this scene we have some entities like User,Page,Course and Version. These entities will form the heart of our graphical database. Information like User’s Name , Page Name will be embedded inside these entities. These entities will interact with each other with various relationships like Jon contributes newton law. 
In OrientDB these entities are  represented by Vertices and relationships by Edges of a graph.

Setting up the vertices:

Just like the Object Oriented terminology we extend out custom made classes to the base ones so in the web editor or the console,issue the following commands:

CREATE CLASS USER EXTENDS V
CREATE CLASS PAGE EXTENDS V
CREATE CLASS COURSE EXTENDS V
CREATE CLASS VERSION EXTENDS V
CREATE CLASS CONTRIBUTE EXTENDS E
CREATE CLASS REVIEW EXTENDS E
CREATE CLASS INSIDE EXTENDS E
CREATE CLASS V_STACK EXTENDS E
CREATE CLASS P_VERSION EXTENDS E

Let’s now embed information inside the vertices and edges don’t worry if you don’t understand all the used parameters they will be explained in the subsequent posts.

USER:

CREATE VERTEX USER SET NAME="JON",J_DATE="2014-05-12"


CREATE VERTEX USER SET NAME="JOSH",J_DATE="2015-05-20"


CREATE VERTEX USER SET NAME="JACOB",J_DATE="2013-12-10"

PAGE:

CREATE VERTEX PAGE SET NAME="NEWTON LAW",C_RELIABILITY=2.0,RATING=3.4


CREATE VERTEX PAGE SET NAME="WORK AND POWER",C_RELIABILITY=2.0,RATING=3.4


CREATE VERTEX PAGE SET NAME="PSEUDO FORCE",C_RELIABILITY=2.0,RATING=3.4

VERSION:

CREATE VERTEX VERSION SET V_NO=0,P_NAME="NEWTON LAW",C_RELIABILITY=1.0,RATING=4.2


CREATE VERTEX VERSION SET V_NO=1,P_NAME="NEWTON LAW",C_RELIABILITY=1.0,RATING=4.2


CREATE VERTEX VERSION SET V_NO=1,P_NAME="WORK AND POWER",C_RELIABILITY=1.0,RATING=4.2


CREATE VERTEX VERSION SET V_NO=0,P_NAME="WORK AND POWER",C_RELIABILITY=1.0,RATING=4.2


CREATE VERTEX VERSION SET V_NO=0,P_NAME="PSEUDO FORCE",C_RELIABILITY=1.0,RATING=4.2


CREATE VERTEX VERSION SET V_NO=1,P_NAME="PSEUDO FORCE",C_RELIABILITY=1.0,RATING=4.2

COURSE:

CREATE VERTEX COURSE SET NAME="MECHANICS",C_RELIABILITY=2.0,C_VOTE=5.2

Drawing Edges:

So now we need to link the disjoint vertices with relationships.We need to connect the contributor to his work (CONTRIBUTE), Reviewer to content reviewed(REVIEW), pages to course(INSIDE), Versions to pages in a stack like manner (V_STACK) and finally linking the current version to pages(P_VERSION). Let’s see them one by one:

CONTRIBUTE:

CREATE EDGE CONTRIBUTE FROM (SELECT FROM USER WHERE NAME="JON") TO (SELECT FROM VERSION WHERE P_NAME="NEWTON LAW")


CREATE EDGE CONTRIBUTE FROM (SELECT FROM USER WHERE NAME="JOSH") TO (SELECT FROM VERSION WHERE P_NAME="WORK AND POWER" OR (P_NAME="PSEUDO FORCE" AND V_NO=0))


CREATE EDGE CONTRIBUTE FROM (SELECT FROM USER WHERE NAME="JACOB") TO (SELECT FROM VERSION WHERE P_NAME="PSEUDO FORCE" AND V_NO=1)

REVIEW:

CREATE EDGE REVIEW FROM (SELECT FROM USER WHERE NAME="JON") TO (SELECT FROM VERSION WHERE P_NAME="PSEUDO FORCE" AND V_NO=0) SET VOTE=5


CREATE EDGE REVIEW FROM (SELECT FROM USER WHERE NAME="JOSH") TO (SELECT FROM VERSION WHERE P_NAME="NEWTON LAW" AND V_NO=1) SET VOTE=8


CREATE EDGE REVIEW FROM (SELECT FROM USER WHERE NAME="JACOB") TO (SELECT FROM VERSION WHERE P_NAME="WORK AND POWER" ) SET VOTE=9

P_VERSION:

CREATE EDGE P_VERSION FROM (SELECT * FROM VERSION WHERE P_NAME="NEWTON LAW" AND V_NO=0) TO (SELECT * FROM VERSION WHERE P_NAME="NEWTON LAW" AND V_NO=1)


CREATE EDGE P_VERSION FROM (SELECT * FROM VERSION WHERE P_NAME="PSEUDO FORCE" AND V_NO=0) TO (SELECT * FROM VERSION WHERE P_NAME="PSEUDO FORCE" AND V_NO=1)


CREATE EDGE P_VERSION FROM (SELECT * FROM VERSION WHERE P_NAME="WORK AND POWER" AND V_NO=0) TO (SELECT * FROM VERSION WHERE P_NAME="WORK AND POWER" AND V_NO=1)

V_STACK:

CREATE EDGE V_STACK FROM (SELECT * FROM VERSION WHERE P_NAME="NEWTON LAW" AND V_NO=1) TO (SELECT * FROM PAGE WHERE NAME ="NEWTON LAW")


CREATE EDGE V_STACK FROM (SELECT * FROM VERSION WHERE P_NAME="WORK AND POWER" AND V_NO=1) TO (SELECT * FROM PAGE WHERE NAME ="WORK AND POWER")


CREATE EDGE V_STACK FROM (SELECT * FROM VERSION WHERE P_NAME="PSEUDO FORCE" AND V_NO=1) TO (SELECT * FROM PAGE WHERE NAME ="PSEUDO FORCE")

Voila! here it is 🙂

ori

 

Advertisements