Skip to content

Commit aa04e06

Browse files
committed
Natural Language Understanding minor clean up
1 parent 43cd0a8 commit aa04e06

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

test/test_examples.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from glob import glob
1010

1111
# tests to exclude
12-
excludes = ['authorization_v1.py', 'alchemy_data_news_v1.py', 'alchemy_language_v1.py', 'discovery_v1.ipynb', '__init__.py']
12+
excludes = ['authorization_v1.py', 'alchemy_data_news_v1.py',
13+
'alchemy_language_v1.py', 'discovery_v1.ipynb', '__init__.py'
14+
'natural_language_understanding_v1.py']
1315

1416
# examples path. /examples
1517
examples_path = join(dirname(__file__), '../', 'examples', '*.py')

watson_developer_cloud/natural_language_understanding_v1.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,22 @@ def analyze(self, features, text=None, url=None, html=None,
5555
:param language: what language to use
5656
:return: dict of analyzed text
5757
"""
58-
body = {'clean': clean, 'fallback_to_raw': fallback_to_raw,
59-
'return_analyzed_text': return_analyzed_text}
60-
if xpath:
61-
body['xpath'] = xpath
62-
63-
if language:
64-
body['language'] = language
58+
body = {'clean': clean,
59+
'fallback_to_raw': fallback_to_raw,
60+
'return_analyzed_text': return_analyzed_text,
61+
'xpath': xpath,
62+
'language': language,
63+
'text': text,
64+
'url': url,
65+
'html': html
66+
}
6567

6668
feature_dict = {}
6769
for feature in features:
6870
feature_dict[feature.name()] = feature.toDict()
6971
body['features'] = feature_dict
7072

71-
if text:
72-
body['text'] = text
73-
elif url:
74-
body['url'] = url
75-
elif html:
76-
body['html'] = html
77-
else:
73+
if not (text or url or body):
7874
msg = "html, text, or url must have content"
7975
raise ValueError(msg)
8076

@@ -84,5 +80,5 @@ def analyze(self, features, text=None, url=None, html=None,
8480
return self.request(method='POST', url='/v1/analyze',
8581
params={"version": self.version},
8682
headers={'content-type': 'application/json'},
87-
data=json.dumps(body),
83+
json=body,
8884
accept_json=True)

0 commit comments

Comments
 (0)