Skip to content

Step 5: Slots

9 min · step 5 of 8

Introduction#

Describe what you can say about each class: its color, its maker, the foods it pairs with.

A class with no description is just a name. Slots are how an ontology holds facts. They also keep the model tidy, because you attach each slot to one class and every class below it gets it for free (inheritance). You can read the full guide to this step in Method.

What you’ll make#

11 slots. Some hold a value, like color or body. Others link to another thing, like maker. You’ll attach each slot to the most general class that can use it.

Run the commands#

A slot comes in two kinds. A property holds a value, such as light or Napa Valley. A relationship links to another thing, such as a winery. okb stores a relationship as an edge in the graph.

Start with the properties every wine has. The --values list is the allowed set, and --card single sets the cardinality, which is how many values the slot can hold. Here it’s one at most:

okb property add color --on Wine --type Enumerated --values red,white,rose --card single --desc "The wine's color."
okb property add body --on Wine --type Enumerated --values light,medium,full --card single --desc "How heavy the wine feels in the mouth."
okb property add flavor --on Wine --type Enumerated --values delicate,moderate,strong --card single --desc "Intensity of the wine's flavor."
okb property add sugar --on Wine --type Enumerated --values dry,offDry,sweet --card single --desc "Residual sweetness."
Added property color on Wine (Enumerated).

Added property body on Wine (Enumerated).

Added property flavor on Wine (Enumerated).

Added property sugar on Wine (Enumerated).

Tannin comes from grape skins, so only red wines have it. Attach it to RedWine, not Wine:

okb property add tanninLevel --on RedWine --type Enumerated --values low,moderate,high --card single --desc "Astringency from grape skins; only meaningful for red wines."
Added property tanninLevel on RedWine (Enumerated).

Now add the links between things. --min 1 means a wine must have at least one maker:

okb relationship add maker --from Wine --to Winery --card single --min 1 --desc "The winery that produced the wine."
okb relationship add produces --from Winery --to Wine --card multiple --desc "Wines the winery makes."
okb relationship add grape --from Wine --to WineGrape --card multiple --min 1 --desc "Grape varieties the wine is made from."
okb relationship add region --from Wine --to WineRegion --card single --desc "Where the wine comes from."
okb property add location --on Winery --type String --card single --desc "Where the winery is."
okb relationship add goesWellWith --from Wine --to Food --card multiple --desc "Foods this wine pairs well with."
Added relationship maker: (Wine)-[:MAKER]->(Winery).

Added relationship produces: (Winery)-[:PRODUCES]->(Wine).

Added relationship grape: (Wine)-[:GRAPE]->(WineGrape).

Added relationship region: (Wine)-[:REGION]->(WineRegion).

Added property location on Winery (String).

Added relationship goesWellWith: (Wine)-[:GOES_WELL_WITH]->(Food).

Then look at what RedWine ended up with:

okb show RedWine
RedWine  Class · c.red-wine
  Wine made from dark-skinned grapes with skin contact; described by tannin level.
  parents        Wine
  subclasses     Bordeaux, Beaujolais, Merlot, Port
  disjoint with  WhiteWine, RoseWine

  Slots  (properties hold values; relationships → link to other things)
    tanninLevel        Enumerated, {low, moderate, high}, single
    color              Enumerated, {red, white, rose}, single (from Wine)
    body               Enumerated, {light, medium, full}, single (from Wine)
    flavor             Enumerated, {delicate, moderate, strong}, single (from Wine)
    sugar              Enumerated, {dry, offDry, sweet}, single (from Wine)
    maker              Instance, → Winery (:MAKER), single, min 1 (from Wine)
    grape              Instance, → WineGrape (:GRAPE), multiple, min 1 (from Wine)
    region             Instance, → WineRegion (:REGION), single (from Wine)
    goesWellWith       Instance, → Food (:GOES_WELL_WITH), multiple (from Wine)

Read the output#

  • Inheritance. RedWine lists color, body, flavor and sugar “from Wine”. You added them once, and every class below RedWine inherits them too.
  • Tannin stays on RedWine. Only red wines show tanninLevel. A white wine can’t be given one by mistake.
  • Properties versus relationships. maker shows → Winery (:MAKER). The :MAKER is the name of the edge okb will store. body has no arrow, because it holds a plain value.
  • Two slots for one fact. maker and produces are the same fact seen from each side. Step 6 joins them.

Check your work#

okb status
Wine and Food  · 21 classes · 11 slots · 0 instances · 6 questions

✓ 1. Determine the domain and scope
✓ 2. Consider reusing existing ontologies
✓ 3. Enumerate important terms
✓ 4. Define the classes and the class hierarchy
✓ 5. Define the properties of classes (slots) ◀ you are here
     ✓ At least one slot
     ✓ Every slot is attached to at least one class
✓ 6. Define the facets of the slots
○ 7. Create instances
○ 8. Review against your questions, and iterate

Validator (steps 1–5): ✗ 0  ! 0  i 2   okb validate for details

Step 5 looks done. When you're happy with it: okb step next

When step 5 has a tick, move on:

okb step next
Now on step 6. (To read a step's guide without moving: okb explain 6)

Step 6 of 8: Define the facets of the slots

  Goal: For every slot, decide its value type, allowed values or range, cardinality, and any
  defaults, fixed values or inverse.
  Why it matters: Facets turn a list of fields into rules a machine can check. This is where
  most data-quality errors get caught later.

Questions to answer
  • Is the value text, a number, yes/no, one of a fixed list, or another thing (Instance)?
  • If it's a fixed list, what are all the allowed values?
  • If it's another thing, what is the most general class of things it can be (the range)? Not
  too general, not too narrow.
  • One value or many? Is it required (minimum 1)?
  • Is there a value most instances share (default), or one every instance of a class must have
  (fixed value)?
  • Is this relationship the reverse of another slot (maker ↔ produces)?
  • Does each link need extra information of its own, like a condition or a strength? (Edge
  properties; see decision.edge-or-class.)

You're done when
  ○ Every slot has a value type and cardinality
  ○ The slots have no known mistakes

Tips
  • When in doubt about range, pick the most general class that still only contains valid
  fillers.
  • Defaults are suggestions; fixed values are facts. Don't confuse them.

In Ontology 101's wine example
  • body: one of light, medium or full, and only one value
  • produces (on Winery): points to Wine, can have many values, and is the inverse of maker
  • grape: at least one value
  • Dessert Wine: sugar is fixed at sweet

Decision guides for this step  (okb explain <id>)
  decision.range               What should this slot's range be?
  decision.edge-or-class       Edge property, or make the relationship its own class?

Commands
  okb slot set   okb relationship inverse   okb relationship property   okb class fix   okb class default   okb class restrict

Common mistakes

  • Attaching a slot too high. If tanninLevel were on Wine, every white wine would be asked for one.
  • Attaching a slot too low. If color were on each of the four color classes, you’d repeat yourself and drift apart later.
  • Using a property for a thing. If the value is something with its own details, like a winery, make it a relationship.

Next step#

You added 11 slots: properties that hold values, and relationships that link one thing to another. Next, you’ll add limits and shortcuts, such as fixed values and inverses.

View page source