Introduction#
In this tutorial, you’ll build a small knowledge base about coffee drinks using the okb CLI. It goes one step at a time and ends with an ontology that passes every check.
An ontology is a shared, precise vocabulary for one subject. Say a café wants software that answers “what’s the difference between a cortado and a latte?” The software has to know that both are milk drinks, and that one has twice the milk. An ontology is where you write that down so a program can check it. The Learn page What is an ontology? explains the idea in a few minutes.
This tutorial is a sibling of the wine tutorial. It follows the same eight steps. It also covers things wine doesn’t: a class with two parents, a fact that sits on a link, and rules that come from a document.
Who it’s for#
Developers who are comfortable in a terminal. You don’t need to write code or know anything about ontologies. You don’t need to know coffee either.
What you’ll build#
A small ontology of espresso drinks: the drinks, what goes into them, and a short café menu.
Before you start#
Install okb and check that okb --help works. The Quickstart shows how.
Create the ontology#
Run the okb init command to make a folder named espresso and call the ontology “Espresso drinks”:
okb init espresso --name "Espresso drinks"
✓ Created ontology 'Espresso drinks' in espresso
Step 1 of 8: Determine the domain and scope
Goal: Write down what the ontology is about, what it's for, who will use and maintain it, and
which questions it must answer.
Why it matters: Scope is what lets you say 'no' to things later. Without it, every interesting
fact looks like it belongs, and the ontology never finishes.
Questions to answer
• What is the domain that the ontology will cover? (One sentence.)
• What are we going to use the ontology for? What app, search, report or decision will it
feed?
• What types of questions should it be able to answer? (These become competency questions.)
• Who will use it, and who will maintain it? Do they use the same words for things?
• What is related but deliberately out of scope?
You're done when
○ Domain and purpose are written down
○ Users (and ideally maintainers) are named
○ At least three competency questions
○ At least one thing is explicitly out of scope
Tips
• Competency questions are a sketch, not a contract. You'll add and change them.
• Don't try to list every question now. Write a few examples; each stands for a family of
similar questions, and you can fill in the rest of the family once a question is answered.
• Good questions are specific and answerable: 'Which wines go with grilled meat?' beats 'Tell
me about wine'.
• Include a few questions that need relationships (X goes with Y), not only lookups (what
color is X).
In Ontology 101's wine example
• Domain: wine and food
• Purpose: suggest good wine–food combinations
• Out of scope: winery inventory, restaurant staff
• Question: Is Bordeaux a red or white wine?
• Question: Does Cabernet Sauvignon go well with seafood?
• Question: What is the best choice of wine for grilled meat?
Commands
okb scope okb cq add
Next: cd espresso && okb scope --domain "..." --purpose "..." --users "..."
cd espresso
Read the output#
- okb made a folder with three files:
okb.json,nodes.jsonandedges.json. Every command from here on changes them. - Each command appears in a block you can copy. What okb printed appears in a separate block under it.
Common mistakes
- Running commands outside the folder. okb looks for
okb.jsonin the current folder, so runcd espressofirst.- Editing the files by hand. Use the commands. They check your work as you go.
Next step#
You made an empty ontology. Next, you’ll say what it’s for and which questions it must answer.