setRules

A rules-set can be specified via the setRules method provided by the DanubeClient class. setRules will save your rules-set on our side so you just have to provide its id on any following calls of the danube.ai predicition service. This needs to be done only once or when your rules have changed. Avoid repetitive calls.

Method

Below, the method's header is shown, as it is provided by DanubeClient.

/*
 * Saves a set of rules which can later be used under the specified id.
 *
 * @param id: The id of the new rule set (can be any string).
 * @param override: If set to trua and a set of rules already exists for this id, it will be overridden.
 * @param rules: An array of rules (see below for possible options).
 *
 * @returns true if the rules-set was successfully saved.
 */
public async setRules(
  id: string,
  override: boolean,
  rules: RULE[],
): Promise<boolean> {
  ...
}

Objects in the format of the following rules are valid:

/*
 * The "PERCENTAGE" rule maps the values of the corresponding property from [minRuleValue, maxRuleValue] to [0, 1].
 *
 * @field type: The rule's type.
 * @field minRuleValue (OPTIONAL): The lower bound of the source value range. Defaults to the lowest value of the property, if not specified and 'clamping' is true. Defaults to 0 otherwise.
 * @field maxRuleValue (OPTIONAL): The upper bound of the source value range. Defaults to the hightest value of the property, if not specified.
 * @field clamping (OPTIONAL): Specifies whether clamping should be applied or not, if no 'minRuleValue' is specified.
 * 
 * Formulas:
 * Clamping:
 *   clampedValue = max(min(value, maxRuleValue), minRuleValue)
 * Normalizing:
 *   normalizedValue = (clampedValue - minRuleValue) / (maxRuleValue - minRuleValue)
 */
interface PERCENTAGE_RULE extends RULE {
  type: 'PERCENTAGE';
  minRuleValue?: number;
  maxRuleValue?: number;
  clamping?: boolean;
}

/*
 * The "INVERSE_PERCENTAGE" rule works like the "PERCENTAGE" rule, but inverted (i.e. mapping from [minRuleValue, maxRuleValue] to [1, 0]).
 *
 * @field type: The rule's type.
 * @field minRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field maxRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field clamping (OPTIONAL): see "PERCENTAGE" rule.
 */
interface INVERSE_PERCENTAGE_RULE extends RULE {
  type: 'INVERSE_PERCENTAGE';
  minRuleValue?: number;
  maxRuleValue?: number;
  clamping?: boolean;
}

/*
 * The "PERCENTAGE_SINE" rule works like the "PERCENTAGE" rule, but additionally applies a sine function on the normalized values to make the
 * mapping non-linear.
 *
 * @field type: The rule's type.
 * @field minRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field maxRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field clamping (OPTIONAL): see "PERCENTAGE" rule.
 */
interface PERCENTAGE_SINE_RULE extends RULE {
  type: 'PERCENTAGE_SINE';
  minRuleValue?: number;
  maxRuleValue?: number;
  clamping?: boolean;
}

/*
 * The "INVERSE_PERCENTAGE_SINE" rule works like the "PERCENTAGE_SINE" rule, but inverted (i.e. mapping from [minRuleValue, maxRuleValue] to [1, 0]).
 *
 * @field type: The rule's type.
 * @field minRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field maxRuleValue (OPTIONAL): see "PERCENTAGE" rule.
 * @field clamping (OPTIONAL): see "PERCENTAGE" rule.
 */
interface INVERSE_PERCENTAGE_SINE_RULE extends RULE {
  type: 'INVERSE_PERCENTAGE_SINE';
  minRuleValue?: number;
  maxRuleValue?: number;
  clamping?: boolean;
}

/*
 * The "EQUALS" rule calculates the score-difference between a row's property's value and the property's value in the 'searchData' of a 'danubePrediction' call, based on the 'equalityScores' in the rule. A lower score-difference gets a higher ranking than a higher score-difference.
 * 
 * @field type: The rule's type.
 * @field equalityScores: An array of equality scores.
 */
interface EQUALS_RULE extends RULE {
  type: 'EQUALS';
  equalityScores: EQUALITY_SCORE[];
}

/*
 * An EQUALITY_SCORE maps a possible property value to a score.
 *
 * @field value: A possible value of the property.
 * @field score: The corresponding score for this value.
 */
interface EQUALITY_SCORE {
  value: string,
  score: number,
}

/*
 * The "OVERLAP_LOCAL" rule calculates the amount of overlap between the values of the property in the 'searchData' of a 'danubePrediction' call and
 * the values of a row's property.
 * 
 * @field type: The rule's type.
 */
interface OVERLAP_LOCAL_RULE extends RULE {
  type: 'OVERLAP_LOCAL';
}

/*
 * The "OVERLAP_GLOBAL" rule calculates the amount of overlap between the values of the property in the 'searchData' of a 'danubePrediction' call and
 * the values in a row's property. Additionally, the overlaps are normalized by the globally highest absolute overlap.
 * 
 * @field type: The rule's type.
 */
interface OVERLAP_GLOBAL_RULE extends RULE {
  type: 'OVERLAP_GLOBAL';
}