The WeightedCategory field type allows you to specify a list of choices, and an optional weight for each choice.
You can specify categories in-line or externally in a CSV file, with the preference being that the CSV file is used.
# Load categories from CSV files.
categories:
- name: LETTERS
file: "data/LETTERS.csv"
- name: LETTERS_WEIGHTED
file: "data/LETTERS_WEIGHTED.csv"
fields:
# Simple choices, with equal probability.
- name: simple
type: WeightedCategory
null_probability: 0.5
args:
choices:
- "FOO"
- "bar"
# Simple choices, with weighted probability.
- name: simple_weighted
type: WeightedCategory
args:
choices:
- ["FOO", 1.0]
- ["bar", 0.5]
# Choices from a file, with equal probability.
- name: file
type: WeightedCategory
args:
from_category: LETTERS
# Choices from a file, with weighted probability.
- name: file_weighted
type: WeightedCategory
args:
from_category: LETTERS_WEIGHTED
# data/LETTERS.csv
LETTER
H
E
L
L
O
# data/LETTERS_WEIGHTED.csv
LETTER,WEIGHT
H,4
E,1
L,1
L,1
O,1
| simple | simple_weighted | file | file_weighted |
| FOO | bar | | L |
| bar | FOO | | O |
| bar | H | H |
| bar | FOO | | E |
| bar | H | L |
| Name | Type | Description | Default |
| choices | list | A list of choices to select from. They can be specified both with and without weights as per the schema above. | [] |
| from_category | string | The name of a category to use. This is a reference to a name defined in the categories section. See Categories for more information. | "" |
Note: choices and from_category are mutually exclusive.
| Name | Type | Description | Default Value |
| null_probability | float | The probability that the field will be null. | 0.0 |
| constraints | list | A list of constraints to apply to the field. | [] |
| Name | Description |
| IfNull | The value must only be non-null if another field is null. |