use of com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator in project java-sdk by watson-developer-cloud.
the class DiscoveryV2Example method main.
public static void main(String[] args) throws IOException {
Authenticator authenticator = new BearerTokenAuthenticator("{bearer_token}");
Discovery service = new Discovery("2019-11-22", authenticator);
service.setServiceUrl("{url}");
// This example assumes you have a project and collection set up which can accept documents.
// Paste those
// IDs below.
String projectId = "";
String collectionId = "";
// Add a new document to our collection. Fill in the file path with the file you want to send.
InputStream file = new FileInputStream("");
AddDocumentOptions addDocumentOptions = new AddDocumentOptions.Builder().projectId(projectId).collectionId(collectionId).file(file).filename("example-file").build();
DocumentAccepted addResponse = service.addDocument(addDocumentOptions).execute().getResult();
String documentId = addResponse.getDocumentId();
// Query your collection with the new document inside.
QueryOptions queryOptions = new QueryOptions.Builder().projectId(projectId).addCollectionIds(collectionId).naturalLanguageQuery(// Feel free to replace this to query something different.
"Watson").build();
QueryResponse queryResponse = service.query(queryOptions).execute().getResult();
System.out.println(queryResponse.getMatchingResults() + " results were returned by the query!");
// See if the added document got returned by the query.
for (QueryResult result : queryResponse.getResults()) {
if (result.getDocumentId().equals(documentId)) {
System.out.println("Our new document matched the query!");
}
}
// Delete our uploaded document from the collection.
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().projectId(projectId).collectionId(collectionId).documentId(documentId).build();
service.deleteDocument(deleteDocumentOptions).execute();
}
use of com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method testGetAutocompletion.
/**
* This only works on a Cloud Pak for Data instance, so ignoring to just run manually.
*/
@Test
@Ignore
public void testGetAutocompletion() {
// fill in
Authenticator authenticator = new BearerTokenAuthenticator("");
Discovery service = new Discovery("2019-10-03", authenticator);
service.setServiceUrl("");
HttpConfigOptions configOptions = new HttpConfigOptions.Builder().disableSslVerification(true).build();
service.configureClient(configOptions);
GetAutocompletionOptions options = new GetAutocompletionOptions.Builder().environmentId(// fill in
"").collectionId(// fill in
"").prefix("Ba").count(10L).build();
Completions response = service.getAutocompletion(options).execute().getResult();
// System.out.println(response);
}
use of com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method testQueryWithSpellingSuggestions.
/**
* This only works on a Cloud Pak for Data instance, so ignoring to just run manually.
*/
@Test
@Ignore
public void testQueryWithSpellingSuggestions() {
// fill in
Authenticator authenticator = new BearerTokenAuthenticator("");
Discovery service = new Discovery("2019-10-03", authenticator);
service.setServiceUrl("");
HttpConfigOptions configOptions = new HttpConfigOptions.Builder().disableSslVerification(true).build();
service.configureClient(configOptions);
QueryOptions options = new QueryOptions.Builder().naturalLanguageQuery("cluod").spellingSuggestions(true).environmentId(// fill in
"").collectionId(// fill in
"").build();
QueryResponse response = service.query(options).execute().getResult();
// System.out.println(response);
}
Aggregations