|
| 1 | +# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""The Feature Definitions for FeatureStore.""" |
| 14 | +from __future__ import absolute_import |
| 15 | + |
| 16 | +from enum import Enum |
| 17 | +from typing import Dict, Any |
| 18 | + |
| 19 | +import attr |
| 20 | + |
| 21 | +from sagemaker.feature_store.inputs import Config |
| 22 | + |
| 23 | + |
| 24 | +class FeatureTypeEnum(Enum): |
| 25 | + """Enum of feature types.""" |
| 26 | + |
| 27 | + FRACTIONAL = "Fractional" |
| 28 | + INTEGRAL = "Integral" |
| 29 | + STRING = "String" |
| 30 | + |
| 31 | + |
| 32 | +@attr.s |
| 33 | +class FeatureDefinition(Config): |
| 34 | + """Feature definition. |
| 35 | +
|
| 36 | + Attributes: |
| 37 | + feature_name (str): The name of the feature |
| 38 | + feature_type (FeatureTypeEnum): The type of the feature |
| 39 | + """ |
| 40 | + |
| 41 | + feature_name: str = attr.ib() |
| 42 | + feature_type: FeatureTypeEnum = attr.ib() |
| 43 | + |
| 44 | + def to_dict(self) -> Dict[str, Any]: |
| 45 | + """Constructs a dictionary based on the attributes""" |
| 46 | + return Config.construct_dict( |
| 47 | + FeatureName=self.feature_name, FeatureType=self.feature_type.value |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +class FractionalFeatureDefinition(FeatureDefinition): |
| 52 | + """Fractional feature definition. |
| 53 | +
|
| 54 | + Attributes: |
| 55 | + feature_name (str): The name of the feature |
| 56 | + feature_type (FeatureTypeEnum): A `FeatureTypeEnum.FRACTIONAL` type |
| 57 | + """ |
| 58 | + |
| 59 | + def __init__(self, feature_name: str): |
| 60 | + """Constructs an instance of FractionalFeatureDefinition. |
| 61 | +
|
| 62 | + Args: |
| 63 | + feature_name (str): the name of the feature. |
| 64 | + """ |
| 65 | + super(FractionalFeatureDefinition, self).__init__(feature_name, FeatureTypeEnum.FRACTIONAL) |
| 66 | + |
| 67 | + |
| 68 | +class IntegralFeatureDefinition(FeatureDefinition): |
| 69 | + """Fractional feature definition. |
| 70 | +
|
| 71 | + Attributes: |
| 72 | + feature_name (str): the name of the feature. |
| 73 | + feature_type (FeatureTypeEnum): a `FeatureTypeEnum.INTEGRAL` type. |
| 74 | + """ |
| 75 | + |
| 76 | + def __init__(self, feature_name: str): |
| 77 | + """Constructs an instance of IntegralFeatureDefinition. |
| 78 | +
|
| 79 | + Args: |
| 80 | + feature_name (str): the name of the feature. |
| 81 | + """ |
| 82 | + super(IntegralFeatureDefinition, self).__init__(feature_name, FeatureTypeEnum.INTEGRAL) |
| 83 | + |
| 84 | + |
| 85 | +class StringFeatureDefinition(FeatureDefinition): |
| 86 | + """Fractional feature definition. |
| 87 | +
|
| 88 | + Attributes: |
| 89 | + feature_name (str): the name of the feature. |
| 90 | + feature_type (FeatureTypeEnum): a `FeatureTypeEnum.STRING` type. |
| 91 | + """ |
| 92 | + |
| 93 | + def __init__(self, feature_name: str): |
| 94 | + """Constructs an instance of StringFeatureDefinition. |
| 95 | +
|
| 96 | + Args: |
| 97 | + feature_name (str): the name of the feature. |
| 98 | + """ |
| 99 | + super(StringFeatureDefinition, self).__init__(feature_name, FeatureTypeEnum.STRING) |
0 commit comments