Catalogs hold information about generic and specific entities. The entities may correspond to MENUITEMs or OPTIONs. The Catalog's YAML representation looks like
{
genericItems: GenericEntity[]
specificItems: SpecificEntity[]
}
The Catalog class provides methods for inspecting its contents:
- hasPID(pid: PID) - returns true if the catalog contains a
generic entitiywith the specifiedPID. - getGeneric(pid: PID) - returns the
generic enntitywith the specifiedPID. - hasKey(key: Key) - returns true if the catalog contains a
specific entitywith the specifiedKey. - getSpecific(key: Key) - returns the
specific entitywith the specifiedKey. - getTensorFromPID(pid: PID) - returns the id of the tensor associated with the
generic productwith the specifiedPID. - genericEntities() - iterator of all
generic entitiesin the catalog. - specificEntities() - iterator of all
specific entitiesin the catalog.
A generic product represents a class of related products that can be customized to specific products with the application of attributes. For example, an ice cream cone might be a generic product that could be specialized with SKU-specifying attributes like
- Size:
small,medium, andlarge - Type:
soft serve,hand packed - Flavor:
chocolate,strawberry, andvanilla
In the Catalog, a generic product is represented by the GenericEntity interface:
export interface GenericEntity extends Entity {
pid: PID;
cid: CID;
aliases: string[];
tensor: TID;
defaultKey: Key;
}
The GenericEntity fields are as follows:
pid: an integer product identifier that is unique across all generic products.cid: an integer category identifier. Allows us to implement mutual exclusivity of any options.aliases: an array of alias generator expressions for the phrases that represent this entity. Continuing the ice cream example, the aliases forice cream conemight include- ice cream
- ice cream cone
- cone
tensor: a tensor mapping attribute combinations to specific product keys. In the ince cream example, the tensor would have dimensions corresponding tosize,type, andflavor. Note that each generic product can have its own tensor. So, for example, a generic coffee product might specify a two dimensional tensor withsizeandcaffienedimensions.defaultKey: the key of the specific product when no attributes are specified. This key is used to provide default values of each unspecified attribute.
A specific product represents a specialization of a generic product. Unlike its generic cousin, the specific product has a SKU and can be purchased.
In the Catalog, a specific product is represented by the SpecificEntity interface:
export interface SpecificEntity extends Entity {
sku: SKU;
key: Key;
}
The SpecificEntity fields are as follows:
- sku: the entity's
stock keeping unitcode. Note thatprix-fixedoes not use theSKUas an index key forSpecificEntities. - key: a string representation of the product's coordinates in the tensor. The form is
P:X:Y:ZwherePis the products generic PID andX,Y,Zare its coordinates in its tensor space. Note that the key will have as many coordinate components as tensor dimensions. Some products aren't configured by attributes, and therefor are associated with a zero-dimensional tensor. Other products may have one, two, three, or more coordinate components.
Note that SpecificEntity does not specify aliases. These are provided by the GenericEntity.
The attributes.yaml file specifies Dimensions, AttributesYaml, and Tensors:
export interface AttributesYaml {
dimensions: DimensionDescription[];
tensors: TensorDescription[];
}
A Dimension is a set of related, but mutually exclusive attributes. In the examples, above, size, type, and flavor are all dimensions.
export interface DimensionDescription {
did: DID;
name: string;
attributes: AttributeDescription[];
}
The fields of DimensionDescription are as follows:
- did - an integer dimension identifier that is unique across all dimensions.
- name - a friendly name for the dimension. This name is not intended to be used by NLP algorithms to recognize dimensions, but it might be used to generate text to prompt the customer to provide a value for a dimension. For example, "what size cone would you like?".
- attributes: an array of
AttributeDescriptionthat make up the dimension. For example, asizedimension might have entries forsmall,medium, andlarge.
export interface AttributeDescription {
aid: AID;
name: string;
aliases: string[];
hidden?: boolean;
}
The AttributeDescription fields are as follows:
- aid: an integer attribute identifier that is unique across all attributes.
- name: a friendly name for the attribute. Note that the name is not intended to be used by NLP algorithms that recognize attributes.
- aliases: an array of alias generator expressions for the phrases that represent this attribute. In a coffee ordering scenario, the
mediumsize attirbute might specify the following aliases:- medium
- grande
- hidden - specifies whether this field should be displayed as part of the specific item's name. In many cases, the default attribute is not displayed. For example, coffee might have
icedandhotattributes, but thehotattribute would not be printed.
export interface TensorDescription {
tid: TID;
name: string;
dimensions: DID[];
}
The fields of the TensorDescription are as follows:
- tid: an integer tensor identifier that is unique across all tensors.
- name: a friendly name for the tensor, e.g.
sizes,flavors, etc. - dimensions: an array of identifers of the tensor's dimensions.
Options are product modifications that are added as children of a product.
As with products, options can be quantified, and generic options can be specialized with attributes.
Generic options are analogous to generic products.
A generic option represents a class of related options that can be customized to specific options with the application of attributes. For example, an chocolate syrup might be a generic product that could be specialized with SKU-specifying attributes like
- Quantity:
no,light,extra
In some cases an attribute might specify that the option is quantifed with a number, e.g. five pumps of chocolate syrup.
In the Catalog, a generic option is represented by the GenericEntity interface described earlier in the section on Generic Products.
A specific option represents a specialization of a generic option. Unlike its generic cousin, the specific option has a SKU and can be used to customize a specific product.
In the Catalog, a specific product is represented by the SpecificEntity interface.
Modifiers are Options that are mutually exclusive, within a set. For example, when ordering a latte, a customer might express a milk preference that could be one of non fat, two percent, whole milk, or soy milk.
Aliases are used to configure the NLP system to recognized products, options, and attributes.
The prix-fixe alias generator supports a few constructs to simplify the job of writing aliases:
- optional: a comma-separated list of phrases inside square brackets is treated an a choice of zero or one phrase from the list. So, the pattern
"chicago [combo,meal]"would match any of the following:- chicago
- chicago combo
- chicago meal
- choose exactly one: a comma-separated list of phrases inside parentheses is treated as a choice of exactly one phrase from the list. So the pattern,
"(iced,sweet) tea"would match- iced tea
- sweet tea
Note that you cannot nest either of these constructs.
The generateAliases() function generates all of the aliases associated with a specified pattern.
export const generateAliases: (pattern: string) => IterableIterator<string>;