code: def parse_ruleset(r: Union[List[dict], Path, str]) -> List[Rule]:
      if isinstance(r, str):
          if r.endswith(".json"):
              r = Path(r)
          else:
              if r == "*":
                  # Support for * to mean all
                  return sum(
                      [
                          parse_ruleset(ruleset)
                          for ruleset in default_rulesets.keys()
                      ],
                      [],
                  )
              if r not in default_rulesets:
                  raise KeyError(
                      f"Ruleset {r} is not in the defaults {list(default_rulesets.keys())}. "
                      f"Alternatively, specify a path to a `ruleset.json`."
                  )
              r = default_rulesets[r]
      if isinstance(r, Path):
          with open(r.as_posix()) as f:
              r = json.load(f)
  
      return [Rule.from_dict(d) for d in r]
  
imports: import json
  import logging
  import re
  from dataclasses import dataclass, field
  from pathlib import Path
  from typing import List, Type, Optional, Dict, Tuple, Union, Callable
  from dataclasses_json import dataclass_json
  from paiargparse import pai_dataclass, pai_meta
  from tfaip.data.pipeline.processor.dataprocessor import DataProcessorParams
  from tfaip.util.enum import StrEnum
  from calamari_ocr import calamari_ocr_dir
  from calamari_ocr.ocr.dataset.textprocessors import TextProcessor
label_desc: Use image node_id 2 for calling a global function with example usage: parse_ruleset(r) and returns: unknown, sum