Esempio n. 1
0
def is_categorical_feature(feature: schema_pb2.Feature):
    """Checks if the input feature is categorical."""
    if feature.type == schema_pb2.BYTES:
        return True
    elif feature.type == schema_pb2.INT:
        return ((feature.HasField('int_domain')
                 and feature.int_domain.is_categorical)
                or feature.WhichOneof('domain_info')
                in ['bool_domain', 'natural_language_domain'])
    else:
        return False
Esempio n. 2
0
def _copy_domain_info(origin: schema_pb2.Feature, dest: schema_pb2.Feature):
    """Copy the domain info."""
    one_of_field_name = origin.WhichOneof("domain_info")
    if one_of_field_name is None:
        return

    origin_field = getattr(origin, one_of_field_name)

    field_descriptor = origin.DESCRIPTOR.fields_by_name.get(one_of_field_name)
    if field_descriptor is None or field_descriptor.message_type is None:
        setattr(dest, one_of_field_name, origin_field)
    else:
        dest_field = getattr(dest, one_of_field_name)
        dest_field.CopyFrom(origin_field)