Search in sources :

Example 1 with KnowledgeType

use of com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType in project java-dialogflow by googleapis.

the class DocumentManagement method createDocument.

public static Document createDocument(String knowledgeBaseName, String displayName, String mimeType, String knowledgeType, String contentUri) throws IOException, ApiException, InterruptedException, ExecutionException, TimeoutException {
    // Instantiates a client
    try (DocumentsClient documentsClient = DocumentsClient.create()) {
        Document document = Document.newBuilder().setDisplayName(displayName).setContentUri(contentUri).setMimeType(mimeType).addKnowledgeTypes(KnowledgeType.valueOf(knowledgeType)).build();
        CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(document).setParent(knowledgeBaseName).build();
        OperationFuture<Document, KnowledgeOperationMetadata> response = documentsClient.createDocumentAsync(createDocumentRequest);
        Document createdDocument = response.get(180, TimeUnit.SECONDS);
        System.out.format("Created Document:\n");
        System.out.format(" - Display Name: %s\n", createdDocument.getDisplayName());
        System.out.format(" - Knowledge ID: %s\n", createdDocument.getName());
        System.out.format(" - MIME Type: %s\n", createdDocument.getMimeType());
        System.out.format(" - Knowledge Types:\n");
        for (KnowledgeType knowledgeTypeId : document.getKnowledgeTypesList()) {
            System.out.format("  - %s \n", knowledgeTypeId.getValueDescriptor());
        }
        System.out.format(" - Source: %s \n", document.getContentUri());
        return createdDocument;
    }
}
Also used : KnowledgeOperationMetadata(com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata) CreateDocumentRequest(com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest) Document(com.google.cloud.dialogflow.v2beta1.Document) KnowledgeType(com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType) DocumentsClient(com.google.cloud.dialogflow.v2beta1.DocumentsClient)

Aggregations

CreateDocumentRequest (com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest)1 Document (com.google.cloud.dialogflow.v2beta1.Document)1 KnowledgeType (com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType)1 DocumentsClient (com.google.cloud.dialogflow.v2beta1.DocumentsClient)1 KnowledgeOperationMetadata (com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata)1