Newbie Questions (Matching Mainly)


#1

Hi, Sorry for the probably simple questions, but I’m new to Grakn and Graph databases as a whole, but I’m experienced in traditional SQL (mySQL) and I’m looking to see how Grakn could help take our product to the next level.

Basically its a CRM system for Recruitment and where I think it could well help is matching candidates with jobs and vice-versa.

Anyway, as a really basic starting point, I created a Ontology as below…
(Excuse the bad names of the relations, it was my first attempt at not quite understanding what I was doing!)

insert rating sub resource, datatype double;
insert name sub resource, datatype string;
insert "start_date" sub resource, datatype string;
insert "end_date" sub resource, datatype string;

# Define Roles
insert employee sub role;
insert employer sub role;
insert skill_holder sub role;
insert knowledge sub role;

# Define Entities
insert person sub entity has name, plays skill_holder, plays employee;
insert company sub entity has name, plays employer; 
insert skill sub entity has name, plays knowledge;

# Define Relationships
insert employment sub relation, relates employee,  relates employer,  has "start_date",  has "end_date";
insert skills sub relation, relates skill_holder, relates knowledge, has rating;

# insert Data
insert $x isa person, has name "Steve";
insert $x isa person, has name "Peter";

insert $c isa company, has name "Company A";

insert $x isa skill has name "PHP";
insert $x isa skill has name "Javascript";
insert $x isa skill has name "Delphi";
insert $x isa skill has name "Database Design";
insert $x isa skill has name "UI Design";

match $x isa person has name "Steve"; $c has name "Company A";insert (employee: $x, employer: $c) isa employment;
match $x isa person has name "Peter"; $c has name "Company A";insert (employee: $x, employer: $c) isa employment;

# Steve's Skills
match $x isa person has name "Steve"; $sk isa skill has name "PHP";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 90;
match $x isa person has name "Steve"; $sk isa skill has name "Javascript";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 90;
match $x isa person has name "Steve"; $sk isa skill has name "Delphi";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 90;
match $x isa person has name "Steve"; $sk isa skill has name "Database Design";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 90;
match $x isa person has name "Steve"; $sk isa skill has name "UI Design";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 90;

#Peter's Skills
match $x isa person has name "Peter"; $sk isa skill has name "PHP";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 70;
match $x isa person has name "Peter"; $sk isa skill has name "Javascript";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 70;
match $x isa person has name "Peter"; $sk isa skill has name "Database Design";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 50;
match $x isa person has name "Peter"; $sk isa skill has name "UI Design";insert (skill_holder: $x, knowledge: $sk) isa skills, has rating 20;

What I would like to do is find out which people have PHP as a skill ( I think I have this now ( match ($x,$y) isa skills; $x isa skill, has name “PHP”;)).
Which people have PHP and Delphi as a Skill (I thought match ($x,$y) isa skills; $x isa skill, has name “PHP” or has name “Delphi”; but this brings back about 23 ‘rows’!)

Out of interest, how would I get a list of the Skills Peter and Steve have in common?

I know this is a trivial example, but I want to start off with the basics first and then grow from there.

TIA

Steve.


#2

Hi Steve,

What I would like to do is find out which people have PHP as a skill ( I think I have this now ( match ($x,$y) isa skills; $x isa skill, has name “PHP”;)).

Yeah, this one is exactly right!

Which people have PHP and Delphi as a Skill (I thought match ($x,$y) isa skills; $x isa skill, has name “PHP” or has name “Delphi”; but this brings back about 23 ‘rows’!)

This is nearly correct and I can definitely understand your thinking. The catch is, the property has name "Delphi" is not applied to $x. Instead, it gets applied to a new, anonymous variable:

match
($x,$y) isa skills;
{ $x isa skill, has name “PHP”; } or { $ANON has name “Delphi”; };

You should instead explicitly state the variable you are applying the property to:

match
($x,$y) isa skills;
$x isa skill;
{$x has name “PHP”; } or { $x has name “Delphi”; };

I’ve added the braces for clarity, but they are not strictly necessary.

Out of interest, how would I get a list of the Skills Peter and Steve have in common?

match
$peter has name "Peter";
$steve has name "Steve";
($peter, $skill) isa skills;
($steve, $skill) isa skills;