A brief introduction to the syntax of knowledge graphs
Introducing a simple syntax for Resource Description Framework (RDF).
The British computer scientist, Tim Berners-Lee, had a vision for the World Wide Web, that all data could be analysed. Content, links, transactions between machine and human, and between machine and machine. His vision was a “semantic web”.
Semantic technologies are coined on this vision and encodes the meaning behind data and content, separate from applications. This makes it possible for humans and machines to share and reason on data during runtime.
This technology provides a common framework that give the possibility of data being used and re-used across applications. Development of these technologies is lead by World Wide Web Consortium (W3C) in cooporation with several scientists and other professionals.
The foundation of the semantic technologies is Resource Description Framework (RDF), which I will cover in this article. RDF is the foundational technology in knowledge graphs.

I am not considering this article as a part of my From Data Engineering to Knowledge Engineering series, but this might work as a handy helper to you who are not familiar with the syntax of knowledge graphs.
Resource Description Framework
Disclaimer: Forget everything you know about tabular data. 😎
Think about data as directed graphs, and that all things has a relation to other things.
RDF describes data as a directed graph. Which means that all edges of the graph are pointing in a certain direction.
Data is described as triples, consisting of a subject, a predicate, and an object.
A triple might be referred to as a fact a statement.
All elements of a triple (subject, predicate and object) are a resource.
We use Uniform Resource Identifiers (URI) to denote resources from one another.
Uniform Resource Identifiers
An URI is only a name. It does not need to point to anything.
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]We usually create URIs under the HTTP domain, with some path and fragment that are unique for this specific resource. An example might be
http://example.org/birds#Eurasian_blue_titData as a directed graph
In this example we see that the resource Eurasian blue tit (the subject) has some relation to Paridae (the object). That relation is the named edge is of family (the predicate). We see that the edge go in one direction, which is true for every relation described with RDF. Let us have a look at this example written in one of the RDF syntaxes.
Syntax
Remember that RDF is only a standard describing data as directed graphs. There are several syntaxes for writing graphs following RDF. Traditionally RDF/XML was widely used. However, XML is a bit outdated and hard to read, so luckily there are several other options. Most used today is the Turtle syntax, and this is the one you will encounter while reading papers on semantic technologies describing data in RDF. Other popular options are JSON-LD and N-Triples.
<http://example.org/birds#Eurasian_blue_tit> <http://example.org/birds/family> <http://example.org/birds#Paridae> .The three URIs above describes the directed graph from previous image as RDF Turtle. One good thing about Turtle is that we do not have to write the full namespace (http://example.org/) each time we want to describe one resource.
@prefix birds: <http://example.org/birds> .
birds:Eurasian_blue_tit birds:family birds:Paridae .By prefixing the namespace to some name, we get to use only that name instead of the whole URI each time. Saves us some keystrokes!
Literal values
In object position of a triple, there might be a resource (object) or a literal (data value). There are five possible literal values that a predicate can point to.
birds:Eurasian_blue_tit birds:latinName “Cyanistes caeruleus” .
birds:Eurasian_blue_tit birds:name “Blåmeis”@no .
birds:Eurasian_blue_tit birds:firstDescribed “1555”^^xsd:gYear .
birds:Eurasian_blue_tit birds:avgWeight 11 .
birds:Eurasian_blue_tit birds:isABird true .First we have a plain string value.
String value with language tag
@nofor Norwegian.“1555”^^xsd:gYearis a typed literal. Typed as a year from the XSD-vocabulary.Plain numeric value.
Boolean value,
trueorfalse.
Compact syntax
In the section about literal values, we see that we have to write the subject’s name five times in a row. Luckily, we can avoid that by sharing predicates on subjects. This is also possible for sharing objects on predicates.
birds:Eurasian_blue_tit
birds:latinName “Cyanistes caeruleus” ;
birds:firstDescribed “1555”^^xsd:year ;
birds:avgWeight 11 ;
birds:name “Blåmeis”@no, “Blaumeise”@de, “Eurasian blue tit”@en .Several predicates concerning one subject are listed with semicolon (;), and several objects concerning one predicate is listed with comma (,). Descriptions of subjects are always ended with full stop (.).
Summary
In this article, we have introduced one syntax for RDF. RDF is the foundation of semantic technologies, which are better known as knowledge graphs.



