|
1 | 1 | /* |
2 | | - * Copyright 2017 IBM Corp. All Rights Reserved. |
| 2 | + * Copyright 2018 IBM Corp. All Rights Reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
5 | 5 | * the License. You may obtain a copy of the License at |
|
12 | 12 | */ |
13 | 13 | package com.ibm.watson.developer_cloud.discovery.v1; |
14 | 14 |
|
15 | | -import okhttp3.MultipartBody; |
16 | | -import okhttp3.RequestBody; |
17 | | -import com.ibm.watson.developer_cloud.util.RequestUtils; |
18 | 15 | import com.google.gson.JsonObject; |
19 | 16 | import com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions; |
20 | 17 | import com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions; |
|
23 | 20 | import com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions; |
24 | 21 | import com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions; |
25 | 22 | import com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions; |
| 23 | +import com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions; |
26 | 24 | import com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions; |
27 | 25 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteAllTrainingDataOptions; |
28 | 26 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions; |
29 | 27 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteConfigurationOptions; |
30 | 28 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteDocumentOptions; |
31 | 29 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteEnvironmentOptions; |
| 30 | +import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions; |
32 | 31 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingDataOptions; |
33 | 32 | import com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingExampleOptions; |
34 | 33 | import com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted; |
35 | 34 | import com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus; |
36 | 35 | import com.ibm.watson.developer_cloud.discovery.v1.model.Environment; |
| 36 | +import com.ibm.watson.developer_cloud.discovery.v1.model.Expansions; |
37 | 37 | import com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryNoticesOptions; |
38 | 38 | import com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryOptions; |
39 | 39 | import com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions; |
|
50 | 50 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListConfigurationsResponse; |
51 | 51 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions; |
52 | 52 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse; |
| 53 | +import com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions; |
53 | 54 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListFieldsOptions; |
54 | 55 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingDataOptions; |
55 | 56 | import com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingExamplesOptions; |
|
76 | 77 | import com.ibm.watson.developer_cloud.http.ServiceCall; |
77 | 78 | import com.ibm.watson.developer_cloud.service.WatsonService; |
78 | 79 | import com.ibm.watson.developer_cloud.util.GsonSingleton; |
| 80 | +import com.ibm.watson.developer_cloud.util.RequestUtils; |
79 | 81 | import com.ibm.watson.developer_cloud.util.ResponseConverterUtils; |
80 | 82 | import com.ibm.watson.developer_cloud.util.Validator; |
| 83 | +import okhttp3.MultipartBody; |
| 84 | +import okhttp3.RequestBody; |
81 | 85 |
|
82 | 86 | /** |
83 | 87 | * The IBM Watson Discovery Service is a cognitive search and content analytics engine that you can add to applications |
@@ -212,7 +216,7 @@ public ServiceCall<ListEnvironmentsResponse> listEnvironments(ListEnvironmentsOp |
212 | 216 | } |
213 | 217 |
|
214 | 218 | /** |
215 | | - * List environments |
| 219 | + * List environments. |
216 | 220 | * |
217 | 221 | * List existing environments for the service instance. |
218 | 222 | * |
@@ -462,6 +466,28 @@ public ServiceCall<Collection> createCollection(CreateCollectionOptions createCo |
462 | 466 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class)); |
463 | 467 | } |
464 | 468 |
|
| 469 | + /** |
| 470 | + * Set the expansion list. |
| 471 | + * |
| 472 | + * Create or replace the Expansion list for this collection. The maximum number of expanded terms per collection is |
| 473 | + * `500`. The current expansion list is replaced with the uploaded content. |
| 474 | + * |
| 475 | + * @param createExpansionsOptions the {@link CreateExpansionsOptions} containing the options for the call |
| 476 | + * @return a {@link ServiceCall} with a response type of {@link Expansions} |
| 477 | + */ |
| 478 | + public ServiceCall<Expansions> createExpansions(CreateExpansionsOptions createExpansionsOptions) { |
| 479 | + Validator.notNull(createExpansionsOptions, "createExpansionsOptions cannot be null"); |
| 480 | + RequestBuilder builder = RequestBuilder.post(String.format("/v1/environments/%s/collections/%s/expansions", |
| 481 | + createExpansionsOptions.environmentId(), createExpansionsOptions.collectionId())); |
| 482 | + builder.query(VERSION, versionDate); |
| 483 | + final JsonObject contentJson = new JsonObject(); |
| 484 | + if (createExpansionsOptions.expansions() != null) { |
| 485 | + contentJson.add("expansions", GsonSingleton.getGson().toJsonTree(createExpansionsOptions.expansions())); |
| 486 | + } |
| 487 | + builder.bodyJson(contentJson); |
| 488 | + return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class)); |
| 489 | + } |
| 490 | + |
465 | 491 | /** |
466 | 492 | * Delete a collection. |
467 | 493 | * |
@@ -476,6 +502,23 @@ public ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollecti |
476 | 502 | return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); |
477 | 503 | } |
478 | 504 |
|
| 505 | + /** |
| 506 | + * Delete the expansions list. |
| 507 | + * |
| 508 | + * Remove the expansion information for this collection. The expansion list must be deleted to disable query expansion |
| 509 | + * for a collection. |
| 510 | + * |
| 511 | + * @param deleteExpansionsOptions the {@link DeleteExpansionsOptions} containing the options for the call |
| 512 | + * @return a {@link ServiceCall} with a response type of Void |
| 513 | + */ |
| 514 | + public ServiceCall<Void> deleteExpansions(DeleteExpansionsOptions deleteExpansionsOptions) { |
| 515 | + Validator.notNull(deleteExpansionsOptions, "deleteExpansionsOptions cannot be null"); |
| 516 | + RequestBuilder builder = RequestBuilder.delete(String.format("/v1/environments/%s/collections/%s/expansions", |
| 517 | + deleteExpansionsOptions.environmentId(), deleteExpansionsOptions.collectionId())); |
| 518 | + builder.query(VERSION, versionDate); |
| 519 | + return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); |
| 520 | + } |
| 521 | + |
479 | 522 | /** |
480 | 523 | * Get collection details. |
481 | 524 | * |
@@ -526,6 +569,23 @@ public ServiceCall<ListCollectionsResponse> listCollections(ListCollectionsOptio |
526 | 569 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ListCollectionsResponse.class)); |
527 | 570 | } |
528 | 571 |
|
| 572 | + /** |
| 573 | + * List current expansions. |
| 574 | + * |
| 575 | + * Returns the current expansion list for the specified collection. If an expansion list is not specified, an object |
| 576 | + * with empty expansion arrays is returned. |
| 577 | + * |
| 578 | + * @param listExpansionsOptions the {@link ListExpansionsOptions} containing the options for the call |
| 579 | + * @return a {@link ServiceCall} with a response type of {@link Expansions} |
| 580 | + */ |
| 581 | + public ServiceCall<Expansions> listExpansions(ListExpansionsOptions listExpansionsOptions) { |
| 582 | + Validator.notNull(listExpansionsOptions, "listExpansionsOptions cannot be null"); |
| 583 | + RequestBuilder builder = RequestBuilder.get(String.format("/v1/environments/%s/collections/%s/expansions", |
| 584 | + listExpansionsOptions.environmentId(), listExpansionsOptions.collectionId())); |
| 585 | + builder.query(VERSION, versionDate); |
| 586 | + return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class)); |
| 587 | + } |
| 588 | + |
529 | 589 | /** |
530 | 590 | * Update a collection. |
531 | 591 | * |
@@ -562,7 +622,7 @@ public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCo |
562 | 622 | * service attempts to automatically detect the document's media type. * The following field names are reserved and |
563 | 623 | * will be filtered out if present after normalization: `id`, `score`, `highlight`, and any field with the prefix of: |
564 | 624 | * `_`, `+`, or `-` * Fields with empty name values after normalization are filtered out before indexing. * Fields |
565 | | - * containing the following characters after normalization are filtered out before indexing: `#` and `,` |
| 625 | + * containing the following characters after normalization are filtered out before indexing: `#` and `,`. |
566 | 626 | * |
567 | 627 | * @param addDocumentOptions the {@link AddDocumentOptions} containing the options for the call |
568 | 628 | * @return a {@link ServiceCall} with a response type of {@link DocumentAccepted} |
|