|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.cmkg.cmkg.server.impl;
|
|
|
|
|
|
|
|
|
|
import com.cmkg.cmkg.server.ReturnData;
|
|
|
|
|
import com.hankcs.hanlp.dictionary.CustomDictionary;
|
|
|
|
|
import com.cmkg.cmkg.process.ModelProcess;
|
|
|
|
|
import com.cmkg.cmkg.repository.QuestionRespository;
|
|
|
|
@ -31,14 +32,10 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private QuestionRespository questionRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showDictPath() {
|
|
|
|
|
System.out.println("HanLP分词字典及自定义问题模板根目录:" + rootDictPath);
|
|
|
|
|
System.out.println("用户自定义扩展词库【病症名】:" + diseasePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String answer(String question) throws Exception {
|
|
|
|
|
public ReturnData answer(String question) throws Exception {
|
|
|
|
|
|
|
|
|
|
ModelProcess queryProcess = new ModelProcess(rootDictPath);
|
|
|
|
|
|
|
|
|
@ -54,8 +51,9 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
loadMedicine(medicinePath);
|
|
|
|
|
|
|
|
|
|
ArrayList<String> reStrings = queryProcess.analyQuery(question);
|
|
|
|
|
for(String sss:reStrings) System.out.println(sss);
|
|
|
|
|
int modelIndex = Integer.valueOf(reStrings.get(0));
|
|
|
|
|
String answer = null;
|
|
|
|
|
ReturnData answer = new ReturnData();
|
|
|
|
|
String title = "";
|
|
|
|
|
/**
|
|
|
|
|
* 匹配问题模板
|
|
|
|
@ -66,11 +64,13 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
* nm 治疗方法 == 病的治疗方法
|
|
|
|
|
*/
|
|
|
|
|
title = reStrings.get(1);
|
|
|
|
|
String[] measure = questionRepository.getDiseaseToMedicine(title);
|
|
|
|
|
System.out.println(title);
|
|
|
|
|
String[] measure = questionRepository.getDiseaseToMedicine(title);
|
|
|
|
|
|
|
|
|
|
if (measure.length==0) {
|
|
|
|
|
answer = null;
|
|
|
|
|
} else {
|
|
|
|
|
answer = measure.toString();
|
|
|
|
|
answer.setData(measure);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
@ -79,8 +79,9 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
*/
|
|
|
|
|
title = reStrings.get(1);
|
|
|
|
|
String symptom = questionRepository.getDiseaseSymptom(title);
|
|
|
|
|
System.out.println(symptom);
|
|
|
|
|
if (symptom != null) {
|
|
|
|
|
answer = symptom;
|
|
|
|
|
answer.setData(symptom);
|
|
|
|
|
} else {
|
|
|
|
|
answer = null;
|
|
|
|
|
}
|
|
|
|
@ -90,9 +91,10 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
* nhm 用法 == 药品用法
|
|
|
|
|
*/
|
|
|
|
|
title = reStrings.get(1);
|
|
|
|
|
String use = questionRepository.getMedicineUse(title);
|
|
|
|
|
String use = questionRepository.getMedicineOperation(title);
|
|
|
|
|
System.out.println(use);
|
|
|
|
|
if (use != null) {
|
|
|
|
|
answer = use;
|
|
|
|
|
answer.setData(use);
|
|
|
|
|
} else {
|
|
|
|
|
answer = null;
|
|
|
|
|
}
|
|
|
|
@ -102,9 +104,10 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
* nhm 作用 == 药品作用
|
|
|
|
|
*/
|
|
|
|
|
title = reStrings.get(1);
|
|
|
|
|
String function= questionRepository.getMedicineFunction(title);
|
|
|
|
|
String function= questionRepository.getMedicineSyndromes(title);
|
|
|
|
|
System.out.println(function);
|
|
|
|
|
if (function != null) {
|
|
|
|
|
answer = function;
|
|
|
|
|
answer.setData(function);
|
|
|
|
|
} else {
|
|
|
|
|
answer = null;
|
|
|
|
|
}
|
|
|
|
@ -113,14 +116,21 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
break; //如果未匹配到模板,返回title的所有信息,待解决
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// System.out.println(answer);
|
|
|
|
|
System.out.println(answer);
|
|
|
|
|
if (answer != null && !answer.equals("") && !answer.equals("\\N")) {
|
|
|
|
|
return answer;
|
|
|
|
|
} else {
|
|
|
|
|
return "sorry,我没有找到你要的答案";
|
|
|
|
|
answer.setData("sorry,我没有找到你要的答案");
|
|
|
|
|
return answer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showDictPat() {
|
|
|
|
|
System.out.println("HanLP分词字典及自定义问题模板根目录:" + rootDictPath);
|
|
|
|
|
System.out.println("用户自定义扩展词库【病症名】:" + diseasePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载自定义病症字典
|
|
|
|
|
*
|
|
|
|
|