package com.qiwu.inference.common.utils; import com.qiwu.inference.common.TimingAcquisition; import com.qiwu.inference.pojo.DemandTask; import java.util.List; import java.util.Random; public class SpeechUtil { /** * 取指定范围内的随机数 * @param num1 * @param num2 * @return Integer */ public static Integer getRandomNum(Integer num1, Integer num2) { Integer min = num1 > num2 ? num2 : num1; int sub = num1 > num2 ? num1-num2 : num2-num1; sub = sub == 0 ? 1 : sub; Random random = new Random(); //random.nextInt(1)结果为0,random.nextInt(0)会报错 return random.nextInt(sub) + min; } /** * 从询问模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getAskSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.askSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从任务模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getTaskSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.taskSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getCheckSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.checkSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getBarrierSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.barrierSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 替换话术中的一个数字 * @param one * @return String */ public static String speechReplaceNum(String text, String one) { return text.replace("【1】", one); } /** * 替换话术中的两个数字 * @param one * @param two * @return String */ public static String speechReplaceNum(String text, String one, String two) { return text.replace("【1】", one).replace("【2】", two); } /** * 替换话术中的三个数字 * @param one * @param two * @param three * @return String */ public static String speechReplaceNum(String text, String one, String two, String three) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three); } /** * 替换话术中的四个数字 * @param one * @param two * @param three * @param four * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three).replace("【4】", four); } /** * 替换话术中的五个数字 * @param one * @param two * @param three * @param four * @param five * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five); } /** * 替换话术中的六个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six); } /** * 替换话术中的七个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six).replace("【7】", seven); } /** * 替换话术中的八个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @param eight * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven, String eight) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six) .replace("【7】", seven).replace("【8】", eight); } /** * 替换话术中的九个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @param eight * @param nine * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven, String eight, String nine) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six) .replace("【7】", seven).replace("【8】", eight).replace("【9】", nine); } /** * 替换话术中的【A】 * @param A * @return String */ public static String speechReplaceLetter(String text, String A) { return text.replace("【A】", A); } /** * 替换话术中的【A】和【B】 * @param A * @param B * @return String */ public static String speechReplaceLetter(String text, String A, String B) { return text.replace("【A】", A).replace("【B】", B); } /** * 获取线索配置表中的话术 */ public static String getSpeechFromClue(String uid, Integer taskId) { DemandTask demandTask = TimingAcquisition.demandTaskMap.get(taskId); return null; } /** * 删除话术的开头“【旁白@正常】” * @param text */ public static String deleteAsideHead(String text) { return text.replaceAll("【(.+)@(.{2,4})】", ""); } /** * 合并话术 * @param text1 * @param text2 */ public static String mergeSpeech(String text1, String text2) { text2 = deleteAsideHead(text2); return text1 + text2; } /** * 替换人物名称 * @param text * @return String */ public static String replaceHeader(String text, String name) { return text.replaceAll("【人物名称", "【" + name); } }