Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b8b67c
fix(generation): api def tag 'sdk-2020-08-20' with disco-v2 passage u…
kevinkowa Sep 24, 2020
139d33a
chore(assistant-v1): manual changes
kevinkowa Aug 21, 2020
076e0c5
chore(assistant-v2): manual changes
kevinkowa Aug 21, 2020
03efcd4
chore(language-translator-v3): manual changes
kevinkowa Aug 21, 2020
c80edab
chore(natural-language-classifier-v1): manual changes
kevinkowa Aug 21, 2020
fa3e487
chore(natural-language-understanding-v1): manual changes
kevinkowa Aug 21, 2020
2f04ed6
chore(speech-to-text-v1): manual changes
kevinkowa Aug 21, 2020
0c36249
chore(text-to-speech-v1): manual changes
kevinkowa Aug 21, 2020
378d4c0
chore(visual-recognition-v3): manual changes
kevinkowa Aug 21, 2020
51251ad
chore(visual-recognition-v4): manual changes
kevinkowa Aug 21, 2020
bf98eff
chore(copyright dates): ran lint-copyright-dates
kevinkowa Sep 24, 2020
7f19ef2
chore(assistant-v2): post-gen manual change
kevinkowa Aug 24, 2020
d69fa80
chore(discovery-v1): post-gen manual change
kevinkowa Aug 25, 2020
4693e58
chore(language-translator-v3): post-gen manual change
kevinkowa Aug 25, 2020
06ff414
chore(natural-language-understanding-v1): post-gen manual change
kevinkowa Aug 25, 2020
4153c6f
chore(visual-recognition-v4): post-gen manual change
kevinkowa Aug 25, 2020
4f997aa
chore(natural-language-understanding-v1): post-gen manual change
kevinkowa Aug 25, 2020
93e9479
chore(java-format-google): ran java_format_google.sh
kevinkowa Sep 24, 2020
6457b78
test(discovery-v2): add tests for PassagesPerDocument
kevinkowa Sep 24, 2020
289a9e6
chore(java-format-google): ran java_format_google.sh
kevinkowa Sep 24, 2020
bb87b55
test(disco-v1): update test badCredentialsThrowsException
kevinkowa Sep 25, 2020
5e60f1b
test(language-translator): update test testDocumentTranslation
kevinkowa Sep 25, 2020
ab1458b
test(discovery-v1): update service url in IT tests
kevinkowa Sep 28, 2020
21d51b2
test(discovery-v1): increase timout on createCollection and output tr…
kevinkowa Sep 28, 2020
9e934ca
test(discovery-v1): increate timeout for createDocument and print tra…
kevinkowa Sep 28, 2020
35267d9
test(discovery-v1): remove unnecesary changes
kevinkowa Sep 28, 2020
b66e5d4
test(discovery-v1): revert previous changes
kevinkowa Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class QueryResponse extends GenericModel {
@SerializedName("table_results")
protected List<QueryTableResult> tableResults;

protected List<QueryResponsePassage> passages;

/**
* Gets the matchingResults.
*
Expand Down Expand Up @@ -113,4 +115,15 @@ public List<QuerySuggestedRefinement> getSuggestedRefinements() {
public List<QueryTableResult> getTableResults() {
return tableResults;
}

/**
* Gets the passages.
*
* <p>Passages returned by Discovery.
*
* @return the passages
*/
public List<QueryResponsePassage> getPassages() {
return passages;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* (C) Copyright IBM Corp. 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.discovery.v2.model;

import com.google.gson.annotations.SerializedName;
import com.ibm.cloud.sdk.core.service.model.GenericModel;

/** A passage query response. */
public class QueryResponsePassage extends GenericModel {

@SerializedName("passage_text")
protected String passageText;

@SerializedName("passage_score")
protected Double passageScore;

@SerializedName("document_id")
protected String documentId;

@SerializedName("collection_id")
protected String collectionId;

@SerializedName("start_offset")
protected Long startOffset;

@SerializedName("end_offset")
protected Long endOffset;

protected String field;

/**
* Gets the passageText.
*
* <p>The content of the extracted passage.
*
* @return the passageText
*/
public String getPassageText() {
return passageText;
}

/**
* Gets the passageScore.
*
* <p>The confidence score of the passages's analysis. A higher score indicates greater
* confidence.
*
* @return the passageScore
*/
public Double getPassageScore() {
return passageScore;
}

/**
* Gets the documentId.
*
* <p>The unique identifier of the ingested document.
*
* @return the documentId
*/
public String getDocumentId() {
return documentId;
}

/**
* Gets the collectionId.
*
* <p>The unique identifier of the collection.
*
* @return the collectionId
*/
public String getCollectionId() {
return collectionId;
}

/**
* Gets the startOffset.
*
* <p>The position of the first character of the extracted passage in the originating field.
*
* @return the startOffset
*/
public Long getStartOffset() {
return startOffset;
}

/**
* Gets the endOffset.
*
* <p>The position of the last character of the extracted passage in the originating field.
*
* @return the endOffset
*/
public Long getEndOffset() {
return endOffset;
}

/**
* Gets the field.
*
* <p>The label of the field from which the passage has been extracted.
*
* @return the field
*/
public String getField() {
return field;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
import com.google.gson.internal.LazilyParsedNumber;
import com.ibm.cloud.sdk.core.http.HttpConfigOptions;
import com.ibm.cloud.sdk.core.http.HttpMediaType;
import com.ibm.cloud.sdk.core.http.Response;
import com.ibm.cloud.sdk.core.security.Authenticator;
import com.ibm.cloud.sdk.core.security.BasicAuthenticator;
import com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator;
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
import com.ibm.cloud.sdk.core.service.exception.BadRequestException;
import com.ibm.cloud.sdk.core.service.exception.ForbiddenException;
import com.ibm.cloud.sdk.core.service.exception.InternalServerErrorException;
import com.ibm.cloud.sdk.core.service.exception.NotFoundException;
import com.ibm.cloud.sdk.core.service.exception.*;
import com.ibm.cloud.sdk.core.util.GsonSingleton;
import com.ibm.watson.common.RetryRunner;
import com.ibm.watson.common.WaitFor;
Expand All @@ -40,6 +38,8 @@
import com.ibm.watson.discovery.query.Operator;
import com.ibm.watson.discovery.v1.model.*;
import com.ibm.watson.discovery.v1.model.NormalizationOperation.Operation;

import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -354,7 +354,7 @@ public void pingIsSuccessful() {
}

/** Bad credentials throws exception. */
@Test(expected = ForbiddenException.class)
@Test(expected = UnauthorizedException.class)
public void badCredentialsThrowsException() {
Discovery badService = new Discovery("2019-04-30", new BasicAuthenticator("foo", "bar"));
badService.listEnvironments(null).execute().getResult();
Expand Down Expand Up @@ -2304,7 +2304,8 @@ private class WaitForCollectionAvailable implements WaitFor.Condition {
public boolean isSatisfied() {
GetCollectionOptions getOptions =
new GetCollectionOptions.Builder(environmentId, collectionId).build();
String status = discovery.getCollection(getOptions).execute().getResult().getStatus();
Collection collectionResult = discovery.getCollection(getOptions).execute().getResult();
String status = collectionResult.getStatus();
return status.equals(Collection.Status.ACTIVE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.ibm.cloud.sdk.core.http.HttpMediaType;
import com.ibm.cloud.sdk.core.http.Response;
import com.ibm.cloud.sdk.core.security.Authenticator;
import com.ibm.cloud.sdk.core.security.BasicAuthenticator;
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
import com.ibm.watson.common.RetryRunner;
import com.ibm.watson.common.WatsonServiceTest;
import com.ibm.watson.discovery.query.AggregationType;
Expand All @@ -32,21 +32,21 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

/** The Class DiscoveryIT. */
@Ignore
@RunWith(RetryRunner.class)
@Ignore
public class DiscoveryIT extends WatsonServiceTest {
private static final String VERSION = "2019-11-22";
private static final String RESOURCE = "src/test/resources/discovery/v2/";
private static final String PROJECT_ID = "9558dc01-8554-4d18-b0a5-70196f9f2fe6";
private static final String COLLECTION_ID = "161d1e47-9651-e657-0000-016e8e939caf";
private static final String PROJECT_ID = "571ec4f7-c413-4928-b7f9-3c69045ed27a";
private static final String COLLECTION_ID = "d02b9aa7-903e-2ea1-0000-017410e684bd";

private Discovery service;

Expand All @@ -64,12 +64,11 @@ public class DiscoveryIT extends WatsonServiceTest {
@Before
public void setUp() throws Exception {
super.setUp();
String bearerToken = getProperty("discovery_v2.bearer_token");
Assume.assumeFalse("config.properties doesn't have valid credentials.", (bearerToken == null));

// Authenticator authenticator = new BearerTokenAuthenticator(bearerToken);
String apiKey = getProperty("discovery.apikey");
Authenticator authenticator = new BasicAuthenticator("apikey", apiKey);
Authenticator authenticator =
new IamAuthenticator(
apiKey, "https://iam.test.cloud.ibm.com/identity/token", null, null, false, null);
service = new Discovery(VERSION, authenticator);
service.setDefaultHeaders(getDefaultHeaders());
service.setServiceUrl(getProperty("discovery_v2.url"));
Expand Down Expand Up @@ -1103,4 +1102,47 @@ public void testDeleteUserData() {
assertNotNull(deleteResponse);
assertTrue(deleteResponse.getStatusCode() == 204);
}

/** Test query passages per document true. */
@Test
public void TestQueryPassagesPerDocumentTrue() {
List<String> Ids = new ArrayList<>();
Ids.add(COLLECTION_ID);
QueryLargePassages queryLargePassages =
new QueryLargePassages.Builder().perDocument(true).build();

QueryOptions queryOptions =
new QueryOptions.Builder()
.projectId(PROJECT_ID)
.collectionIds(Ids)
.passages(queryLargePassages)
.query("text:IBM")
.count(2)
.build();
QueryResponse queryResult = service.query(queryOptions).execute().getResult();
assertNotNull(queryResult.getResults().get(0).getDocumentPassages().get(0).getPassageText());
}

/** Test query passages per document false. */
@Test
public void TestQueryPassagesPerDocumentFalse() {
List<String> Ids = new ArrayList<>();
Ids.add(COLLECTION_ID);
QueryLargePassages queryLargePassages =
new QueryLargePassages.Builder().perDocument(false).build();

QueryOptions queryOptions =
new QueryOptions.Builder()
.projectId(PROJECT_ID)
.collectionIds(Ids)
.passages(queryLargePassages)
.query("text:IBM")
.count(2)
.build();
QueryResponse queryResult = service.query(queryOptions).execute().getResult();
assertNotNull(queryResult);
assertNotNull(queryResult.getPassages().get(0).getCollectionId());
assertNotNull(queryResult.getPassages().get(0).getPassageText());
assertNotNull(queryResult.getPassages().get(0).getDocumentId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public void testDocumentTranslation() throws FileNotFoundException, InterruptedE
new TranslateDocumentOptions.Builder()
.file(new File("src/test/resources/language_translation/document_to_translate.txt"))
.fileContentType(HttpMediaType.TEXT_PLAIN)
.filename("java-integration-test-file")
.source("en")
.target("es")
.build();
Expand Down