@@ -39,6 +39,87 @@ class FeatureTypeEnum(Enum):
39
39
STRING = "String"
40
40
41
41
42
+ class CollectionTypeEnum (Enum ):
43
+ """Enum of collection types.
44
+
45
+ The collection type of a feature can be List, Set or Vector.
46
+ """
47
+
48
+ LIST = "List"
49
+ SET = "Set"
50
+ VECTOR = "Vector"
51
+
52
+
53
+ @attr .s
54
+ class CollectionType (Config ):
55
+ """Collection type and its configuration.
56
+
57
+ This initiates a collectiontype object where CollectionType is a subclass of Config.
58
+
59
+ Attributes:
60
+ collection_type (CollectionTypeEnum): The type of the collection
61
+ collection_config (Dict[str, Any]): The configuration for the collection.
62
+ """
63
+
64
+ collection_type : CollectionTypeEnum = attr .ib ()
65
+ collection_config : Dict [str , Any ] = attr .ib ()
66
+
67
+ def to_dict (self ) -> Dict [str , Any ]:
68
+ """Construct a dictionary based on each attribute."""
69
+ return Config .construct_dict (
70
+ CollectionType = self .collection_type .value , CollectionConfig = self .collection_config
71
+ )
72
+
73
+
74
+ class ListCollectionType (CollectionType ):
75
+ """List collection type
76
+
77
+ This class instantiates a ListCollectionType object, as subclass of CollectionType
78
+ where the collection type is defined as List.
79
+
80
+ """
81
+
82
+ def __init__ (self ):
83
+ """Construct an instance of ListCollectionType."""
84
+ super (ListCollectionType , self ).__init__ (CollectionTypeEnum .LIST , None )
85
+
86
+
87
+ class SetCollectionType (CollectionType ):
88
+ """Set collection type
89
+
90
+ This class instantiates a SetCollectionType object, as subclass of CollectionType
91
+ where the collection type is defined as Set.
92
+
93
+ """
94
+
95
+ def __init__ (self ):
96
+ """Construct an instance of SetCollectionType."""
97
+ super (SetCollectionType , self ).__init__ (CollectionTypeEnum .SET , None )
98
+
99
+
100
+ class VectorCollectionType (CollectionType ):
101
+ """Vector collection type
102
+
103
+ This class instantiates a VectorCollectionType object, as subclass of CollectionType
104
+ where the collection type is defined as Vector.
105
+
106
+ Attributes:
107
+ dimension (int): The dimension size for the Vector.
108
+ """
109
+
110
+ def __init__ (self , dimension : int ):
111
+ """Construct an instance of VectorCollectionType.
112
+
113
+ Attributes:
114
+ dimension (int): The dimension size for the Vector.
115
+ """
116
+ collection_config : Dict [str , Any ] = {}
117
+ vector_config : Dict [str , Any ] = {}
118
+ vector_config ["Dimension" ] = dimension
119
+ collection_config ["VectorConfig" ] = vector_config
120
+ super (VectorCollectionType , self ).__init__ (CollectionTypeEnum .VECTOR , collection_config )
121
+
122
+
42
123
@attr .s
43
124
class FeatureDefinition (Config ):
44
125
"""Feature definition.
@@ -48,15 +129,25 @@ class FeatureDefinition(Config):
48
129
Attributes:
49
130
feature_name (str): The name of the feature
50
131
feature_type (FeatureTypeEnum): The type of the feature
132
+ collection_type (CollectionType): The type of collection for the feature
51
133
"""
52
134
53
135
feature_name : str = attr .ib ()
54
136
feature_type : FeatureTypeEnum = attr .ib ()
137
+ collection_type : CollectionType = attr .ib (default = None )
55
138
56
139
def to_dict (self ) -> Dict [str , Any ]:
57
140
"""Construct a dictionary based on each attribute."""
141
+
58
142
return Config .construct_dict (
59
- FeatureName = self .feature_name , FeatureType = self .feature_type .value
143
+ FeatureName = self .feature_name ,
144
+ FeatureType = self .feature_type .value ,
145
+ CollectionType = (
146
+ self .collection_type .collection_type .value if self .collection_type else None
147
+ ),
148
+ CollectionConfig = (
149
+ self .collection_type .collection_config if self .collection_type else None
150
+ ),
60
151
)
61
152
62
153
@@ -69,15 +160,18 @@ class FractionalFeatureDefinition(FeatureDefinition):
69
160
Attributes:
70
161
feature_name (str): The name of the feature
71
162
feature_type (FeatureTypeEnum): A `FeatureTypeEnum.FRACTIONAL` type
163
+ collection_type (CollectionType): The type of collection for the feature
72
164
"""
73
165
74
- def __init__ (self , feature_name : str ):
166
+ def __init__ (self , feature_name : str , collection_type : CollectionType = None ):
75
167
"""Construct an instance of FractionalFeatureDefinition.
76
168
77
169
Args:
78
170
feature_name (str): the name of the feature.
79
171
"""
80
- super (FractionalFeatureDefinition , self ).__init__ (feature_name , FeatureTypeEnum .FRACTIONAL )
172
+ super (FractionalFeatureDefinition , self ).__init__ (
173
+ feature_name , FeatureTypeEnum .FRACTIONAL , collection_type
174
+ )
81
175
82
176
83
177
class IntegralFeatureDefinition (FeatureDefinition ):
@@ -89,15 +183,18 @@ class IntegralFeatureDefinition(FeatureDefinition):
89
183
Attributes:
90
184
feature_name (str): the name of the feature.
91
185
feature_type (FeatureTypeEnum): a `FeatureTypeEnum.INTEGRAL` type.
186
+ collection_type (CollectionType): The type of collection for the feature.
92
187
"""
93
188
94
- def __init__ (self , feature_name : str ):
189
+ def __init__ (self , feature_name : str , collection_type : CollectionType = None ):
95
190
"""Construct an instance of IntegralFeatureDefinition.
96
191
97
192
Args:
98
193
feature_name (str): the name of the feature.
99
194
"""
100
- super (IntegralFeatureDefinition , self ).__init__ (feature_name , FeatureTypeEnum .INTEGRAL )
195
+ super (IntegralFeatureDefinition , self ).__init__ (
196
+ feature_name , FeatureTypeEnum .INTEGRAL , collection_type
197
+ )
101
198
102
199
103
200
class StringFeatureDefinition (FeatureDefinition ):
@@ -109,12 +206,15 @@ class StringFeatureDefinition(FeatureDefinition):
109
206
Attributes:
110
207
feature_name (str): the name of the feature.
111
208
feature_type (FeatureTypeEnum): a `FeatureTypeEnum.STRING` type.
209
+ collection_type (CollectionType): The type of collection for the feature.
112
210
"""
113
211
114
- def __init__ (self , feature_name : str ):
212
+ def __init__ (self , feature_name : str , collection_type : CollectionType = None ):
115
213
"""Construct an instance of StringFeatureDefinition.
116
214
117
215
Args:
118
216
feature_name (str): the name of the feature.
119
217
"""
120
- super (StringFeatureDefinition , self ).__init__ (feature_name , FeatureTypeEnum .STRING )
218
+ super (StringFeatureDefinition , self ).__init__ (
219
+ feature_name , FeatureTypeEnum .STRING , collection_type
220
+ )
0 commit comments