Skip to content

Commit 5f40ac2

Browse files
committed
feat(model): _convert_model doesnt need classname anymore
1 parent f367c4f commit 5f40ac2

10 files changed

+66
-114
lines changed

ibm_watson/assistant_v1.py

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ def message(self,
132132
if workspace_id is None:
133133
raise ValueError('workspace_id must be provided')
134134
if input is not None:
135-
input = self._convert_model(input, MessageInput)
135+
input = self._convert_model(input)
136136
if intents is not None:
137-
intents = [self._convert_model(x, RuntimeIntent) for x in intents]
137+
intents = [self._convert_model(x) for x in intents]
138138
if entities is not None:
139-
entities = [self._convert_model(x, RuntimeEntity) for x in entities]
139+
entities = [self._convert_model(x) for x in entities]
140140
if context is not None:
141-
context = self._convert_model(context, Context)
141+
context = self._convert_model(context)
142142
if output is not None:
143-
output = self._convert_model(output, OutputData)
143+
output = self._convert_model(output)
144144

145145
headers = {}
146146
if 'headers' in kwargs:
@@ -277,20 +277,15 @@ def create_workspace(self,
277277
"""
278278

279279
if system_settings is not None:
280-
system_settings = self._convert_model(system_settings,
281-
WorkspaceSystemSettings)
280+
system_settings = self._convert_model(system_settings)
282281
if intents is not None:
283-
intents = [self._convert_model(x, CreateIntent) for x in intents]
282+
intents = [self._convert_model(x) for x in intents]
284283
if entities is not None:
285-
entities = [self._convert_model(x, CreateEntity) for x in entities]
284+
entities = [self._convert_model(x) for x in entities]
286285
if dialog_nodes is not None:
287-
dialog_nodes = [
288-
self._convert_model(x, DialogNode) for x in dialog_nodes
289-
]
286+
dialog_nodes = [self._convert_model(x) for x in dialog_nodes]
290287
if counterexamples is not None:
291-
counterexamples = [
292-
self._convert_model(x, Counterexample) for x in counterexamples
293-
]
288+
counterexamples = [self._convert_model(x) for x in counterexamples]
294289

295290
headers = {}
296291
if 'headers' in kwargs:
@@ -442,20 +437,15 @@ def update_workspace(self,
442437
if workspace_id is None:
443438
raise ValueError('workspace_id must be provided')
444439
if system_settings is not None:
445-
system_settings = self._convert_model(system_settings,
446-
WorkspaceSystemSettings)
440+
system_settings = self._convert_model(system_settings)
447441
if intents is not None:
448-
intents = [self._convert_model(x, CreateIntent) for x in intents]
442+
intents = [self._convert_model(x) for x in intents]
449443
if entities is not None:
450-
entities = [self._convert_model(x, CreateEntity) for x in entities]
444+
entities = [self._convert_model(x) for x in entities]
451445
if dialog_nodes is not None:
452-
dialog_nodes = [
453-
self._convert_model(x, DialogNode) for x in dialog_nodes
454-
]
446+
dialog_nodes = [self._convert_model(x) for x in dialog_nodes]
455447
if counterexamples is not None:
456-
counterexamples = [
457-
self._convert_model(x, Counterexample) for x in counterexamples
458-
]
448+
counterexamples = [self._convert_model(x) for x in counterexamples]
459449

460450
headers = {}
461451
if 'headers' in kwargs:
@@ -629,7 +619,7 @@ def create_intent(self,
629619
if intent is None:
630620
raise ValueError('intent must be provided')
631621
if examples is not None:
632-
examples = [self._convert_model(x, Example) for x in examples]
622+
examples = [self._convert_model(x) for x in examples]
633623

634624
headers = {}
635625
if 'headers' in kwargs:
@@ -752,9 +742,7 @@ def update_intent(self,
752742
if intent is None:
753743
raise ValueError('intent must be provided')
754744
if new_examples is not None:
755-
new_examples = [
756-
self._convert_model(x, Example) for x in new_examples
757-
]
745+
new_examples = [self._convert_model(x) for x in new_examples]
758746

759747
headers = {}
760748
if 'headers' in kwargs:
@@ -924,7 +912,7 @@ def create_example(self,
924912
if text is None:
925913
raise ValueError('text must be provided')
926914
if mentions is not None:
927-
mentions = [self._convert_model(x, Mention) for x in mentions]
915+
mentions = [self._convert_model(x) for x in mentions]
928916

929917
headers = {}
930918
if 'headers' in kwargs:
@@ -1036,9 +1024,7 @@ def update_example(self,
10361024
if text is None:
10371025
raise ValueError('text must be provided')
10381026
if new_mentions is not None:
1039-
new_mentions = [
1040-
self._convert_model(x, Mention) for x in new_mentions
1041-
]
1027+
new_mentions = [self._convert_model(x) for x in new_mentions]
10421028

10431029
headers = {}
10441030
if 'headers' in kwargs:
@@ -1476,7 +1462,7 @@ def create_entity(self,
14761462
if entity is None:
14771463
raise ValueError('entity must be provided')
14781464
if values is not None:
1479-
values = [self._convert_model(x, CreateValue) for x in values]
1465+
values = [self._convert_model(x) for x in values]
14801466

14811467
headers = {}
14821468
if 'headers' in kwargs:
@@ -1606,9 +1592,7 @@ def update_entity(self,
16061592
if entity is None:
16071593
raise ValueError('entity must be provided')
16081594
if new_values is not None:
1609-
new_values = [
1610-
self._convert_model(x, CreateValue) for x in new_values
1611-
]
1595+
new_values = [self._convert_model(x) for x in new_values]
16121596

16131597
headers = {}
16141598
if 'headers' in kwargs:
@@ -2498,13 +2482,11 @@ def create_dialog_node(self,
24982482
if dialog_node is None:
24992483
raise ValueError('dialog_node must be provided')
25002484
if output is not None:
2501-
output = self._convert_model(output, DialogNodeOutput)
2485+
output = self._convert_model(output)
25022486
if next_step is not None:
2503-
next_step = self._convert_model(next_step, DialogNodeNextStep)
2487+
next_step = self._convert_model(next_step)
25042488
if actions is not None:
2505-
actions = [
2506-
self._convert_model(x, DialogNodeAction) for x in actions
2507-
]
2489+
actions = [self._convert_model(x) for x in actions]
25082490

25092491
headers = {}
25102492
if 'headers' in kwargs:
@@ -2678,14 +2660,11 @@ def update_dialog_node(self,
26782660
if dialog_node is None:
26792661
raise ValueError('dialog_node must be provided')
26802662
if new_output is not None:
2681-
new_output = self._convert_model(new_output, DialogNodeOutput)
2663+
new_output = self._convert_model(new_output)
26822664
if new_next_step is not None:
2683-
new_next_step = self._convert_model(new_next_step,
2684-
DialogNodeNextStep)
2665+
new_next_step = self._convert_model(new_next_step)
26852666
if new_actions is not None:
2686-
new_actions = [
2687-
self._convert_model(x, DialogNodeAction) for x in new_actions
2688-
]
2667+
new_actions = [self._convert_model(x) for x in new_actions]
26892668

26902669
headers = {}
26912670
if 'headers' in kwargs:

ibm_watson/assistant_v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ def message(self,
203203
if session_id is None:
204204
raise ValueError('session_id must be provided')
205205
if input is not None:
206-
input = self._convert_model(input, MessageInput)
206+
input = self._convert_model(input)
207207
if context is not None:
208-
context = self._convert_model(context, MessageContext)
208+
context = self._convert_model(context)
209209

210210
headers = {}
211211
if 'headers' in kwargs:

ibm_watson/compare_comply_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def add_feedback(self,
338338

339339
if feedback_data is None:
340340
raise ValueError('feedback_data must be provided')
341-
feedback_data = self._convert_model(feedback_data, FeedbackDataInput)
341+
feedback_data = self._convert_model(feedback_data)
342342

343343
headers = {}
344344
if 'headers' in kwargs:

ibm_watson/discovery_v1.py

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,13 @@ def create_configuration(self,
365365
if name is None:
366366
raise ValueError('name must be provided')
367367
if conversions is not None:
368-
conversions = self._convert_model(conversions, Conversions)
368+
conversions = self._convert_model(conversions)
369369
if enrichments is not None:
370-
enrichments = [
371-
self._convert_model(x, Enrichment) for x in enrichments
372-
]
370+
enrichments = [self._convert_model(x) for x in enrichments]
373371
if normalizations is not None:
374-
normalizations = [
375-
self._convert_model(x, NormalizationOperation)
376-
for x in normalizations
377-
]
372+
normalizations = [self._convert_model(x) for x in normalizations]
378373
if source is not None:
379-
source = self._convert_model(source, Source)
374+
source = self._convert_model(source)
380375

381376
headers = {}
382377
if 'headers' in kwargs:
@@ -527,18 +522,13 @@ def update_configuration(self,
527522
if name is None:
528523
raise ValueError('name must be provided')
529524
if conversions is not None:
530-
conversions = self._convert_model(conversions, Conversions)
525+
conversions = self._convert_model(conversions)
531526
if enrichments is not None:
532-
enrichments = [
533-
self._convert_model(x, Enrichment) for x in enrichments
534-
]
527+
enrichments = [self._convert_model(x) for x in enrichments]
535528
if normalizations is not None:
536-
normalizations = [
537-
self._convert_model(x, NormalizationOperation)
538-
for x in normalizations
539-
]
529+
normalizations = [self._convert_model(x) for x in normalizations]
540530
if source is not None:
541-
source = self._convert_model(source, Source)
531+
source = self._convert_model(source)
542532

543533
headers = {}
544534
if 'headers' in kwargs:
@@ -1039,7 +1029,7 @@ def create_expansions(self, environment_id, collection_id, expansions,
10391029
raise ValueError('collection_id must be provided')
10401030
if expansions is None:
10411031
raise ValueError('expansions must be provided')
1042-
expansions = [self._convert_model(x, Expansion) for x in expansions]
1032+
expansions = [self._convert_model(x) for x in expansions]
10431033

10441034
headers = {}
10451035
if 'headers' in kwargs:
@@ -1169,8 +1159,7 @@ def create_tokenization_dictionary(self,
11691159
raise ValueError('collection_id must be provided')
11701160
if tokenization_rules is not None:
11711161
tokenization_rules = [
1172-
self._convert_model(x, TokenDictRule)
1173-
for x in tokenization_rules
1162+
self._convert_model(x) for x in tokenization_rules
11741163
]
11751164

11761165
headers = {}
@@ -2235,9 +2224,9 @@ def query_entities(self,
22352224
if collection_id is None:
22362225
raise ValueError('collection_id must be provided')
22372226
if entity is not None:
2238-
entity = self._convert_model(entity, QueryEntitiesEntity)
2227+
entity = self._convert_model(entity)
22392228
if context is not None:
2240-
context = self._convert_model(context, QueryEntitiesContext)
2229+
context = self._convert_model(context)
22412230

22422231
headers = {}
22432232
if 'headers' in kwargs:
@@ -2313,13 +2302,11 @@ def query_relations(self,
23132302
if collection_id is None:
23142303
raise ValueError('collection_id must be provided')
23152304
if entities is not None:
2316-
entities = [
2317-
self._convert_model(x, QueryRelationsEntity) for x in entities
2318-
]
2305+
entities = [self._convert_model(x) for x in entities]
23192306
if context is not None:
2320-
context = self._convert_model(context, QueryEntitiesContext)
2307+
context = self._convert_model(context)
23212308
if filter is not None:
2322-
filter = self._convert_model(filter, QueryRelationsFilter)
2309+
filter = self._convert_model(filter)
23232310

23242311
headers = {}
23252312
if 'headers' in kwargs:
@@ -2423,9 +2410,7 @@ def add_training_data(self,
24232410
if collection_id is None:
24242411
raise ValueError('collection_id must be provided')
24252412
if examples is not None:
2426-
examples = [
2427-
self._convert_model(x, TrainingExample) for x in examples
2428-
]
2413+
examples = [self._convert_model(x) for x in examples]
24292414

24302415
headers = {}
24312416
if 'headers' in kwargs:
@@ -2893,7 +2878,7 @@ def create_event(self, type, data, **kwargs):
28932878
raise ValueError('type must be provided')
28942879
if data is None:
28952880
raise ValueError('data must be provided')
2896-
data = self._convert_model(data, EventData)
2881+
data = self._convert_model(data)
28972882

28982883
headers = {}
28992884
if 'headers' in kwargs:
@@ -3284,8 +3269,7 @@ def create_credentials(self,
32843269
if environment_id is None:
32853270
raise ValueError('environment_id must be provided')
32863271
if credential_details is not None:
3287-
credential_details = self._convert_model(credential_details,
3288-
CredentialDetails)
3272+
credential_details = self._convert_model(credential_details)
32893273

32903274
headers = {}
32913275
if 'headers' in kwargs:
@@ -3400,8 +3384,7 @@ def update_credentials(self,
34003384
if credential_id is None:
34013385
raise ValueError('credential_id must be provided')
34023386
if credential_details is not None:
3403-
credential_details = self._convert_model(credential_details,
3404-
CredentialDetails)
3387+
credential_details = self._convert_model(credential_details)
34053388

34063389
headers = {}
34073390
if 'headers' in kwargs:

ibm_watson/natural_language_classifier_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def classify_collection(self, classifier_id, collection, **kwargs):
130130
raise ValueError('classifier_id must be provided')
131131
if collection is None:
132132
raise ValueError('collection must be provided')
133-
collection = [self._convert_model(x, ClassifyInput) for x in collection]
133+
collection = [self._convert_model(x) for x in collection]
134134

135135
headers = {}
136136
if 'headers' in kwargs:

ibm_watson/natural_language_understanding_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def analyze(self,
151151

152152
if features is None:
153153
raise ValueError('features must be provided')
154-
features = self._convert_model(features, Features)
154+
features = self._convert_model(features)
155155

156156
headers = {}
157157
if 'headers' in kwargs:

ibm_watson/personality_insights_v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def profile(self,
189189
if accept is None:
190190
raise ValueError('accept must be provided')
191191
if isinstance(content, Content):
192-
content = self._convert_model(content, Content)
192+
content = self._convert_model(content)
193193

194194
headers = {
195195
'Accept': accept,

ibm_watson/speech_to_text_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ def add_words(self, customization_id, words, **kwargs):
17821782
raise ValueError('customization_id must be provided')
17831783
if words is None:
17841784
raise ValueError('words must be provided')
1785-
words = [self._convert_model(x, CustomWord) for x in words]
1785+
words = [self._convert_model(x) for x in words]
17861786

17871787
headers = {}
17881788
if 'headers' in kwargs:

ibm_watson/text_to_speech_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def update_voice_model(self,
489489
if customization_id is None:
490490
raise ValueError('customization_id must be provided')
491491
if words is not None:
492-
words = [self._convert_model(x, Word) for x in words]
492+
words = [self._convert_model(x) for x in words]
493493

494494
headers = {}
495495
if 'headers' in kwargs:
@@ -634,7 +634,7 @@ def add_words(self, customization_id, words, **kwargs):
634634
raise ValueError('customization_id must be provided')
635635
if words is None:
636636
raise ValueError('words must be provided')
637-
words = [self._convert_model(x, Word) for x in words]
637+
words = [self._convert_model(x) for x in words]
638638

639639
headers = {}
640640
if 'headers' in kwargs:

0 commit comments

Comments
 (0)