Semantic Web technologies enable us to represent and query for very complex and heterogeneous datasets. We can add semantics and reason over large bodies of data on the web. However, despite a lot of educational material available, they have failed to achieve mass adoption outside academia.
TypeDB works at a higher level of abstraction and enables developers to be more productive when working with complex data. TypeDB is easier to learn, reducing the barrier to entry and enabling more developers to access semantic technologies. Instead of using a myriad of standards and technologies, we just use one language - TypeQL.
In this talk we will:
- look at how TypeQL compares to Semantic Web standards, specifically RDF, SPARQL RDFS, OWL and SHACL.
- cover questions such as, how do we represent hyper-relations in TypeDB? How does one use rdfs:domain and rdfs:range in TypeDB? And how do the modelling philosophies compare?
Speaker: Tomás Sabat
Tomás is the Chief Operating Officer at Vaticle. He works closely with TypeDB's open source and enterprise users who use TypeDB to build applications in a wide number of industries including financial services, life sciences, cyber security and supply chain management. A graduate of the University of Cambridge, Tomás has spent the last seven years founding and building businesses in the technology industry.
16. RDF Triples
foaf:Person foaf:Person
foaf:knows
“Peter Parker” “Aunt May”
foaf:name foaf:name
Person
Person knows
name: ”Peter
Parker”
name: ”Aunt
May”
Instead of triples, TypeDB implements a concept level entity-relationship
model
Peter Parker knows Aunt May
17. RDF Triples
foaf:Person foaf:Person
foaf:knows
“Peter Parker” “Aunt May”
foaf:name foaf:name
Person
Person knows
name: ”Peter
Parker”
name: ”Aunt
May”
NB: TypeDB does not use public namespaces
Peter Parker knows Aunt May
19. RDF Triples
foaf:Person foaf:Person
foaf:knows
“Peter Parker” “Aunt May”
foaf:name foaf:name
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<foaf:Person>
<foaf:name>Peter Parker</foaf:name>
<foaf:knows>
<foaf:Person>
<foaf:name>Aunt May</foaf:name>
</foaf:Person>
</foaf:knows>
</foaf:Person>
</rdf:RDF>
$p isa person, has name "Peter Parker";
$p2 isa person, has name "Aunt May";
($p, $p2) isa knows;
20. RDF Triples
foaf:Person foaf:Person
foaf:knows
“Peter Parker” “Aunt May”
foaf:name foaf:name
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<foaf:Person>
<foaf:name>Peter Parker</foaf:name>
<foaf:knows>
<foaf:Person>
<foaf:name>Aunt May</foaf:name>
</foaf:Person>
</foaf:knows>
</foaf:Person>
</rdf:RDF>
$p isa person, has name $n,
has uri "http://xmlns.com/foaf/0.1/Person";
$n "Peter Parker”; $n has uri
"http://xmlns.com/foaf/0.1/name";
$p1 isa person, has name $n1,
has uri "http://xmlns.com/foaf/0.1/Person";
$n1 "Aunt May"; $n1 has uri
"http://xmlns.com/foaf/0.1/name";
($p, $p1) isa knows,
has uri "http://xmlns.com/foaf/0.1/knows";
NB: We can add URIs as attributes in TypeDB.
31. Higher Order Relationships
lit:HarryPotter bio:author lit:JKRowling .
lit:HarryPotter lit:JKRowling
bio:author
bio:n1 bio:author lit:JKRowling .
bio:n1 bio:title "Harry Potter" .
bio:n1 bio:publicationDate 2000 .
bio:n1 lit:JKRowling
bio:author
JK Rowling wrote Harry Potter JK Rowling wrote Harry Potter in 2000
”Harry Potter”
2000
bio:title
bio:publicationDate
32. Higher Order Relationships
bio:n1 bio:author lit:JKRowling .
bio:n1 bio:title "Harry Potter" .
bio:n1 bio:publicationDate 2000 .
bio:n1 lit:JKRowling
bio:author
JK Rowling wrote Harry Potter in 2000
”Harry Potter”
2000
bio:title
bio:publicationDate
date 2000
book authorship person
name: ”JK
Rowling”
name: ”Harry
Potter”
$a isa person, has name "JK Rowling";
$b isa book, has name "Harry Potter";
(author: $a, publication: $b) isa authorship,
has date "2000";
33. Blank Nodes
Harry Potter was inspired by a man who lives in England
lit: HarryPotter bio:name lit:"Harry Potter" .
lit:HarryPotter lit:hasInspiration [a :Man;
bio:livesIn geo:England] .
34. Blank Nodes
Harry Potter was inspired by a man who lives in England
lit: HarryPotter bio:name lit:"Harry Potter" .
lit:HarryPotter lit:hasInspiration [a :Man;
bio:livesIn geo:England] .
$b isa book, has name "Harry Potter";
$m isa man;
($b, $m) isa inspiration;
$l isa location, has name "England";
($m, $l) isa lives-in;
35. Blank Nodes
Harry Potter was inspired by a man who lives in England
Or, we query for a thing without a key “URI”.
lit: HarryPotter bio:name lit:"Harry Potter" .
lit:HarryPotter lit:hasInspiration [a :Man;
bio:livesIn geo:England] .
$b isa book, has name "Harry Potter";
$m isa man;
($b, $m) isa inspiration;
$l isa location, has name "England";
($m, $l) isa lives-in;
38. Inserting Data
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
<http://example/book1> dc:title "A new book" ;
dc:creator "A.N.Other" .
}
A book with the title “New Book” and creator “A.N.Other”.
39. Inserting Data
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
<http://example/book1> dc:title "A new book" ;
dc:creator "A.N.Other" .
}
insert
$b isa book, has title "A new book", has creator
"A.N.Other";
A book with the title “New Book” and creator “A.N.Other”.
41. Querying for Data
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?whom
WHERE {
?person rdf:type foaf:Person .
?person vcard:family-name "Smith" .
?person vcard:given-name "Adam" .
?person foaf:knows ?whom .
}
Who are all the persons that “Adam Smith” knows?
42. Querying for Data
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?whom
WHERE {
?person rdf:type foaf:Person .
?person vcard:family-name "Smith" .
?person vcard:given-name "Adam" .
?person foaf:knows ?whom .
}
match
$p isa person, has family-name "Smith", has given-name
"Adam";
($p, $p2) isa knows; get $p2;
Who are all the persons that “Adam Smith” knows?
43. Querying for Data
Give me the director and movies that James Dean played in, where also a woman played a role,
and that woman played in a movie directed by John Ford.
44. Querying for Data
PREFIX movie: <http://example.com/moviedb/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX. foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?director ?movie
WHERE {
?actor rdf:type foaf:Man ;
movie:name "James Dean" ;
movie:playedIn ?movie .
?actress movie:playedIn ?movie ;
rdf:type foaf:Woman ;
movie:playedIn ?anotherMovie .
?JohnFord rdf:type foaf:Man ;
movie:name "John Ford" .
?anotherMovie movie:directedBy ?JohnFord .
}
Give me the director and movies that James Dean played in, where also a woman played a role,
and that woman played in a movie directed by John Ford.
45. Querying for Data
PREFIX movie: <http://example.com/moviedb/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX. foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?director ?movie
WHERE {
?actor rdf:type foaf:Man ;
movie:name "James Dean" ;
movie:playedIn ?movie .
?actress movie:playedIn ?movie ;
rdf:type foaf:Woman ;
movie:playedIn ?anotherMovie .
?JohnFord rdf:type foaf:Man ;
movie:name "John Ford" .
?anotherMovie movie:directedBy ?JohnFord .
}
match
$p isa man, has name "James Dean";
$w isa woman; (actor: $p, actress: $w, casted-movie: $m) isa
casting;
(actress: $w, casted-movie: $m2) isa casting;
$d isa man, has name "John Ford";
($m2, $d) isa directorship;
get $d, $m;
Give me the director and movies that James Dean played in, where also a woman played a role,
and that woman played in a movie directed by John Ford.
47. Querying for Data
James Dean
casting
actor
woman
movie
casting
movie directorship John Ford
actress
casted-
movie
casted-
movie
actress
director
directed-
movie
56. Multiple Inheritance
company rdf:type rdfs:Class
government rdf:type rdfs:Class
employer rdf:type rdfs:Class
employer rdfs:subClassOf company
employer rdfs:subClassOf government
company government
employer
rdfs:subClassOf
rdfs:subClassOf
57. Multiple Inheritance
company rdf:type rdfs:Class
government rdf:type rdfs:Class
employer rdf:type rdfs:Class
employer rdfs:subClassOf company
employer rdfs:subClassOf government
company sub entity,
plays employment:employer;
government sub entity,
plays employment:employer;
employment sub relation,
relates employer;
company government
employer
rdfs:subClassOf
rdfs:subClassOf
employment
employer
company
employment
employer
government
60. rdfs:domain and rdfs:range
:publishedOn rdfs:domain :PublishedBook
rdfs:domain
… ...
:publishedOn
:PublishedBook
rdfs:domain
when {
$b has published-date $pd;
} then {
(published-book: $b) isa publishing;
};
61. rdfs:domain and rdfs:range
:hasBrother rdfs:range :Male
rdfs:range
… ...
:hasBrother
:Male
rdfs:range
when {
$r (brother: $p) isa siblingship;
} then {
$p has gender "male";
};
62. If we have a vessel of class DepartingVessel, which has the Property nextDeparture specified, we could state:
ship:Vessel rdf:type rdfs:Class .
ship:DepartingVessel rdf:type rdfs:Class .
ship:nextDeparture rdf:type rdf:Property .
ship:QEII a ship:Vessel .
ship:QEII ship:nextDeparture "Mar 4, 2010" .
rdfs:domain and rdfs:range
63. If we have a vessel of class DepartingVessel, which has the Property nextDeparture specified, we could state:
ship:Vessel rdf:type rdfs:Class .
ship:DepartingVessel rdf:type rdfs:Class .
ship:nextDeparture rdf:type rdf:Property .
ship:QEII a ship:Vessel .
ship:QEII ship:nextDeparture "Mar 4, 2010" .
rdfs:domain and rdfs:range
With rdfs:domain, any vessel with nextDeparture will be inferred to be a DepartingVessel:
ship:nextDeparture rdfs:domain ship:DepartingVessel .
64. If we have a vessel of class DepartingVessel, which has the Property nextDeparture specified, we could state:
ship:Vessel rdf:type rdfs:Class .
ship:DepartingVessel rdf:type rdfs:Class .
ship:nextDeparture rdf:type rdf:Property .
ship:QEII a ship:Vessel .
ship:QEII ship:nextDeparture "Mar 4, 2010" .
rdfs:domain and rdfs:range
With rdfs:domain, any vessel with nextDeparture will be inferred to be a DepartingVessel:
ship:nextDeparture rdfs:domain ship:DepartingVessel .
“QEII” will now be a member of the DepartingVessel class.
65. In TypeDB, we write a rule that connect any entity with a next-departure attribute to the departing-vessel role.
rdfs:domain and rdfs:range
when {
$s has next-departure $nd;
} then {
(departing-vessel: $s) isa departure;
};
66. In TypeDB, we write a rule that connect any entity with a next-departure attribute to the departing-vessel role.
rdfs:domain and rdfs:range
when {
$s has next-departure $nd;
} then {
(departing-vessel: $s) isa departure;
};
If we insert this data:
$s isa vessel, has name "QEII", has next-departure "Mar 4, 2010";
67. In TypeDB, we write a rule that connect any entity with a next-departure attribute to the departing-vessel role.
rdfs:domain and rdfs:range
when {
$s has next-departure $nd;
} then {
(departing-vessel: $s) isa departure;
};
If we insert this data:
$s isa vessel, has name "QEII", has next-departure "Mar 4, 2010";
TypeDB will infer that QEII plays the role departing-vessel in a departure relation.
70. OWL Restrictions
:Person
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :hasParent ;
owl:allValuesFrom :Person
] .
AllValuesFrom: The range of hasParent with Person/Animal classes can only Person-parents/Animal-parents values.
71. OWL Restrictions
:Person
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :hasParent ;
owl:allValuesFrom :Person
] .
:Animal
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :hasParent ;
owl:allValuesFrom :Animal
] .
AllValuesFrom: The range of hasParent with Person/Animal classes can only Person-parents/Animal-parents values.
72. OWL Restrictions
:Person
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :hasParent ;
owl:allValuesFrom :Person
] .
:Animal
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :hasParent ;
owl:allValuesFrom :Animal
] .
person sub entity,
plays person-parentship:child,
plays person-parentship:parent;
animal sub entity,
plays animal-parentship:child,
plays animal-parentship:parent;
parentship sub relation, abstract;
person-parentship sub parentship,
relates child,
relates parent;
animal-parentship sub parentship,
relates child,
relates parent;
AllValuesFrom: The range of hasParent with Person/Animal classes can only Person-parents/Animal-parents values.
73. Transitive Properties
If A is connected to B, and B is connected to C, then A is connected to C.
London
located
UK Kings Cross
located
located
74. Transitive Properties
:isLocated rdf:type owl:TransitiveProperty.
If A is connected to B, and B is connected to C, then A is connected to C.
London
located
UK Kings Cross
located
located
75. Transitive Properties
:isLocated rdf:type owl:TransitiveProperty.
:KingsCross :isLocated :London.
:London :isLocated :UK.
:UK : :isLocated :Europe.
If A is connected to B, and B is connected to C, then A is connected to C.
London
located
UK Kings Cross
located
located
76. Transitive Properties
:isLocated rdf:type owl:TransitiveProperty.
:KingsCross :isLocated :London.
:London :isLocated :UK.
:UK : :isLocated :Europe.
when {
$r1 (located: $a, locating: $b);
$r2 (located: $b, locating: $c);
} then {
(located: $a, locating: $c);
};
If A is connected to B, and B is connected to C, then A is connected to C.
London
located
UK Kings Cross
located
located
77. Transitive Properties
:isLocated rdf:type owl:TransitiveProperty.
:KingsCross :isLocated :London.
:London :isLocated :UK.
:UK : :isLocated :Europe.
when {
$r1 (located: $a, locating: $b);
$r2 (located: $b, locating: $c);
} then {
(located: $a, locating: $c);
};
If A is connected to B, and B is connected to C, then A is connected to C.
With this TypeDB rule, if we insert:
insert
$ldn isa city, has name "London";
$uk isa country, has name "Uk";
$eu isa continent, has name "Europe";
(located: $ldn, locating: $uk);
(located: $uk, locating: $eu);
78. Transitive Properties
:isLocated rdf:type owl:TransitiveProperty.
:KingsCross :isLocated :London.
:London :isLocated :UK.
:UK : :isLocated :Europe.
when {
$r1 (located: $a, locating: $b);
$r2 (located: $b, locating: $c);
} then {
(located: $a, locating: $c);
};
If A is connected to B, and B is connected to C, then A is connected to C.
With this TypeDB rule, if we insert:
This query will return UK and London:
match
$eu isa continent, has name "Europe";
(locating: $eu, located: $loc); get $loc;
insert
$ldn isa city, has name "London";
$uk isa country, has name "Uk";
$eu isa continent, has name "Europe";
(located: $ldn, locating: $uk);
(located: $uk, locating: $eu);
81. Equivalent Properties
:borrows owl:equivalentProperty :checkedOut . when {
(borrower: $x, borrowing: $y) isa borrowing;
} then {
(checking-out: $x, checked-out: $y) isa checked-out;
};
Two properties have the same property extension.
$y
borrowing
$x
checked-out
84. hasValue
:RedWine
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty :color ;
owl:hasValue "red"
] .
when {
$w isa red-wine;
} then {
$w has color "red";
};
Red wines should have the colour “red” property
red-wine color: “red”
has
87. Verification with SHACL
:Person a sh:NodeShape, rdfs:Class ;
sh:property [
sh:path schema:worksFor ;
sh:node :Company ;
] .
:Company a sh:Shape ;
sh:property [
sh:path schema:name ;
sh:datatype xsd:string;
] .
Restrict person to work for a company
Restrict a company to have a name attribute of value string
88. Verification with SHACL
:Person a sh:NodeShape, rdfs:Class ;
sh:property [
sh:path schema:worksFor ;
sh:node :Company ;
] .
:Company a sh:Shape ;
sh:property [
sh:path schema:name ;
sh:datatype xsd:string;
] .
define
person sub entity,
plays employment:employee;
company sub entity,
owns name,
plays employment:employer;
employment sub relation,
relates employer,
relates employee;
name sub attribute, value string;
Restrict person to work for a company
Restrict a company to have a name attribute of value string
89. TypeDB reduces the complexity while maintaining a high degree of expressivity
90. TypeDB provides a higher-level abstraction for working with complex data
91. Semantic Web Standards are built for the Web, TypeDB works for closed world systems
with private data