@@ -71,15 +71,6 @@ class Tool:
71
71
instructions = "Classification Example")
72
72
tool.add_classification(classification)
73
73
74
- relationship_tool = Tool(
75
- tool = Tool.Type.RELATIONSHIP,
76
- name = "Relationship Tool Example",
77
- constraints = [
78
- ("source_tool_feature_schema_id_1", "target_tool_feature_schema_id_1"),
79
- ("source_tool_feature_schema_id_2", "target_tool_feature_schema_id_2")
80
- ]
81
- )
82
-
83
74
Attributes:
84
75
tool: (Tool.Type)
85
76
name: (str)
@@ -89,7 +80,6 @@ class Tool:
89
80
schema_id: (str)
90
81
feature_schema_id: (str)
91
82
attributes: (list)
92
- constraints: (list of [str, str]) (only available for RELATIONSHIP tool type)
93
83
"""
94
84
95
85
class Type (Enum ):
@@ -113,28 +103,21 @@ class Type(Enum):
113
103
schema_id : Optional [str ] = None
114
104
feature_schema_id : Optional [str ] = None
115
105
attributes : Optional [FeatureSchemaAttributes ] = None
116
- constraints : Optional [Tuple [str , str ]] = None
117
106
118
107
def __post_init__ (self ):
119
- if self .constraints is not None and self .tool != Tool .Type .RELATIONSHIP :
120
- warnings .warn (
121
- "The constraints attribute is only available for Relationship tool. The provided constraints will be ignored."
122
- )
123
- self .constraints = None
124
108
if self .attributes is not None :
125
109
warnings .warn (
126
110
"The attributes for Tools are in beta. The attribute name and signature may change in the future."
127
111
)
128
112
129
113
@classmethod
130
114
def from_dict (cls , dictionary : Dict [str , Any ]) -> Dict [str , Any ]:
131
- tool = Tool .Type (dictionary ["tool" ])
132
115
return cls (
133
116
name = dictionary ["name" ],
134
117
schema_id = dictionary .get ("schemaNodeId" , None ),
135
118
feature_schema_id = dictionary .get ("featureSchemaId" , None ),
136
119
required = dictionary .get ("required" , False ),
137
- tool = tool ,
120
+ tool = Tool . Type ( dictionary [ " tool" ]) ,
138
121
classifications = [
139
122
Classification .from_dict (c )
140
123
for c in dictionary ["classifications" ]
@@ -146,9 +129,6 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
146
129
]
147
130
if dictionary .get ("attributes" )
148
131
else None ,
149
- constraints = dictionary .get ("constraints" , None )
150
- if tool == Tool .Type .RELATIONSHIP
151
- else None ,
152
132
)
153
133
154
134
def asdict (self ) -> Dict [str , Any ]:
@@ -165,9 +145,6 @@ def asdict(self) -> Dict[str, Any]:
165
145
"attributes" : [a .asdict () for a in self .attributes ]
166
146
if self .attributes is not None
167
147
else None ,
168
- "constraints" : self .constraints
169
- if self .constraints is not None
170
- else None ,
171
148
}
172
149
173
150
def add_classification (self , classification : Classification ) -> None :
@@ -178,6 +155,56 @@ def add_classification(self, classification: Classification) -> None:
178
155
)
179
156
self .classifications .append (classification )
180
157
158
+ @dataclass
159
+ class RelationshipTool (Tool ):
160
+ """
161
+ A relationship tool to be added to a Project's ontology.
162
+
163
+ To instantiate, the "tool" and "name" parameters must
164
+ be passed in.
165
+
166
+ The "classifications" parameter holds a list of Classification objects.
167
+ This can be used to add nested classifications to a tool.
168
+
169
+ Example(s):
170
+ tool = RelationshipTool(
171
+ name = "Relationship Tool example")
172
+ constraints = [
173
+ ("source_tool_feature_schema_id_1", "target_tool_feature_schema_id_1"),
174
+ ("source_tool_feature_schema_id_2", "target_tool_feature_schema_id_2")
175
+ ]
176
+ )
177
+ classification = Classification(
178
+ class_type = Classification.Type.TEXT,
179
+ instructions = "Classification Example")
180
+ tool.add_classification(classification)
181
+
182
+ Attributes:
183
+ tool: Tool.Type.RELATIONSHIP
184
+ name: (str)
185
+ required: (bool)
186
+ color: (str)
187
+ classifications: (list)
188
+ schema_id: (str)
189
+ feature_schema_id: (str)
190
+ attributes: (list)
191
+ constraints: (list of [str, str])
192
+ """
193
+
194
+ tool : Type = Tool .Type .RELATIONSHIP
195
+ constraints : Optional [List [Tuple [str , str ]]] = None
196
+
197
+ def __post_init__ (self ):
198
+ super ().__post_init__ ()
199
+ if self .tool != Tool .Type .RELATIONSHIP :
200
+ raise ValueError ("RelationshipTool can only be used with Tool.Type.RELATIONSHIP" )
201
+
202
+ def asdict (self ) -> Dict [str , Any ]:
203
+ result = super ().asdict ()
204
+ if self .constraints is not None :
205
+ result ["constraints" ] = self .constraints
206
+ return result
207
+
181
208
182
209
"""
183
210
The following 2 functions help to bridge the gap between the step reasoning all other tool ontologies.
@@ -188,6 +215,8 @@ def tool_cls_from_type(tool_type: str):
188
215
tool_cls = map_tool_type_to_tool_cls (tool_type )
189
216
if tool_cls is not None :
190
217
return tool_cls
218
+ if tool_type == Tool .Type .RELATIONSHIP :
219
+ return RelationshipTool
191
220
return Tool
192
221
193
222
0 commit comments