A few elementary pieces on logic
...the pieces you need to know to start building an ontology for a knowledge graph
“In mathematics you don’t understand things. You just get used to them.”
— John von Neumann
I guess this is true for most things. Not only mathematics. Well, then again, mathematics are usually found in the foundation of basically everything tho. It’s definitely true for most data practitioners that I’ve met along my career. That you just do stuff, code stuff, model stuff, from habit/what you copy-pasted/what you saw in that YouTube-video, and not from understanding. It seems to me that something got lost along the way. Or has universities just stopped bothering about foundations? I don’t know. Anyways, enough with the rant. Here I am, giving you some foundations for understanding knowledge graphs through logic and mathematical logic. I hope you enjoy this topic as much as I do. 🥰
Communication
How do I ensure that my meant intention is the same thing as you interpret? A shared ontology strive to be the key to a unified understanding. An ontology provides formal terms, definitions and context for the concepts of our world. Let us break it down.
The Concept: not necessarily a physical thing. More the idea of a thing.
The Term: the word we use for a concept.
The Definition: what limits the interpretation of the term, and reduce (hopefully eliminates) ambiguity.
The Context: how does the concept relate to other concepts?
Concepts
A concept is a mental representation, or even a sense, of a thing and serves all aspects of cognition. Concepts materialise when we give them terms and definitions.
Terms
A concept holds some intended meaning, while the term is the word we give this concept. Example of (unrelated) terms: triangle, democracy, acid.
Changes in terms
Quite often will new terms originate from old ones. Within (computer) science, it happens that people (perhaps in good faith, or to appear original), bombards with new and deafening terminology that indicates new and sensational ideas. [1]
Examples (🔥):
Data Science -> Data Analysis & Modeling
Data Products -> Owned datasets
Workflow Orchestration -> Job scheduling
Agile Transformation -> Iterative delivery
Data Fabric -> Unified data access layer
Data Mesh -> Decentralised data ownership
Knowledge Graphs -> Semantic Technologies -> The Semantic Web
Good definitions
The possibility of substitution. The trial of substitution will disclose a definition from factual statements (which are better served as axioms, back to that later) that pretends to be definitions.
The length. A definition shall be short and precise.
Avoid doubtful clauses. “Where is my cent?” “Under the book”. “Where is the book?” “On top of the cent”. [1]
The purpose of the definition is to give a limitation of possible interpretation, or to give an interpretation if there is none.
Neutral and objective.
Example of good definitions:
A triangle is a polygon with exactly three sides.
Democracy is a system of government in which political power is held by the people, either directly or through elected representatives.
An acid is a substance that donates protons (H⁺ ions) in an aqueous solution.
Set theory
A concept’s scope, is a group of phenomenons or things. This group of things, have one thing in common, and that is they fit within the definition of the concept. Such a group is called a class. A class can also be seen as a set, depending on your perspective.
A class (or set) can hold several sub-classes (or sub-sets), and the sub-classes may also hold sub-classes. Whatever is most reasonable for the concepts in question. All classes might also hold individuals, or elements, depending on your perspective.
Operator symbols cheat sheet
⊤ : Everything
⊥ : Nothing
A ⊆ B : A subset of B
A ∩ B : the intersection of A and B, what they hold in common
A ∪ B : the union of A and B, everything in both A and B
a ∈ B : element a is in the set B
b ∉ B : element b is not in the set B
∅ : the empty set
Identifying the difference between a class and an individual
Usually I follow this simple thumb-rule:
This is sufficient for most cases. By “most things”, I mean can this thing hold sub-classes (sub sets). Let me give you one example.
Sets and sub-sets
A set is a finite, or infinite, collection of elements, where the order of the elements does not matter [2]. A class is the scope of a concept, where all elements in the class have the 1) same characteristics 2) is alone in this particular set of characteristics, and 3) contains all the phenomena that can exhibit this particular combination of characteristics [1].
In other words; a class (or set) represent an abstract description of a group of elements, and what they have in common. Sometimes there is a need to represent sub-classes (sub-sets) too. From the illustration above, we can easily imagine the class of Planet to contain the two sub-classes; Gas Planet and Terrestrial Planet.
We have two main classes in this example; Astronomical Body and Astronomical Object. We see that there are a slight overlap between the two which is Comet, as the tail is an object and the body a ...body!
The individuals (or elements) in such a class (or set) are the actual things. That concrete stuff that exists. Like Mars and Proxima Centauri are elements of the set of Planets, and likewise Ceres and Pluto individuals of the class Dwarf Planet.
I am mixing terminology here on purpose, btw!
Transferring this knowledge to knowledge graphs, the classes and its definition are found in the ontology, and the individuals are typically your data (graph)1.
Relationships!
Relationships, folks! That’s the gold in a knowledge graph. Treat them well. It provides your concepts with context.
Now there are a couple of lines that has popped up! A relationship named moon going from Planet and Dwarf Planet to the class of Natural Satellites.
Let’s gather our current information:
Classes: Planet, Dwarf Planet, Natural Satellite
Disjoint classes: Planet ⋂ Dwarf Planet ⋂ Natural Satellite
{Ceres, Pluto} ∈ Dwarf Planet
{Mars, Proxima Centauri} ∈ Planet
moon⟨{Planet, Dwarf Planet}, Natural Satellite⟩
Woopsie. If we were to model this data into a knowledge graph and run a reasoner on it, we would have triggered a logical contradiction (untrue for all values). There are some things in this model that does not make sense!
What we say is that this moon relationship is a relationship between Planet and Dwarf Planet to Natural Satellite, meaning that those two classes have this particular relationship in common. However, we also say that Planet and Dwarf Planet are disjoint. And the thing in common between disjoint classes is ..., the empty set!
Dont’t worry. This is possible to fix. With a more sophisticated class hierarchy, and setting the relationships at the correct level in the hierarchy.
Introducing Planetary Body as a superclass for Planet and Dwarf Planet! Now it is possible to state that Mars has a moon Phobos, and Pluto has a moon Styx at the same time.
Summary
This article has introduced a few rules for defining concepts with their terms and definitions. It has shown how terms changes in time.
We have seen how we can think about concepts in terms of sets and classes, with their elements and relationships that provide context to concepts.
Literature
[1] Peter Wessel Zapffe, Den logiske sandkasse—Elementær logikk for universitet og selvstudium. Universitetsforlaget, 1966.
[2] Roger Antonsen, Logiske metoder—Kunsten å tenke abstrakt og matematisk. Universitetsforlaget, 2014.
and Kari Opdahl, Logikk—En enkel innføring. Tapir, 1981.
Several ontologies contains individuals too, of course. They are quite handy for e.g. enumerations.








This is helpful for new people. One thing I’d note, you introduce set operators (⋂ and ∈) without telling the reader how they function. So it might not be obvious how to read that section for people who haven’t done set theory.
Perfect bedtime reading — I was hoping for Gandalf 😂
Great read and explainer. I love the journey. I like to say a concept can wear a backpack but framing that imagery WITH set theory—what do you think?