update QuestionServiceImpl

master
ziyonghong 5 years ago
parent 1c861b7495
commit 90e478126e

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

Loading…
Cancel
Save