Skip to content

Commit 6208d90

Browse files
merge master
2 parents 758e08f + 8ba86b8 commit 6208d90

13 files changed

Lines changed: 967 additions & 148 deletions

README.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ See [CONTRIBUTING.md][CONTRIBUTING].
6969
This library is licensed under the [Apache 2.0 license][license].
7070

7171
[wdc]: http://www.ibm.com/watson/developercloud/
72-
[bluemix]: https://console.ng.bluemix.net
72+
[bluemix]: https://console.bluemix.net
7373
[responses]: https://github.com/getsentry/responses
7474
[requests]: http://docs.python-requests.org/en/latest/
7575
[examples]: https://github.com/watson-developer-cloud/python-sdk/tree/master/examples

examples/discovery v1 configuration tasks .ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"language_info": {
132132
"codemirror_mode": {
133133
"name": "ipython",
134-
"version": 3
134+
"version": 3.0
135135
},
136136
"file_extension": ".py",
137137
"mimetype": "text/x-python",
@@ -143,4 +143,4 @@
143143
},
144144
"nbformat": 4,
145145
"nbformat_minor": 0
146-
}
146+
}

examples/discovery_v1.ipynb

Lines changed: 286 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"source": [
1111
"import sys,pprint\n",
1212
"import os\n",
13+
"import json\n",
1314
"sys.path.append(os.path.join(os.getcwd(),'..'))\n",
1415
"import watson_developer_cloud"
1516
]
@@ -135,7 +136,9 @@
135136
"collapsed": true
136137
},
137138
"outputs": [],
138-
"source": []
139+
"source": [
140+
""
141+
]
139142
},
140143
{
141144
"cell_type": "code",
@@ -150,43 +153,11 @@
150153
},
151154
{
152155
"cell_type": "code",
153-
"execution_count": 18,
156+
"execution_count": null,
154157
"metadata": {
155158
"collapsed": false
156159
},
157-
"outputs": [
158-
{
159-
"name": "stdout",
160-
"output_type": "stream",
161-
"text": [
162-
"{ 'created': '2016-12-16T19:58:20.699Z',\n",
163-
" 'description': 'bogus env',\n",
164-
" 'environment_id': '68f1d470-7e02-466d-b79c-446d3e544bf9',\n",
165-
" 'index_capacity': { 'disk_usage': { 'percent_used': 0,\n",
166-
" 'total': '4 GB',\n",
167-
" 'total_bytes': 4294967296,\n",
168-
" 'used': '0 KB',\n",
169-
" 'used_bytes': 0},\n",
170-
" 'memory_usage': { 'percent_used': 0,\n",
171-
" 'total': '0 KB',\n",
172-
" 'total_bytes': 0,\n",
173-
" 'used': '0 KB',\n",
174-
" 'used_bytes': 0}},\n",
175-
" 'name': 'new env',\n",
176-
" 'read_only': False,\n",
177-
" 'status': 'pending',\n",
178-
" 'updated': '2016-12-16T19:58:20.699Z'}\n",
179-
"{ 'collection_id': 'dfdf5d04-b828-4feb-828e-0da223bfb145',\n",
180-
" 'configuration_id': '6eca556e-1805-4f92-a9ef-b39e87069c53',\n",
181-
" 'created': '2016-12-16T20:01:18.246Z',\n",
182-
" 'description': 'just a test',\n",
183-
" 'language': 'en_us',\n",
184-
" 'name': 'Example Collection',\n",
185-
" 'status': 'active',\n",
186-
" 'updated': '2016-12-16T20:01:18.246Z'}\n"
187-
]
188-
}
189-
],
160+
"outputs": [],
190161
"source": [
191162
"pp.pprint(new_environment)\n",
192163
"\n",
@@ -595,12 +566,284 @@
595566
},
596567
{
597568
"cell_type": "code",
598-
"execution_count": null,
599-
"metadata": {
600-
"collapsed": true
601-
},
602-
"outputs": [],
603-
"source": []
569+
"execution_count": 10,
570+
"metadata": {},
571+
"outputs": [
572+
{
573+
"name": "stdout",
574+
"output_type": "stream",
575+
"text": [
576+
"<Response [204]>\n"
577+
]
578+
}
579+
],
580+
"source": [
581+
"res = discovery.delete_training_data(environment_id=writable_environment_id,\n",
582+
" collection_id=collections['collections'][0]['collection_id'])\n",
583+
"print(res)"
584+
]
585+
},
586+
{
587+
"cell_type": "code",
588+
"execution_count": 14,
589+
"metadata": {},
590+
"outputs": [
591+
{
592+
"name": "stdout",
593+
"output_type": "stream",
594+
"text": [
595+
"{\n",
596+
" \"filter\": \"bar\", \n",
597+
" \"query_id\": \"some_unique_id\", \n",
598+
" \"examples\": [\n",
599+
" {\n",
600+
" \"relevance\": 0, \n",
601+
" \"cross_reference\": \"my_cross_id\", \n",
602+
" \"document_id\": \"my_id\"\n",
603+
" }\n",
604+
" ], \n",
605+
" \"natural_language_query\": \"foo\"\n",
606+
"}\n"
607+
]
608+
}
609+
],
610+
"source": [
611+
"examples = [\n",
612+
" {\n",
613+
" 'document_id': 'my_id',\n",
614+
" 'relevance': 0,\n",
615+
" 'cross_reference': 'my_cross_id'\n",
616+
" }\n",
617+
"]\n",
618+
"res = discovery.add_training_data_query(environment_id=writable_environment_id,\n",
619+
" collection_id=collections['collections'][0]['collection_id'],\n",
620+
" natural_language_query='foo',\n",
621+
" query_id='some_unique_id',\n",
622+
" filter='bar',\n",
623+
" examples=examples)\n",
624+
"print(json.dumps(res, indent=4))"
625+
]
626+
},
627+
{
628+
"cell_type": "code",
629+
"execution_count": 12,
630+
"metadata": {},
631+
"outputs": [
632+
{
633+
"name": "stdout",
634+
"output_type": "stream",
635+
"text": [
636+
"{\n",
637+
" \"collection_id\": \"cb86efe7-d5b1-42c6-8c7b-2ca248dc3fb0\", \n",
638+
" \"environment_id\": \"1cf6702f-d6f4-40f3-97cf-fb99eb110ef8\", \n",
639+
" \"queries\": [\n",
640+
" {\n",
641+
" \"filter\": \"bar\", \n",
642+
" \"query_id\": \"86d74eeba3b2b2175617dcbbd7dabab7db840a1\", \n",
643+
" \"examples\": [\n",
644+
" {\n",
645+
" \"relevance\": 0, \n",
646+
" \"cross_reference\": \"my_cross_id\", \n",
647+
" \"document_id\": \"my_id\"\n",
648+
" }\n",
649+
" ], \n",
650+
" \"natural_language_query\": \"foo\"\n",
651+
" }\n",
652+
" ]\n",
653+
"}\n"
654+
]
655+
}
656+
],
657+
"source": [
658+
"res = discovery.list_training_data(environment_id=writable_environment_id,\n",
659+
" collection_id=collections['collections'][0]['collection_id'])\n",
660+
"\n",
661+
"print(json.dumps(res, indent=4))"
662+
]
663+
},
664+
{
665+
"cell_type": "code",
666+
"execution_count": 13,
667+
"metadata": {},
668+
"outputs": [
669+
{
670+
"name": "stdout",
671+
"output_type": "stream",
672+
"text": [
673+
"<Response [204]>\n"
674+
]
675+
}
676+
],
677+
"source": [
678+
"res = discovery.delete_training_data_query(environment_id=writable_environment_id,\n",
679+
" collection_id=collections['collections'][0]['collection_id'],\n",
680+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1')\n",
681+
"\n",
682+
"print(res)"
683+
]
684+
},
685+
{
686+
"cell_type": "code",
687+
"execution_count": 15,
688+
"metadata": {},
689+
"outputs": [
690+
{
691+
"name": "stdout",
692+
"output_type": "stream",
693+
"text": [
694+
"{\n",
695+
" \"filter\": \"bar\", \n",
696+
" \"query_id\": \"86d74eeba3b2b2175617dcbbd7dabab7db840a1\", \n",
697+
" \"examples\": [\n",
698+
" {\n",
699+
" \"relevance\": 0, \n",
700+
" \"cross_reference\": \"my_cross_id\", \n",
701+
" \"document_id\": \"my_id\"\n",
702+
" }\n",
703+
" ], \n",
704+
" \"natural_language_query\": \"foo\"\n",
705+
"}\n"
706+
]
707+
}
708+
],
709+
"source": [
710+
"res = discovery.get_training_data_query(environment_id=writable_environment_id,\n",
711+
" collection_id=collections['collections'][0]['collection_id'],\n",
712+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1')\n",
713+
"\n",
714+
"print(json.dumps(res, indent=4))"
715+
]
716+
},
717+
{
718+
"cell_type": "code",
719+
"execution_count": 16,
720+
"metadata": {},
721+
"outputs": [
722+
{
723+
"name": "stdout",
724+
"output_type": "stream",
725+
"text": [
726+
"[\n",
727+
" {\n",
728+
" \"relevance\": 0, \n",
729+
" \"cross_reference\": \"my_cross_id\", \n",
730+
" \"document_id\": \"my_id\"\n",
731+
" }\n",
732+
"]\n"
733+
]
734+
}
735+
],
736+
"source": [
737+
"res = discovery.list_training_data_query_examples(environment_id=writable_environment_id,\n",
738+
" collection_id=collections['collections'][0]['collection_id'],\n",
739+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1')\n",
740+
"\n",
741+
"print(json.dumps(res, indent=4))"
742+
]
743+
},
744+
{
745+
"cell_type": "code",
746+
"execution_count": 22,
747+
"metadata": {},
748+
"outputs": [
749+
{
750+
"name": "stdout",
751+
"output_type": "stream",
752+
"text": [
753+
"{\n",
754+
" \"relevance\": 0, \n",
755+
" \"cross_reference\": \"my_other_cross_id\", \n",
756+
" \"document_id\": \"my_other_id\"\n",
757+
"}\n"
758+
]
759+
}
760+
],
761+
"source": [
762+
"res = discovery.add_training_data_query_example(environment_id=writable_environment_id,\n",
763+
" collection_id=collections['collections'][0]['collection_id'],\n",
764+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1',\n",
765+
" document_id='my_other_id',\n",
766+
" relevance=0,\n",
767+
" cross_reference='my_other_cross_id')\n",
768+
"\n",
769+
"print(json.dumps(res, indent=4))"
770+
]
771+
},
772+
{
773+
"cell_type": "code",
774+
"execution_count": 23,
775+
"metadata": {},
776+
"outputs": [
777+
{
778+
"name": "stdout",
779+
"output_type": "stream",
780+
"text": [
781+
"{\n",
782+
" \"relevance\": 0, \n",
783+
" \"cross_reference\": \"my_other_cross_id\", \n",
784+
" \"document_id\": \"my_other_id\"\n",
785+
"}\n"
786+
]
787+
}
788+
],
789+
"source": [
790+
"res = discovery.get_training_data_query_example(environment_id=writable_environment_id,\n",
791+
" collection_id=collections['collections'][0]['collection_id'],\n",
792+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1',\n",
793+
" example_id='my_other_id')\n",
794+
"\n",
795+
"print(json.dumps(res, indent=4))"
796+
]
797+
},
798+
{
799+
"cell_type": "code",
800+
"execution_count": 24,
801+
"metadata": {},
802+
"outputs": [
803+
{
804+
"name": "stdout",
805+
"output_type": "stream",
806+
"text": [
807+
"{\n",
808+
" \"relevance\": 1, \n",
809+
" \"cross_reference\": \"my_other_cross_id\", \n",
810+
" \"document_id\": \"my_other_id\"\n",
811+
"}\n"
812+
]
813+
}
814+
],
815+
"source": [
816+
"res = discovery.update_training_data_query_example(environment_id=writable_environment_id,\n",
817+
" collection_id=collections['collections'][0]['collection_id'],\n",
818+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1',\n",
819+
" example_id='my_other_id',\n",
820+
" relevance=1,\n",
821+
" cross_reference='my_other_cross_id')\n",
822+
"\n",
823+
"print(json.dumps(res, indent=4))"
824+
]
825+
},
826+
{
827+
"cell_type": "code",
828+
"execution_count": 21,
829+
"metadata": {},
830+
"outputs": [
831+
{
832+
"name": "stdout",
833+
"output_type": "stream",
834+
"text": [
835+
"<Response [204]>\n"
836+
]
837+
}
838+
],
839+
"source": [
840+
"res = discovery.delete_training_data_query_example(environment_id=writable_environment_id,\n",
841+
" collection_id=collections['collections'][0]['collection_id'],\n",
842+
" query_id='86d74eeba3b2b2175617dcbbd7dabab7db840a1',\n",
843+
" example_id='my_other_id')\n",
844+
"\n",
845+
"print(res)"
846+
]
604847
}
605848
],
606849
"metadata": {
@@ -613,7 +856,7 @@
613856
"language_info": {
614857
"codemirror_mode": {
615858
"name": "ipython",
616-
"version": 3
859+
"version": 3.0
617860
},
618861
"file_extension": ".py",
619862
"mimetype": "text/x-python",
@@ -625,4 +868,4 @@
625868
},
626869
"nbformat": 4,
627870
"nbformat_minor": 0
628-
}
871+
}

0 commit comments

Comments
 (0)