IntentHandler.java
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.ys.yslibrary.bean;
import com.ys.yslibrary.viewmodel.PlayerViewModel;
import org.json.JSONArray;
import java.util.List;
/**
* 语义结果处理抽象类
*/
public abstract class IntentHandler {
public static final String NEWLINE = "<br/>";
public static final String NEWLINE_NO_HTML = "\n";
public static final String CONTROL_TIP = "你可以通过语音控制上一个,下一个哦";
public static int controlTipReqCount = 0;
public abstract Answer getFormatContent(SemanticResult result);
//减少播放控制类指令提示次数
public static boolean isNeedShowControlTip() {
return controlTipReqCount++ % 5 == 0;
}
protected String optSlotValue(SemanticResult result, String slotKey) {
JSONArray slots = result.semantic.optJSONArray("slots");
for (int index = 0; index < slots.length(); index++) {
String key = slots.optJSONObject(index).optString("name");
if (key.equalsIgnoreCase(slotKey)) {
return slots.optJSONObject(index).optString("value");
}
}
return null;
}
}