Creating Knowledge Graphs

Wouter Beek (wouter@triply.cc)

Core conceptual content
Core technical content

Overview

  1. Names
  2. Triples
  3. Graphs

Part 1: Names

What does ‘40’ mean?
“40 feet?”
“40 meters?”

Another example of ambiguity

Who or what is ‘Mew’?


In a Knowledge Graph, names must be unambiguous

Names (1/2): IRIs

Globally unique & unambiguous names.

‘Mew’ the Pokemon
https://demo.triply.cc/academy/pokemon/id/pokemon/mew
‘Mew’ the band
http://dbpedia.org/resource/Mew_(band)
Etc.

Names (2/2): Literals

Some things are not easily expressed with IRIs.

Natural language
あらゆる わざを つかうため ポケモンの せんぞと かんがえる がくしゃが たくさん いる。
Numbers
0.333333; 1,000,000,000; etc.
Date/time
2018-01-01T09:30:45.0Z
Etc.

Syntax for names

  • IRI
    <https://demo.triply.cc/academy/pokemon/id/pokemon/mew>
  • Literal
    • Typed literal
      "40"^^<http://www.w3.org/2001/XMLSchema#integer>
    • Language-tagged string
      "ミュウ"@ja

Short syntax for names (1/2): IRIs

Full IRI

<https://demo.triply.cc/academy/pokemon/id/pokemon/mew>

Prefix declaration

prefix pokemon: <https://demo.triply.cc/academy/pokemon/id/pokemon/>

Short IRI

pokemon:mew

Short syntax for names (2/2): Literals

Full literal

"40"^^<http://www.w3.org/2001/XMLSchema#integer>

Prefix declaration

prefix xsd: <http://www.w3.org/2001/XMLSchema#>

Short literal

"40"^^xsd:integer
prefix : <https://example.org/>
prefix dce: <http://purl.org/dc/elements/1.1/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix graph: <http://demo.triply.cc/academy/pokemon/graph/>
prefix pokemon: <https://demo.triply.cc/academy/pokemon/id/pokemon/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix time: <http://www.w3.org/2006/time#>
prefix vocab: <https://demo.triply.cc/academy/pokemon/def/>
prefix void: <http://rdfs.org/ns/void#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
In the following, we will assume these prefix declarations.

Part 2: Triples

By combining names, we can express meaning.


The smallest unit of meaning in a Knowledge Graph is called a ‘triple’

Semantics of a triple

“Pikachu knows Mew.”

(The resource ‘Pikachu’ and the resource ‘Mew’ are related (in that order) by the ‘knows’ property.)

Syntax of a triple

pokemon:pikachu foaf:knows pokemon:mew.
A sequence of three names.

Two views of a triple: Statement & Arc

pokemon:pikachu foaf:knows pokemon:mew.

Statement

  • Subject (pokemon:pikachu)
  • Predicate (foaf:knows)
  • Object (pokemon:mew)

Arc

  • Nodes (pokemon:pikachu & pokemon:mew)
  • Predicate (foaf:knows)

Part 3: Graphs

Graph

A collection of zero or more triples.

A graph with 1 triple

Semantics

Syntax

pokemon:pikachu foaf:knows pokemon:mew.

A graph with 3 triples

pokemon:pikachu foaf:knows   pokemon:mew.
pokemon:pikachu vocab:name   "ピカチュウ"@ja.
pokemon:pikachu vocab:weight "60"^^xsd:integer.

Short Syntax for triples (1/2)

:s :p :o1;
   :q :o2,
      :o3.
:s :p :o1.
:s :q :o2.
:s :q :o3.
Dot (.)
Regular end of triple symbol.
Semicolon (;)
The next triple uses the same subject term (:s).
Comma (,)
The next triple uses the same subject and predicate terms (:s :q).

Short syntax for triples (2/2)

:s :p 60,
      60.0,
      6.0e2,
      "6".
:s :p "60"^^xsd:integer.
:s :p "60.0"^^xsd:decimal.
:s :p "6.0e2"^^xsd:double,
:s :p "6"^^xsd:string.
  • Whole numbers (60) have datatype IRI xsd:integer.
  • Numbers with a decimal separator (60.0) have datatype IRI xsd:decimal.
  • Numbers with decimal separator ánd engineering notation (6.0e2) have datatype IRI xsd:double.
  • Strings ("6") have datatype IRI xsd:string.

A graph with 3 triples (short syntax)

pokemon:pikachu foaf:knows   pokemon:mew;
                vocab:name   "ピカチュウ"@ja;
                vocab:weight 60.

A graph with 6 triples (short syntax)

pokemon:mew     vocab:name   "ミュウ"@ja;
                vocab:weight 40.
pokemon:pikachu foaf:knows   pokemon:mew;
                vocab:name   "ピカチュウ"@ja;
                vocab:weight 60.

[Advanced] Part 4: Datasets

Dataset

A collection of named graphs.

A simple dataset

graph:mew {
  pokemon:mew vocab:name   "ミュウ"@ja;
              vocab:weight 40.
}

graph:pikachu {
  pokemon:pikachu foaf:knows   pokemon:mew;
                  vocab:name   "ピカチュウ"@ja;
                  vocab:weight 60.
}

Dataset description

graph:mew {
  pokemon:mew vocab:name   "ミュウ"@ja;
         vocab:weight 40.
}

graph:pikachu {
  pokemon:pikachu foaf:knows   pokemon:mew;
                  vocab:name   "ピカチュウ"@ja;
                  vocab:weight 60.
}

<https://triply.cc/academy/pokemon/> a void:Dataset;
  void:subset graph:mew;
  void:subject graph:pokemon.

[Advanced] Events

Event example

John worked at the UvA throughout 2017.

Event (❌)

:john :worksAt :uva;
      :begin   "2017-01-01"^^xsd:date;
      :end     "2017-12-31"^^xsd:date.

Event (✓)

:john :worksAt :uva.
:event rdf:subject   :john;
       rdf:predicate :worksAt;
       rdf:object    :uva;
       :begin        "2017-01-01"^^xsd:date;
       :end          "2017-12-31"^^xsd:date.

RDF reification vocabulary

Event + uncertainty (✓)

:john :worksAt :uva.
:event rdf:subject   :john;
       rdf:predicate :worksAt;
       rdf:object    :uva;
       time:hasBeginning [
         time:inXSDDate "2017-01-01"^^xsd:date;
         time:unitType  time:unitWeek ];
       time:hasEnd [
         time:inXSDDate "2017-12-31"^^xsd:date;
         time:unitType  time:unitWeek ].

http://www.w3.org/2006/time# (Time Ontology in OWL)

Units of measure

Units of measure (❌)

pokemon:pikachu vocab:weight 60.

Weight in pounds, grams, etc?

Units of measure (✓)

pokemon:pikachu vocab:weight [ vocab:unit vocab:kilogram;
                               rdf:value  60 ].

Use an intermediate node to combine the unit of measure (dbd:unit) with the value (rdf:value).

Units of measure (✓)

pokemon:pikachu vocab:weight "60"^^dbd:kilogram.

Use a datatype IRI that expresses the unit of measure (dbd:kilogram).

Thank you for your attention!