增加拼音匹配
This commit is contained in:
parent
d4b58636a8
commit
5978e32094
@ -80,6 +80,13 @@
|
|||||||
<artifactId>spring-cloud-context</artifactId>
|
<artifactId>spring-cloud-context</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.belerweb</groupId>
|
||||||
|
<artifactId>pinyin4j</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -14,6 +14,9 @@ import com.qiuguo.iot.third.nlp.action.Action;
|
|||||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||||
import com.qiuguo.iot.third.nlp.entity.SystemTalkKeyAndDeviceName;
|
import com.qiuguo.iot.third.nlp.entity.SystemTalkKeyAndDeviceName;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@ -51,6 +54,8 @@ public class NlpService {
|
|||||||
List<SystemTalkAnswerConfigEntity> systemIncluds = new ArrayList<>();
|
List<SystemTalkAnswerConfigEntity> systemIncluds = new ArrayList<>();
|
||||||
List<SystemTalkKeyAndDeviceName> systemTalkKeyAndDeviceNameList = new ArrayList<>();
|
List<SystemTalkKeyAndDeviceName> systemTalkKeyAndDeviceNameList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(SystemTalkAnswerConfigEntity entity : systemTalkAnswerConfigService.getCommandList()){
|
for(SystemTalkAnswerConfigEntity entity : systemTalkAnswerConfigService.getCommandList()){
|
||||||
SystemTalkKeyAndDeviceName systemTalkKeyAndDeviceName = new SystemTalkKeyAndDeviceName();
|
SystemTalkKeyAndDeviceName systemTalkKeyAndDeviceName = new SystemTalkKeyAndDeviceName();
|
||||||
@ -82,6 +87,7 @@ public class NlpService {
|
|||||||
String pText = text;
|
String pText = text;
|
||||||
i = 0;
|
i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
Boolean isFinding = false;
|
||||||
for(SystemTalkKeyAndDeviceName sysTalkKeyAndDeviceName :systemTalkKeyAndDeviceNameList){
|
for(SystemTalkKeyAndDeviceName sysTalkKeyAndDeviceName :systemTalkKeyAndDeviceNameList){
|
||||||
if(pText.indexOf(sysTalkKeyAndDeviceName.getKey()) >= 0){
|
if(pText.indexOf(sysTalkKeyAndDeviceName.getKey()) >= 0){
|
||||||
//找到对应的名称
|
//找到对应的名称
|
||||||
@ -89,10 +95,12 @@ public class NlpService {
|
|||||||
//用户绑定设备名称
|
//用户绑定设备名称
|
||||||
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), ">" + (i++) + ">");
|
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), ">" + (i++) + ">");
|
||||||
includs.add(deviceUserBindEntityPagerResult.getData().get(sysTalkKeyAndDeviceName.getIndex()));
|
includs.add(deviceUserBindEntityPagerResult.getData().get(sysTalkKeyAndDeviceName.getIndex()));
|
||||||
|
isFinding = true;
|
||||||
}else{// if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.SYSTEM_COMMAND.getCode())){
|
}else{// if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.SYSTEM_COMMAND.getCode())){
|
||||||
//是系统自定义动词后的名称
|
//是系统自定义动词后的名称
|
||||||
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
||||||
systemIncluds.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
|
systemIncluds.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
|
||||||
|
isFinding = true;
|
||||||
}/*else{
|
}/*else{
|
||||||
//秋果专有名称
|
//秋果专有名称
|
||||||
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), "<" + (j++) + "<");
|
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), "<" + (j++) + "<");
|
||||||
@ -100,6 +108,25 @@ public class NlpService {
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!isFinding){
|
||||||
|
HanyuPinyinOutputFormat hanyuPinyinOutputFormat = new HanyuPinyinOutputFormat();
|
||||||
|
hanyuPinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||||
|
try {
|
||||||
|
String pinyinArray = PinyinHelper.toHanYuPinyinString(text, hanyuPinyinOutputFormat, null, false).replaceAll("null", "");
|
||||||
|
log.info("拼音结果:{}", pinyinArray);
|
||||||
|
for(SystemTalkKeyAndDeviceName sysTalkKeyAndDeviceName :systemTalkKeyAndDeviceNameList){
|
||||||
|
if(pinyinArray.indexOf(sysTalkKeyAndDeviceName.getKey()) >= 0){
|
||||||
|
if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.QIUGUO_NAME.getCode())){
|
||||||
|
pinyinArray = pinyinArray.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
||||||
|
systemIncluds.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
|
||||||
|
return getActions(pinyinArray, text, includs, systemIncluds, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.info("获取拼音异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
return getActions(pText, text, includs, systemIncluds, type);
|
return getActions(pText, text, includs, systemIncluds, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -110,6 +137,7 @@ public class NlpService {
|
|||||||
List<DeviceUserBindEntity> includs,
|
List<DeviceUserBindEntity> includs,
|
||||||
List<SystemTalkAnswerConfigEntity> commands,
|
List<SystemTalkAnswerConfigEntity> commands,
|
||||||
String type) {
|
String type) {
|
||||||
|
|
||||||
return liguoNlpService.geSingletNlp(text, type).map(nlp -> {
|
return liguoNlpService.geSingletNlp(text, type).map(nlp -> {
|
||||||
Actions actions = new Actions();
|
Actions actions = new Actions();
|
||||||
actions.setActions(new ArrayList<>());
|
actions.setActions(new ArrayList<>());
|
||||||
|
|||||||
@ -94,6 +94,8 @@
|
|||||||
<version>4.6.4</version>
|
<version>4.6.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user