setRules
A rules-set can be specified via the setRules endpoint of the danube.ai cloud API. With a setRules
request you can save a rules-set on our side so you just have to provide its id on any of your following danube
prediction API requests. This needs to be done only once or when your rules have changed. Avoid repetitive requests.Request
Below, the setRules request's structure is shown.body: {
"query": String,
"variables": {
"id": String,
"override": Boolean,
"rules": [Rule]
}
}
The query parameter specifies which GraphQL endpoint to call (see example).The variables have the following meanings:
-
id: The id of your rules-set. You can have multiple rules-sets with different ids.
-
override: If true, an existing entry with the same id will be overridden.
-
rules: A list of Rules.
A Rule has the following structure:type Rule: {
"property": String,
"type": String,
"equalityScores": [EqualityScore],
"maxRuleValue": Float,
"minRuleValue": Float,
"clamping": Boolean
}
-
property: The name of the property this rules is used for.
-
type: The type of this rule. Possible types are:
-
"PERCENTAGE": This rule maps the values of the corresponding property from
[minRuleValue, maxRuleValue] to [0, 1].
- If no maxRuleValue is specified, the maximum of all values of this column will be used.
- If no minRuleValue is specified and clamping is false or not specified, 0 will be used.
- If no minRuleValue is specified and clamping is true, the minimum of all values of this column will be used.
-
"INVERSE_PERCENTAGE": This rule works like the "PERCENTAGE" rule, but inverted (i.e. mapping from
[minRuleValue, maxRuleValue] to [1, 0]).
-
"PERCENTAGE_SINE": Similar to the "PERCENTAGE" rule, this rule maps the values of the corresponding property from
[minRuleValue, maxRuleValue] to [0, 1]. Additionally, a sine function is used on the normalized values to make the mapping
non-linear.
-
"INVERSE_PERCENTAGE_SINE": This rule works like the "PERCENTAGE_SINE" rule, but inverted (i.e. mapping from
[minRuleValue, maxRuleValue] to [1, 0]).
-
"EQUALS": This 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.
-
"OVERLAP_LOCAL": This 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.
-
"OVERLAP_GLOBAL": This 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.
-
equalityScores: A list of Equality Scores (Only used by rules of type "EQUALS").
See below for the structure of an Equality Scores.
-
maxRuleValue: The upper bound of the source value range (Only used by rules of type "PERCENTAGE"
or "INVERSE_PERCENTAGE").
-
minRuleValue: The lower bound of the source value range (Only used by rules of type "PERCENTAGE"
or "INVERSE_PERCENTAGE").
-
clamping: Specifies whether clamping should be applied or not, if no minRuleValue is specified
(Only used by rules of type "PERCENTAGE" or "INVERSE_PERCENTAGE").
Formulas used by the "PERCENTAGE" rule:// Clamping:
clampedValue = max(min(value, maxRuleValue), minRuleValue)
// Normalizing:
normalizedValue = (clampedValue - minRuleValue) / (maxRuleValue - minRuleValue)
An Equality Score has the following structure:type EqualityScore: {
"value:": String,
"score:": Float
}
-
value: A possible value of the property.
-
score: The corresponding score for this value.
Response
The setRules endpoint either returns true if the rules-set was successfully saved or false if not.{
"data": {
"setRules": Boolean
}
}