简体   繁体   English

Clojure:Java Interop IBM沃森对话服务

[英]Clojure: Java Interop IBM watson conversation service

The conversation service has its java code written as 会话服务的java代码编写为

import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageRequest;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse;

 /*
 some code written here
*/
MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();

My main question is how to write this 我的主要问题是如何写这个

 **MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();**

in clojure. 在clojure。

This is what i did so far is 这就是我到目前为止所做的

(ns clj.core
(:import
  (com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
  (com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
  (com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))

 (let [username "foo"
        password "bar"
        input "hello"
        context {}
        workspaceId "ibm-watson-id"
        service (ConversationService. "2017-08-26")
        userPass (.setUsernameAndPassword service username password)

        ;obviously this is wrong
        ;dont know how to get this right
        newMessage (.build (.context  context (.inputText input (MessageRequest.Builder.))))



        response (.message service workspaceId newMessage)]
       response)

Please help. 请帮忙。 Thanks 谢谢

aha, eventually figured it out, it seems the MessageRequest class has another class called Builder 啊哈,最终想通了,似乎MessageRequest类还有另一个叫做Builder的类

All i did was to reference this class and tweak the needful 我所做的就是参考这个课程并调整需要的内容

(ns clj.core
 (:import
  (com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
  (com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
  (com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))

(let [username "foo"
     password "bar"
     input "hello"
     context {}
     workspaceId "ibm-watson-id"
     service (ConversationService. "2017-08-26")
     userPass (.setUsernameAndPassword service username password)

     ;just wanna make it work
     msgReq (MessageRequest$Builder.)
     inputText (.inputText msgReq input)
     content (.context inputText context)
     newMessage (.build content)
     response (.execute (.message service workspaceId newMessage))]
   (println  "Watson Response: " response))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM