【发布时间】:2018-12-20 11:41:51
【问题描述】:
是否可以从 java.xml 设置上下文变量的值?我已经修改了节点 json,并在我想从本地数据库设置数据的结果属性中的该操作中添加了一个操作。所以我在java代码中获取动作并尝试设置动作对象的结果属性的值,下面是我正在尝试但它不起作用的代码。有人可以为此提出更好的方法吗?
if(response.getActions()!=null) {
System.out.println("actions : "+response.getActions());
for (int i = 0; i < response.getActions().size(); i++) {
System.out.println(" i : "+response.getActions().get(i).getName());
if(response.getActions().get(i).getName()=="Apply_For_Loan") {
response.getActions().get(i).setResultVariable("123");
}
}
}
在下面的上下文中设置 result_variable 的值是我的代码。
if(response.getActions().get(i).getName().equals("Apply_For_Loan")) {
System.out.println("in action");
Assistant service = new Assistant("2018-12-12");
service.setUsernameAndPassword(userId, password);
service.setEndPoint(endPoint);
String result=response.getActions().get(i).getResultVariable();
Context context = response.getContext();
context.put(result, "123");
MessageOptions msg=new MessageOptions.Builder(watsonId)
.input(new InputData.Builder("Apply For Loan").build())
.context(context)
.build();
response=service.message(msg).execute();
System.out.println("msg : "+response);
}
以下是我重新执行助手呼叫后得到的响应。
{
"output": {
"generic": [
{
"response_type": "text",
"text": "Hello RSR, you loan application of 5420 is created. Please note the Loan Number for future use "
}
],
"text": [
"Hello RSR, you loan application of 5420 is created. Please note the Loan Number for future use "
],
"nodes_visited": [
"node_1_1544613102320",
"node_1_1544613102320"
],
"log_messages": []
},
"input": {
"text": "Apply For Loan"
},
"intents": [
{
"intent": "ApplyForLoan",
"confidence": 1.0
}
],
"entities": [],
"context": {
"number": 9.971070056E9,
"$Loan_Number": "123",
"system": {
"initialized": true,
"dialog_stack": [
{
"dialog_node": "node_1_1544613102320"
}
],
"dialog_turn_counter": 3.0,
"dialog_request_counter": 3.0,
"_node_output_map": {
"node_1_1544613102320": {
"0": [
0.0
]
}
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"Mail_Id": "Email_Id",
"conversation_id": "b59c7a02-2cc6-4149-ae29-602796ab22e1",
"person": "RSR",
"rupees": 5420.0
},
"actions": [
{
"name": "Apply_For_Loan",
"type": "client",
"parameters": {
"pername": "RSR",
"loanamount": 5420.0
},
"result_variable": "$Loan_Number"
}
]
}
在上面的响应中 $Loan_Number 是我从 java 代码更新的结果变量,我在输出文本中使用相同的 result_variable 返回 $Loan_Number,但在输出文本中它仍然是空白的,并且在操作中它也是还是一片空白?
【问题讨论】:
-
更改 result_variable 值后,当我试图从响应中获取它时,我无法获取它,这就是我说它不起作用的原因。我期望当我从 java 更新结果变量值时,它应该反映在 watson assistant api 中的上下文变量中。所以我可以直接从那里将响应发送给用户。
-
你使用的是哪个版本的api?
-
我使用的是version1
标签: java ibm-watson watson-conversation