in src/dfcx_scrapi/builders/intents.py [0:0]
def parameter_checking(self, raise_error: bool = False) -> bool:
"""Check if the annotated parameters exist
in the Parameter attribute of proto_obj.
Args:
raise_error (bool):
A flag to whether raise an error. If False, it will log a warning.
Returns:
True if annotated parameters are the same as parameters in proto_obj
"""
self._check_proto_obj_attr_exist()
tp_params_set = set()
for tp in self.proto_obj.training_phrases:
for part in tp.parts:
tp_params_set.add(part.parameter_id)
# Remove the empty string for unannotated parts
try:
tp_params_set.remove("")
except KeyError:
pass
# Get the parameters from proto_obj
parameters_set = {param.id for param in self.proto_obj.parameters}
# Check for not existing annotated parameters
return_flag = True
for tp_param in tp_params_set:
if tp_param not in parameters_set:
return_flag = False
msg = (
f"parameter_id `{tp_param}` does not exist in parameters."
"\nPlease add it using add_parameter method to continue."
)
if raise_error:
raise UserWarning(msg)
else:
logging.warning(msg)
return bool(return_flag)