Skip to content

Tutorial: Wine ontology

about 1 hr 10 min in total · 8 steps

Introduction#

In this tutorial, you’ll build a small knowledge base about wine and food using the okb CLI. You’ll do it one step at a time, and end with an ontology that passes every check.

You don’t need to know what an ontology is yet. It’s a shared, precise vocabulary for one subject. Say you run a restaurant and want software to suggest a wine for each dish. The software has to know that Bordeaux is a red wine, and that red wine goes well with grilled meat. 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.

The example comes from the paper Ontology Development 101 by Noy and McGuinness (PDF), which this tutorial calls Ontology 101. It follows the paper’s eight steps, and each step has its own page. The full method is in Method.

Who it’s for#

This tutorial is for developers, but you don’t need to write code. You only need to be comfortable working in a terminal: running commands, changing folders and reading what they print.

You don’t need any background in ontologies, knowledge graphs or the wine trade. Each new idea is explained when it first appears.

What you’ll build#

A folder called wine with three files in it: okb.json, nodes.json and edges.json. By the last page it holds 21 classes (kinds of thing, such as Wine), 11 slots (facts you can state about a class, such as color), 9 instances (real things, such as one winery) and 6 competency questions (questions the ontology should answer), and okb validate --all reports no errors.

Before you start#

Install okb by following Installation, then open a terminal.

Create the ontology#

First, create the ontology. Run the init command to make a folder named wine, and use the --name argument to call the ontology “Wine and Food”:

okb init wine --name "Wine and Food"
✓ Created ontology 'Wine and Food' in wine

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 wine && okb scope --domain "..." --purpose "..." --users "..."

Each command appears in a block you can copy. The output okb prints appears in a separate block under it, so you can copy the commands without it.

Then move into the new folder. Run every other command in this tutorial from inside wine:

cd wine

Read the output#

init printed the guide for step 1. It says what you’ll do, why it matters and when you’re done. Print the guide again at any time with okb step, and run okb status whenever you want to know where you are.

Common mistakes

  • Running commands outside the wine folder. okb looks for okb.json in the current folder and its parents. If it can’t find one, it says so and tells you how to create it.
  • Skipping ahead. Each step builds on the one before. okb only shows hints that matter for your current step, so you won’t see everything at once.

Next step#

You created an empty ontology named “Wine and Food”. Next, you’ll write down what it’s for and the questions it must answer.

View page source