approx_match

Return the items which match the most rules.

Function Arguments

Name

Type

Description

rule

str, dict

The matched rule.

max_mismatch

int

(optional; default: 1) The number of mismatched rules at most.

Description

This function is like match function, but it returns the items that match the most rules when there’s no items that match all rules.

Examples

There are 5 rules, 5 items and max_mismatch = 1 in the following examples.

The number of matched rules are [0, 1, 2, 3, 4], this function returns the last item that matches 4 rules.

The number of matched rules are [0, 1, 4, 4, 4], this function returns the last 3 items that match 4 rules.

The number of matched rules are [0, 0, 0, 0, 0], this function returns an empty list because there’s no items that mismatch less equal than 1 rule.

Result

The result is a list which contains the items that match the most rules.

For each result, the schema is like:

{
  "perfect_match": a boolean indicating if the item matches all rules,
  "approx_match": {
    "matched_num": number of matched rules,
    "rule": {
      "rule_name": {
        "info": the rule string,
        "result": a boolean indicating if the item matches the rule
      },...
    }
  },
  "values": the probed results
}