quantity_of
Definition
Setting the property quantity_of
on a numeric attribute or measure to a class will make the count of that class resolve to the sum of the numeric attribute respectively the measure.
Databases sometimes contain QUANTITY
columns, which store a count of objects that correspond to another column, for example the number of products ordered.
We then usually want to be able to ask about the number of products and get the sum of the quantity instead when appropriate.
Note that there is often also a PRODUCT
column, however we want e.g. "number of products ordered this year" to resolve to "sum of quantity" instead of "distinct count of products".
Usage
Configuring quantity_of
is straightforward, the value is just set to the class that should resolve to the quantity when counted.
There is an important restriction: the class needs to be directly connected to the outer class of the quantity attribute (and may not be the outer class itself).
The typical example is found in sales datasets about orders: in these, orders consist of multiple order lines, each representing a quantity of a product in the order. Note that the quantity in this example counts the individual physical products that will be shipped to the customer, e.g. the quantity counts five sunglasses; this is not the same as the product found in the database, which consists of types of these physical product, e.g. the sunglasses product. (For the more theoretically inclined, this distinction is known as type-token distinction in the literature)
kb {
class Order {
/* ... */
}
class OrderLine {
/* ... */
relationship Order {
to: kb.Order
}
relationship Product {
to: kb.Product
}
integer Quantity {
name.en: "Quantity"
// Indicates that "number of product" will be understood as "sum of quantity",
// when appropriate according to the question
// Important: the class kb.Product needs to have a direct relationship
// to the outer class, i.e. kb.OrderLine
quantity_of: kb.Product
}
}
class Product {
/* ... */
}
}
Behavior
Generally speaking, Veezoo will understand the count of products in questions as sum of quantity when the product is connected to an order, for example "How many products were ordered last week?". Questions that don't contain a count or that are clearly about counting distinct products won't be affected, e.g. "Number of products with more than 10 orders".