forked from watson-developer-cloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiscovery_v1.py
More file actions
76 lines (58 loc) · 3.05 KB
/
discovery_v1.py
File metadata and controls
76 lines (58 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8
import json
import watson_developer_cloud
discovery = watson_developer_cloud.DiscoveryV1(
'2016-11-07',
username='YOUR SERVICE USERNAME',
password='YOUR SERVICE PASSWORD')
environments = discovery.get_environments()
print(json.dumps(environments, indent=2))
news_environments = [x for x in environments['environments'] if
x['name'] == 'Watson News Environment']
news_environment_id = news_environments[0]['environment_id']
print(json.dumps(news_environment_id, indent=2))
collections = discovery.list_collections(news_environment_id)
news_collections = [x for x in collections['collections']]
print(json.dumps(collections, indent=2))
configurations = discovery.list_configurations(
environment_id=news_environment_id)
print(json.dumps(configurations, indent=2))
default_config_id = discovery.get_default_configuration_id(
environment_id=news_environment_id)
print(json.dumps(default_config_id, indent=2))
default_config = discovery.get_configuration(
environment_id=news_environment_id, configuration_id=default_config_id)
print(json.dumps(default_config, indent=2))
query_options = {'query': 'IBM'}
query_results = discovery.query(news_environment_id,
news_collections[0]['collection_id'],
query_options)
print(json.dumps(query_results, indent=2))
# new_environment = discovery.create_environment(name="new env", description="bogus env")
# print(new_environment)
#if (discovery.get_environment(environment_id=new_environment['environment_id'])['status'] == 'active'):
# writable_environment_id = new_environment['environment_id']
# new_collection = discovery.create_collection(environment_id=writable_environment_id,
# name='Example Collection',
# description="just a test")
#
# print(new_collection)
#print(discovery.get_collections(environment_id=writable_environment_id))
#res = discovery.delete_collection(environment_id='10b733d0-1232-4924-a670-e6ffaed2e641',
# collection_id=new_collection['collection_id'])
# print(res)
# collections = discovery.list_collections(environment_id=writable_environment_id)
# print(collections)
#with open(os.path.join(os.getcwd(),'..','resources','simple.html')) as fileinfo:
# print(discovery.test_document(environment_id=writable_environment_id, fileinfo=fileinfo))
# In[25]:
# with open(os.path.join(os.getcwd(),'..','resources','simple.html')) as fileinfo:
# res = discovery.add_document(environment_id=writable_environment_id,
# collection_id=collections['collections'][0]['collection_id'],
# fileinfo=fileinfo)
# print(res)
#res = discovery.get_collection(environment_id=writable_environment_id,
# collection_id=collections['collections'][0]['collection_id'])
#print(res['document_counts'])
#res = discovery.delete_environment(environment_id=writable_environment_id)
#print(res)