garmentiq.utils.validate_garment_class_dict
1def validate_garment_class_dict(class_dict: dict) -> bool: 2 """ 3 Validates the structure and content of a garment class dictionary. 4 5 Ensures that the dictionary adheres to the expected format, including the presence 6 of required keys ("num_predefined_points", "index_range", "instruction") and 7 correct data types and logical consistency for their values. 8 9 Args: 10 class_dict (dict): The dictionary to be validated. 11 12 Returns: 13 bool: True if the dictionary is valid, False otherwise. 14 """ 15 required_keys = {"num_predefined_points", "index_range", "instruction"} 16 17 if not isinstance(class_dict, dict): 18 return False 19 20 for class_name, class_info in class_dict.items(): 21 if not isinstance(class_name, str): 22 return False 23 if not isinstance(class_info, dict): 24 return False 25 if not required_keys.issubset(class_info.keys()): 26 return False 27 28 num_points = class_info["num_predefined_points"] 29 index_range = class_info["index_range"] 30 instruction = class_info["instruction"] 31 32 # Check types 33 if not isinstance(num_points, int): 34 return False 35 if ( 36 not isinstance(index_range, tuple) 37 or len(index_range) != 2 38 or not all(isinstance(i, int) for i in index_range) 39 ): 40 return False 41 42 # Check logical consistency 43 if index_range[1] - index_range[0] != num_points: 44 return False 45 46 # Validate instruction field (must be a string ending with .json) 47 if not (isinstance(instruction, str) and instruction.endswith(".json")): 48 return False 49 50 return True
def
validate_garment_class_dict(class_dict: dict) -> bool:
2def validate_garment_class_dict(class_dict: dict) -> bool: 3 """ 4 Validates the structure and content of a garment class dictionary. 5 6 Ensures that the dictionary adheres to the expected format, including the presence 7 of required keys ("num_predefined_points", "index_range", "instruction") and 8 correct data types and logical consistency for their values. 9 10 Args: 11 class_dict (dict): The dictionary to be validated. 12 13 Returns: 14 bool: True if the dictionary is valid, False otherwise. 15 """ 16 required_keys = {"num_predefined_points", "index_range", "instruction"} 17 18 if not isinstance(class_dict, dict): 19 return False 20 21 for class_name, class_info in class_dict.items(): 22 if not isinstance(class_name, str): 23 return False 24 if not isinstance(class_info, dict): 25 return False 26 if not required_keys.issubset(class_info.keys()): 27 return False 28 29 num_points = class_info["num_predefined_points"] 30 index_range = class_info["index_range"] 31 instruction = class_info["instruction"] 32 33 # Check types 34 if not isinstance(num_points, int): 35 return False 36 if ( 37 not isinstance(index_range, tuple) 38 or len(index_range) != 2 39 or not all(isinstance(i, int) for i in index_range) 40 ): 41 return False 42 43 # Check logical consistency 44 if index_range[1] - index_range[0] != num_points: 45 return False 46 47 # Validate instruction field (must be a string ending with .json) 48 if not (isinstance(instruction, str) and instruction.endswith(".json")): 49 return False 50 51 return True
Validates the structure and content of a garment class dictionary.
Ensures that the dictionary adheres to the expected format, including the presence of required keys ("num_predefined_points", "index_range", "instruction") and correct data types and logical consistency for their values.
Arguments:
- class_dict (dict): The dictionary to be validated.
Returns:
bool: True if the dictionary is valid, False otherwise.