WeightedCategory

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.

Schema

# 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

Output

simplesimple_weightedfilefile_weighted
FOObarL
barFOOO
barHH
barFOOE
barHL

Arguments

NameTypeDescriptionDefault
choiceslistA list of choices to select from. They can be specified both with and without weights as per the schema above.[]
from_categorystringThe 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.

Field arguments

NameTypeDescriptionDefault Value
null_probabilityfloatThe probability that the field will be null.0.0
constraintslistA list of constraints to apply to the field.[]

Supported constraints

NameDescription
IfNullThe value must only be non-null if another field is null.