Knowledge Graphs at a Glance. Incorporate human knowledge into... | by Giuseppe Futia | Towards Data Science

Knowledge Graphs (KGs) have emerged as a core abstraction for incorporating human knowledge into intelligent systems. This knowledge is encoded in a graph-based structure whose nodes represent real-world entities, while edges define multiple relations between these entities. KGs are gaining attention from both the industry and academia because they provide a flexible way to capture, organize, and query a large amount of multi-relational data.
The goal of this post is to introduce the twofold perspective that characterizes a KG:
the graph-based perspective, which allows us to perform graph algorithms and inductive reasoning techniques on KGs;the semantic-based perspective, which provides a formal framework for the semantic interpretation of the data, which is essential to perform deductive reasoning.
the graph-based perspective, which allows us to perform graph algorithms and inductive reasoning techniques on KGs;
the semantic-based perspective, which provides a formal framework for the semantic interpretation of the data, which is essential to perform deductive reasoning.
Then, the post will focus on techniques and languages that are related to the semantic perspective and that enable deductive learning. The graph perspective, which enables inductive techniques, will be discussed in some posts of the series dedicated to Graph Representation Learning: https://towardsdatascience.com/tagged/grl-series.
Formally, a KG can be defined as G={E, R, T}, where G is a labeled and directed multi-graph, and E, R, T are the set of nodes, edges, and triples respectively.
Each triple is formalized as (u, e, v) ∊ T, where u ∊ E is the head node, v ∊ E is the tail node, and e ∊ R is the edge connecting u and v. In the semantic regime, a triple is formalized as a fact in which (u, e, v) corresponds to (s, r, o), where s and o are two entities, the subject and the object of the fact respectively, while r is the relation that connects s and o.
To clarify this aspect, please consider the following example statement: “Socrates influenced Plato.” From the graph perspective, the triple includes “Socrates” and “Plato” as two nodes of the graph, while “influenced” is an edge between these two nodes. From the semantic perspective, the simple statement includes “Socrates” and “Plato” as two entities, while “influenced” is the relation between these two entities. Entities and relations can also be defined as terms of the statement.
The Resource Description Framework (RDF) is a core technology of the Semantic Web (SW) for implementing the twofold representation of KGs. The purpose of SW is to realize a Web-scale data infrastructure readable and understandable by machines. To accomplish this vision, which is only partially implemented, Web technologies such as Uniform Resource Identifiers (URIs) and the HyperText Transfer Protocol (HTTP) protocol are adopted.
RDF reflects a simple graph-based data model, exploiting Web technologies, and provides a formal notion of meaning (semantics) that set up the basis for founded deductions. An RDF graph can be serialized in different formats, including N-Triples, N3, Turtle, JSON, and XML. The example “Socrates influenced Plato” can be translated into RDF and serialized in N-Triples as follows:
<http://dbpedia.org/resource/Socrates><http://dbpedia.org/ontology/influenced><http://dbpedia.org/resource/Plato> .
Other types of serialization, such as Turtle, enable a more compact declaration of RDF facts employing the so-called prefixes. The example can be rewritten as follows:
@prefix dbo: <http://dbpedia.org/ontology/> .@prefix dbr: <http://dbpedia.org/resource/> .dbr:Socrates dbo:influenced dbr:Plato .
From the SW point of view, the terms dbr:Socrates, dbo:influenced, and dbr:Plato are also known as resources, and a relation between two different resources — in this case dbo:influenced — is also known as predicate or property. This example directly comes from an existing open KG known as DBpedia, whose goal is to provide the information included in the Wikipedia infoboxes in the form of a collection of RDF triples. This collection can also be denoted as RDF graph.
The running example shows that URIs can be adopted as unique ids for both entities s and o and the relation r. RDF allows us to represent relations between entities, but also specific information related to a single entity. In the RDF statement
dbr:Socrates dbo:birthDate -469-0-0^^xsd:date .
the object is not an entity but a literal value, with a specific data type defined using the XML Schema Datatypes (XSD). From a graph perspective, a literal value is considered a leaf node of the KG. Starting from the RDF representation, quantified statements are added to denote the semantics of entities and relations.
RDF Schema (RDFS) and OWL (Web Ontology Language) are two different language models that enable the construction of quantified statements in the form of RDF graphs. RDFS is one of the most prominent standards for defining a semantic schema for RDF graphs. OWL is the most popular ontology language used in practical cases, incorporating and extending RDFs. RDFS and OWL specify large vocabularies to denote peculiar conditions for using RDF nodes and edges, introducing coherency and specific datatypes to support logic reasoning. Moreover, they indicate how terms are interrelated and impose a structure to define the semantic interpretation’s constraints.
RDFS provides mechanisms to define classes for aggregating entities with similar features. In order to define classes, RDFS provides two different terms:
the rdf:type property defines the “type” of a subject node; the object of this property must be a class. In RDF, rdf:type can be also replaced with a;
the rdfs:Class is used to aggregate similar entities.
In the running example, the following statements can be defined to extend the information related to Socrates:
ex:Human rdf:type rdfs:Class .dbr:Socrates rdf:type ex:Human .
RDFS allows also to define class hierarchies with the rdfs:subClassOf property. Therefore, the collection of facts can be expanded as follows:
ex:Human rdf:type rdfs:Class .dbr:Socrates rdf:type ex:Human .ex:Mortal rdf:type rdfs:Class .ex:Human rdfs:subClassOf ex:Mortal .
RDFS also defines specific terms to extend the semantics of properties. These terms include:
rdf:Property → It is the rdf:type of any terms used as a predicate;
rdfs:domain and rdfs:range →They define the domain and the range of the property. Domain and range are categorized as rdfs:Class;
rdfs:subPropertyOf →It specifies hierarchies of properties.
Therefore, the information related to the dbo:influenced property can be expressed as follows:
dbo:influenced rdf:type rdf:Property ;    rdfs:range ex:Human ;    rdfs:domain ex:Human .
OWL is a language model for describing ontologies. OWL documents, known as ontologies, incorporate the terms defined by RDFS and add further structures to address its limits. For instance, OWL makes explicit the relations of identity or unlikeness between different entities. It supports more expressive class definitions, including union, complement, disjointness, specifying cardinality restrictions. Moreover, it includes more expressive property definitions, enabling the distinction between object and datatype properties. OWL also allows us to define transitive, functional, symmetric, and inverse properties, indicating value restrictions. The statements which describe the relation between classes and properties are also known as axioms. These statements are categorized as true in the reference domain and are fundamental to enable deductive reasoning.
The running example can be extended with OWL as follows:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .@prefix owl: <http://www.w3.org/2002/07/owl#> .@prefix ex: <http://example.com/> .@prefix dbr: <http://dbpedia.org/resource/> .@prefix dbo: <http://dbpedia.org/ontology/> .@prefic wkd: <https://www.wikidata.org/wiki/> .# RDFdbr:Socrates dbo:influenced dbr:Plato ;    dbo:birthDate -469-0-0^^xsd:date .# RDFSdbr:Socrates rdf:type ex:Human . ex:Human rdf:type rdfs:Class ;    rdfs:subClassOf ex:Mortal .dbo:influenced rdf:type rdf:Property ;    rdfs:range ex:Human ;    rdfs:domain ex:Human .# OWL dbr:Socrates owl:sameAs wkd:Q913 .dbo:influenced rdf:type owl:ObjectProperty .dbo:birthDate rdf:type owl:DatatypeProperty .rdfs:subClassOf rdf:type owl:TransitiveProperty .
This example establishes quantified statements such as “All humans are mortal.” Consequently, it also allows us to infer a new fact through deductive reasoning: “Socrates is mortal” derived from the fact that ex:Human is a subclass of ex:Mortal. In the same example, OWL statements allow us to declare that dbo:influenced and dbo:birthDate are two different types of properties, an object property and a data property respectively. Moreover, using OWL it is possible to define the axiom according to which rdfs:subClassOf is a transitive property.
A practical language known as SPARQL (SPARQL Protocol and RDF Query Language) has been developed in the SW context to perform queries on KGs. This structured query language’s core is based on the graph pattern, which follows the same RDF graph model. In addition, SPARQL introduces the use of variables as valid terms. Therefore, graph patterns are divided into constants, represented by resources such dbr:Socrates, and variables such as ?philosopher, which are identified using question marks. During the querying process, the graph pattern is evaluated against the RDF graph. This process generates a mapping between the graph patterns’ variables and the resources in the RDF graph. These variables are then replaced with the RDF resources that satisfy the graph patterns included in the query. Here is available an example of SPARQL query:
@prefix dbr: <http://dbpedia.org/resource/> .@prefix dbo: <http://dbpedia.org/ontology/> .SELECT ?philosopherWHERE {    dbr:Socrates dbo:influenced ?philosopher .
Considering our running example, the ?philosopher variable is replaced with the resource dbr:Plato.
In the following article, I describe the conceptual approach for building KGs from structured sources, mapping the local schema of such sources to the global schema defined by a domain ontology.
towardsdatascience.com
If you like my articles, you can support me using this link https://medium.com/@giuseppefutia/membership and becoming a Medium member.