Skip to main content

class

Definition

If you come from a software background, you may be familiar with the idea of a class as defined in object-oriented programming. In some sense, we are making your data more object-oriented.

So, a class can be defined as a category of things. The best way to understand it is to go over some examples.

A class could be something like:

  • Customer
  • Country
  • Order
  • Movie

A class can be defined by a SQL table, column or SQL query. For instance, for a table customer(id, name, status), Veezoo will generate 2 classes (kb.Customer and kb.Status) and a relationship with_Status between them.

Usage

Let's see how classes are defined in VKL.

File: hitchhiker/knowledge-base/classes/Customer/class.vkl

import: [
db.postgres.movie_db.public.ORDERS
]

kb {
class Customer {
name.en: "Customer"
synonym.en: "Client"
extends: onto.Customer

sql: "${ORDERS.customer_id}"
name_sql.en:
"${ORDERS.customer_firstname} || ' ' || ${ORDERS.customer_lastname}"
}
}

Let's break it down in parts:

  • name: The name of the class in the specified language (en for English). This is the primary way to refer to this concept in a question and what gets displayed to the user in an answer.
  • synonym: Synonyms specify alternative ways to refer to this concept in a question. In our example, we can say "how many customers", but also "how many clients" and it will mean the same.
  • extends: By using this optional attribute, you can point your class to a pre-defined ontology class and inherit labels and other functionalities from it. Veezoo Studio already does this automatically to the best of its knowledge.

The glue between the knowledge-base layer and the database layer is in the sql. Check its reference page to learn more about it.

There are more properties you can add to a class in VKL. Check the next pages to learn more about them.