Skip to content

Commit 49b6531

Browse files
refactor(readme/nlu): text change and param reorder
1 parent 2280dbb commit 49b6531

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
4646

4747
</details>
4848

49-
## ANNOUNCEMENTS!
49+
## Announcements
5050
### Updating endpoint URLs from watsonplatform.net
5151
Watson API endpoint URLs at watsonplatform.net are changing and will not work after 26 May 2021. Update your calls to use the newer endpoint URLs. For more information, see https://cloud.ibm.com/docs/watson?topic=watson-endpoint-change.
5252

ibm_watson/natural_language_understanding_v1.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# (C) Copyright IBM Corp. 2019, 2021.
3+
# (C) Copyright IBM Corp. 2021.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -3438,10 +3438,6 @@ class Features():
34383438
"""
34393439
Analysis features and options.
34403440
3441-
:attr CategoriesOptions categories: (optional) Returns a five-level taxonomy of
3442-
the content. The top three categories are returned.
3443-
Supported languages: Arabic, English, French, German, Italian, Japanese, Korean,
3444-
Portuguese, Spanish.
34453441
:attr ClassificationsOptions classifications: (optional) Returns text
34463442
classifications for the content.
34473443
Supported languages: English only.
@@ -3489,13 +3485,16 @@ class Features():
34893485
:attr SummarizationOptions summarization: (optional) (Experimental) Returns a
34903486
summary of content.
34913487
Supported languages: English only.
3488+
:attr CategoriesOptions categories: (optional) Returns a five-level taxonomy of
3489+
the content. The top three categories are returned.
3490+
Supported languages: Arabic, English, French, German, Italian, Japanese, Korean,
3491+
Portuguese, Spanish.
34923492
:attr SyntaxOptions syntax: (optional) Returns tokens and sentences from the
34933493
input text.
34943494
"""
34953495

34963496
def __init__(self,
34973497
*,
3498-
categories: 'CategoriesOptions' = None,
34993498
classifications: 'ClassificationsOptions' = None,
35003499
concepts: 'ConceptsOptions' = None,
35013500
emotion: 'EmotionOptions' = None,
@@ -3506,14 +3505,11 @@ def __init__(self,
35063505
semantic_roles: 'SemanticRolesOptions' = None,
35073506
sentiment: 'SentimentOptions' = None,
35083507
summarization: 'SummarizationOptions' = None,
3508+
categories: 'CategoriesOptions' = None,
35093509
syntax: 'SyntaxOptions' = None) -> None:
35103510
"""
35113511
Initialize a Features object.
35123512
3513-
:param CategoriesOptions categories: (optional) Returns a five-level
3514-
taxonomy of the content. The top three categories are returned.
3515-
Supported languages: Arabic, English, French, German, Italian, Japanese,
3516-
Korean, Portuguese, Spanish.
35173513
:param ClassificationsOptions classifications: (optional) Returns text
35183514
classifications for the content.
35193515
Supported languages: English only.
@@ -3562,10 +3558,13 @@ def __init__(self,
35623558
:param SummarizationOptions summarization: (optional) (Experimental)
35633559
Returns a summary of content.
35643560
Supported languages: English only.
3561+
:param CategoriesOptions categories: (optional) Returns a five-level
3562+
taxonomy of the content. The top three categories are returned.
3563+
Supported languages: Arabic, English, French, German, Italian, Japanese,
3564+
Korean, Portuguese, Spanish.
35653565
:param SyntaxOptions syntax: (optional) Returns tokens and sentences from
35663566
the input text.
35673567
"""
3568-
self.categories = categories
35693568
self.classifications = classifications
35703569
self.concepts = concepts
35713570
self.emotion = emotion
@@ -3576,15 +3575,13 @@ def __init__(self,
35763575
self.semantic_roles = semantic_roles
35773576
self.sentiment = sentiment
35783577
self.summarization = summarization
3578+
self.categories = categories
35793579
self.syntax = syntax
35803580

35813581
@classmethod
35823582
def from_dict(cls, _dict: Dict) -> 'Features':
35833583
"""Initialize a Features object from a json dictionary."""
35843584
args = {}
3585-
if 'categories' in _dict:
3586-
args['categories'] = CategoriesOptions.from_dict(
3587-
_dict.get('categories'))
35883585
if 'classifications' in _dict:
35893586
args['classifications'] = ClassificationsOptions.from_dict(
35903587
_dict.get('classifications'))
@@ -3610,6 +3607,9 @@ def from_dict(cls, _dict: Dict) -> 'Features':
36103607
if 'summarization' in _dict:
36113608
args['summarization'] = SummarizationOptions.from_dict(
36123609
_dict.get('summarization'))
3610+
if 'categories' in _dict:
3611+
args['categories'] = CategoriesOptions.from_dict(
3612+
_dict.get('categories'))
36133613
if 'syntax' in _dict:
36143614
args['syntax'] = SyntaxOptions.from_dict(_dict.get('syntax'))
36153615
return cls(**args)
@@ -3622,8 +3622,6 @@ def _from_dict(cls, _dict):
36223622
def to_dict(self) -> Dict:
36233623
"""Return a json dictionary representing this model."""
36243624
_dict = {}
3625-
if hasattr(self, 'categories') and self.categories is not None:
3626-
_dict['categories'] = self.categories.to_dict()
36273625
if hasattr(self,
36283626
'classifications') and self.classifications is not None:
36293627
_dict['classifications'] = self.classifications.to_dict()
@@ -3645,6 +3643,8 @@ def to_dict(self) -> Dict:
36453643
_dict['sentiment'] = self.sentiment.to_dict()
36463644
if hasattr(self, 'summarization') and self.summarization is not None:
36473645
_dict['summarization'] = self.summarization.to_dict()
3646+
if hasattr(self, 'categories') and self.categories is not None:
3647+
_dict['categories'] = self.categories.to_dict()
36483648
if hasattr(self, 'syntax') and self.syntax is not None:
36493649
_dict['syntax'] = self.syntax.to_dict()
36503650
return _dict

test/unit/test_natural_language_understanding_v1.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# (C) Copyright IBM Corp. 2019, 2021.
2+
# (C) Copyright IBM Corp. 2021.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -74,12 +74,6 @@ def test_analyze_all_params(self):
7474
content_type='application/json',
7575
status=200)
7676

77-
# Construct a dict representation of a CategoriesOptions model
78-
categories_options_model = {}
79-
categories_options_model['explanation'] = True
80-
categories_options_model['limit'] = 10
81-
categories_options_model['model'] = 'testString'
82-
8377
# Construct a dict representation of a ClassificationsOptions model
8478
classifications_options_model = {}
8579
classifications_options_model['model'] = 'testString'
@@ -130,6 +124,12 @@ def test_analyze_all_params(self):
130124
summarization_options_model = {}
131125
summarization_options_model['limit'] = 10
132126

127+
# Construct a dict representation of a CategoriesOptions model
128+
categories_options_model = {}
129+
categories_options_model['explanation'] = True
130+
categories_options_model['limit'] = 10
131+
categories_options_model['model'] = 'testString'
132+
133133
# Construct a dict representation of a SyntaxOptionsTokens model
134134
syntax_options_tokens_model = {}
135135
syntax_options_tokens_model['lemma'] = True
@@ -142,7 +142,6 @@ def test_analyze_all_params(self):
142142

143143
# Construct a dict representation of a Features model
144144
features_model = {}
145-
features_model['categories'] = categories_options_model
146145
features_model['classifications'] = classifications_options_model
147146
features_model['concepts'] = concepts_options_model
148147
features_model['emotion'] = emotion_options_model
@@ -153,6 +152,7 @@ def test_analyze_all_params(self):
153152
features_model['semantic_roles'] = semantic_roles_options_model
154153
features_model['sentiment'] = sentiment_options_model
155154
features_model['summarization'] = summarization_options_model
155+
features_model['categories'] = categories_options_model
156156
features_model['syntax'] = syntax_options_model
157157

158158
# Set up parameter values
@@ -213,12 +213,6 @@ def test_analyze_value_error(self):
213213
content_type='application/json',
214214
status=200)
215215

216-
# Construct a dict representation of a CategoriesOptions model
217-
categories_options_model = {}
218-
categories_options_model['explanation'] = True
219-
categories_options_model['limit'] = 10
220-
categories_options_model['model'] = 'testString'
221-
222216
# Construct a dict representation of a ClassificationsOptions model
223217
classifications_options_model = {}
224218
classifications_options_model['model'] = 'testString'
@@ -269,6 +263,12 @@ def test_analyze_value_error(self):
269263
summarization_options_model = {}
270264
summarization_options_model['limit'] = 10
271265

266+
# Construct a dict representation of a CategoriesOptions model
267+
categories_options_model = {}
268+
categories_options_model['explanation'] = True
269+
categories_options_model['limit'] = 10
270+
categories_options_model['model'] = 'testString'
271+
272272
# Construct a dict representation of a SyntaxOptionsTokens model
273273
syntax_options_tokens_model = {}
274274
syntax_options_tokens_model['lemma'] = True
@@ -281,7 +281,6 @@ def test_analyze_value_error(self):
281281

282282
# Construct a dict representation of a Features model
283283
features_model = {}
284-
features_model['categories'] = categories_options_model
285284
features_model['classifications'] = classifications_options_model
286285
features_model['concepts'] = concepts_options_model
287286
features_model['emotion'] = emotion_options_model
@@ -292,6 +291,7 @@ def test_analyze_value_error(self):
292291
features_model['semantic_roles'] = semantic_roles_options_model
293292
features_model['sentiment'] = sentiment_options_model
294293
features_model['summarization'] = summarization_options_model
294+
features_model['categories'] = categories_options_model
295295
features_model['syntax'] = syntax_options_model
296296

297297
# Set up parameter values
@@ -2922,11 +2922,6 @@ def test_features_serialization(self):
29222922

29232923
# Construct dict forms of any model objects needed in order to build this model.
29242924

2925-
categories_options_model = {} # CategoriesOptions
2926-
categories_options_model['explanation'] = True
2927-
categories_options_model['limit'] = 10
2928-
categories_options_model['model'] = 'testString'
2929-
29302925
classifications_options_model = {} # ClassificationsOptions
29312926
classifications_options_model['model'] = 'testString'
29322927

@@ -2967,6 +2962,11 @@ def test_features_serialization(self):
29672962
summarization_options_model = {} # SummarizationOptions
29682963
summarization_options_model['limit'] = 10
29692964

2965+
categories_options_model = {} # CategoriesOptions
2966+
categories_options_model['explanation'] = True
2967+
categories_options_model['limit'] = 10
2968+
categories_options_model['model'] = 'testString'
2969+
29702970
syntax_options_tokens_model = {} # SyntaxOptionsTokens
29712971
syntax_options_tokens_model['lemma'] = True
29722972
syntax_options_tokens_model['part_of_speech'] = True
@@ -2977,7 +2977,6 @@ def test_features_serialization(self):
29772977

29782978
# Construct a json representation of a Features model
29792979
features_model_json = {}
2980-
features_model_json['categories'] = categories_options_model
29812980
features_model_json['classifications'] = classifications_options_model
29822981
features_model_json['concepts'] = concepts_options_model
29832982
features_model_json['emotion'] = emotion_options_model
@@ -2988,6 +2987,7 @@ def test_features_serialization(self):
29882987
features_model_json['semantic_roles'] = semantic_roles_options_model
29892988
features_model_json['sentiment'] = sentiment_options_model
29902989
features_model_json['summarization'] = summarization_options_model
2990+
features_model_json['categories'] = categories_options_model
29912991
features_model_json['syntax'] = syntax_options_model
29922992

29932993
# Construct a model instance of Features by calling from_dict on the json representation

0 commit comments

Comments
 (0)