use of com.ibm.watson.discovery.v1.model.DocumentAccepted in project nlp4j by oyahiroki.
the class WD2DocumentImporter method importDocument.
@Override
public void importDocument(Document doc) throws IOException {
String fileName;
if (doc.getAttribute("filename") != null) {
fileName = doc.getAttributeAsString("filename");
} else {
fileName = "hello" + System.currentTimeMillis() + ".json";
}
JsonObject jsonObj = DocumentUtil.toJsonObject(doc);
jsonObj.remove("keywords");
{
IamAuthenticator authenticator = new IamAuthenticator(this.DISCOVERY_APIKEY);
Discovery v2Discovery = new Discovery("2020-08-30", authenticator);
v2Discovery.setServiceUrl(this.DISCOVERY_URL);
AddDocumentOptions options = //
new AddDocumentOptions.Builder().projectId(//
this.projectId).collectionId(//
this.collectionId).file(//
new ByteArrayInputStream(jsonObj.toString().getBytes(StandardCharsets.UTF_8))).filename(//
fileName).fileContentType(//
"application/json").build();
DocumentAccepted response = v2Discovery.addDocument(options).execute().getResult();
System.err.println(response.getStatus());
System.err.println(response);
}
}
Aggregations