Commit 7a142331 authored by 李维's avatar 李维

添加新的句子匹配方法

parent acb6a9cc
...@@ -1789,7 +1789,17 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1789,7 +1789,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
result.detail.correctText = contentData.inputText; result.detail.correctText = contentData.inputText;
let right = false; let right = false;
if(contentData.keyWordMatch) { if(contentData.adaptContraction) {
// 测试新的匹配规则
right = this.checkEqualitySentence(currentInputText, contentData.inputText, {
keyWordMatch: contentData.keyWordMatch ? true : false,
keyWordMatchInOrder: contentData.keyWordMatchInOrder ? true : false,
isCaseInsensitive: contentData.isCaseInsensitive ? true : false,
openAnswer: contentData.openAnswer ? true : false,
capitalizedFirstLetter: contentData.capitalizedFirstLetter ? true : false,
adaptContraction: contentData.adaptContraction ? true : false,
})
} else if(contentData.keyWordMatch) {
// 关键词匹配,只有回答文字中包含全部关键词,就算对 // 关键词匹配,只有回答文字中包含全部关键词,就算对
right = this.fuzzyMatchingString(currentInputText, contentData.inputText, contentData.isCaseInsensitive) right = this.fuzzyMatchingString(currentInputText, contentData.inputText, contentData.isCaseInsensitive)
} else if(contentData.openAnswer) { } else if(contentData.openAnswer) {
...@@ -2798,6 +2808,246 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -2798,6 +2808,246 @@ export default class SceneComponent extends MyCocosSceneComponent {
return rightInGroup; return rightInGroup;
} }
// 句子相同匹配
checkEqualitySentence(userStr, configStr, options) {
const {
keyWordMatch,
keyWordMatchInOrder,
isCaseInsensitive,
openAnswer,
capitalizedFirstLetter,
adaptContraction
} = options;
// 去掉字符串 首尾空格
userStr = userStr.trim();
configStr = configStr.trim();
// 如果是开放型回答 只有有内容即可
if(openAnswer) {
// 检查结果默认为正确
let right = true;
// 如果是开放型回答 并且有首字母大写要求
if(capitalizedFirstLetter) {
let capitalized = /^[A-Z]/
if(!capitalized.test(userStr)) {
right = false
} else {
right = userStr != ""
}
} else {
right = userStr != ""
}
// 直接返回结果 其他的不需要检查
return right;
}
// 首字母需要大写检查 - 如果不满足,直接返回False
// if(capitalizedFirstLetter) {
// let capitalized = /^[A-Z]/
// if(!capitalized.test(userStr)) {
// return false
// }
// }
// 把一些常见缩写替换统一字符串
if(adaptContraction) {
userStr = this.adaptContraction(userStr);
configStr = this.adaptContraction(configStr);
}
console.log(userStr, configStr)
// 如果是大小写不敏感则统一转换成小写
if(isCaseInsensitive) {
userStr = userStr.toLowerCase();
configStr = configStr.toLowerCase();
}
return userStr == configStr;
}
// 把对应缩写都转换为统一串 AC = Adapt-Contraction
adaptContraction(str) {
const contractionTemplate = {
// I am
"I am": "[@AC(Iam)]",
"I'm": "[@AC(Iam)]",
"I was": "[@AC(Iwas)]",
"i am": "[@AC(iam)]",
"i'm": "[@AC(iam)]",
"i was": "[@AC(iwas)]",
// You are
"You are not": "[@AC(Youarenot)]",
"You're not": "[@AC(Youarenot)]",
"You aren't": "[@AC(Youarenot)]",
"You are": "[@AC(Youare)]",
"You're": "[@AC(Youare)]",
"You were not": "[@AC(Youwerenot)]",
"You weren't": "[@AC(Youwerenot)]",
"You were": "[@AC(Youwere)]",
"you are not": "[@AC(youarenot)]",
"you're not": "[@AC(youarenot)]",
"you aren't": "[@AC(youarenot)]",
"you are": "[@AC(youare)]",
"you're": "[@AC(youare)]",
"you were not": "[@AC(youwerenot)]",
"you weren't": "[@AC(youwerenot)]",
"you were": "[@AC(youwere)]",
// He is
"He is not": "[@AC(Heisnot)]",
"He's not": "[@AC(Heisnot)]",
"He isn't": "[@AC(Heisnot)]",
"He is": "[@AC(Heis)]",
"He's": "[@AC(Heis)]",
"He was not": "[@AC(Hewasnot)]",
"He wasn't": "[@AC(Hewasnot)]",
"He was": "[@AC(Hewas)]",
"he is not": "[@AC(heisnot)]",
"he's not": "[@AC(heisnot)]",
"he isn't": "[@AC(heisnot)]",
"he is": "[@AC(heis)]",
"he's": "[@AC(heis)]",
"he was not": "[@AC(hewasnot)]",
"he wasn't": "[@AC(hewasnot)]",
"he was": "[@AC(hewas)]",
// She is
"She is not": "[@AC(Sheisnot)]",
"She's not": "[@AC(Sheisnot)]",
"She isn't": "[@AC(Sheisnot)]",
"She is": "[@AC(Sheis)]",
"She's": "[@AC(Sheis)]",
"She was not": "[@AC(Shewasnot)]",
"She wasn't": "[@AC(Shewasnot)]",
"She was": "[@AC(Shewas)]",
"she is not": "[@AC(sheisnot)]",
"she's not": "[@AC(sheisnot)]",
"she isn't": "[@AC(sheisnot)]",
"she is": "[@AC(sheis)]",
"she's": "[@AC(sheis)]",
"she was not": "[@AC(shewasnot)]",
"she wasn't": "[@AC(shewasnot)]",
"she was": "[@AC(shewas)]",
// It is
"It is not": "[@AC(Itisnot)]",
"It's not": "[@AC(Itisnot)]",
"It isn't": "[@AC(Itisnot)]",
"It is": "[@AC(Itis)]",
"It's": "[@AC(Itis)]",
"It was not": "[@AC(Itwasnot)]",
"It wasn't": "[@AC(Itwasnot)]",
"It was": "[@AC(Itwas)]",
"it is not": "[@AC(itisnot)]",
"it's not": "[@AC(itisnot)]",
"it isn't": "[@AC(itisnot)]",
"it is": "[@AC(itis)]",
"it's": "[@AC(itis)]",
"it was not": "[@AC(itwasnot)]",
"it wasn't": "[@AC(itwasnot)]",
"it was": "[@AC(itwas)]",
// They are
"They are not": "[@AC(Theyarenot)]",
"They're not": "[@AC(Theyarenot)]",
"They aren't": "[@AC(Theyarenot)]",
"They are": "[@AC(Theyare)]",
"They're": "[@AC(Theyare)]",
"They were not": "[@AC(Theywerenot)]",
"They weren't": "[@AC(Theywerenot)]",
"They were": "[@AC(Theywere)]",
"they are not": "[@AC(theyarenot)]",
"they're not": "[@AC(theyarenot)]",
"they aren't": "[@AC(theyarenot)]",
"they are": "[@AC(theyare)]",
"they're": "[@AC(theyare)]",
"they were not": "[@AC(theywerenot)]",
"they weren't": "[@AC(theywerenot)]",
"they were": "[@AC(theywere)]",
// is not
"is not": "[@AC(isnot)]",
"isn't": "[@AC(isnot)]",
"are not": "[@AC(arenot)]",
"aren't": "[@AC(arenot)]",
"was not": "[@AC(wasnot)]",
"wasn't": "[@AC(wasnot)]",
"were not": "[@AC(werenot)]",
"weren't": "[@AC(werenot)]",
// Do
"do not": "[@AC(donot)]",
"don't": "[@AC(donot)]",
"does not": "[@AC(doesnot)]",
"doesn't": "[@AC(doesnot)]",
// Where What Who How Why When
"Where is": "[@AC(Whereis)]",
"Where's": "[@AC(Whereis)]",
"where is": "[@AC(whereis)]",
"where's": "[@AC(whereis)]",
"What is": "[@AC(Whatis)]",
"What's": "[@AC(Whatis)]",
"what is": "[@AC(whatis)]",
"what's": "[@AC(whatis)]",
"Who is": "[@AC(Whois)]",
"Who's": "[@AC(Whois)]",
"who is": "[@AC(whois)]",
"who's": "[@AC(whois)]",
"How is": "[@AC(Howis)]",
"How's": "[@AC(Howis)]",
"how is": "[@AC(howis)]",
"how's": "[@AC(howis)]",
"Why is": "[@AC(Whyis)]",
"Why's": "[@AC(Whyis)]",
"why is": "[@AC(whyis)]",
"why's": "[@AC(whyis)]",
"When is": "[@AC(Whenis)]",
"When's": "[@AC(Whenis)]",
"when is": "[@AC(whenis)]",
"when's": "[@AC(whenis)]",
"Where are": "[@AC(Whereare)]",
"Where're": "[@AC(Whereare)]",
"where are": "[@AC(whereare)]",
"where're": "[@AC(whereare)]",
"What are": "[@AC(Whatare)]",
"What're": "[@AC(Whatare)]",
"what are": "[@AC(whatare)]",
"what're": "[@AC(whatare)]",
"Who are": "[@AC(Whoare)]",
"Who're": "[@AC(Whoare)]",
"who are": "[@AC(whoare)]",
"who're": "[@AC(whoare)]",
"How are": "[@AC(Howare)]",
"How're": "[@AC(Howare)]",
"how are": "[@AC(howare)]",
"how're": "[@AC(howare)]",
"Why are": "[@AC(Whyare)]",
"Why're": "[@AC(Whyare)]",
"why are": "[@AC(whyare)]",
"why're": "[@AC(whyare)]",
"When are": "[@AC(Whenare)]",
"When're": "[@AC(Whenare)]",
"when are": "[@AC(whenare)]",
"when're": "[@AC(whenare)]",
}
for(let contraction in contractionTemplate) {
str = str.replace(new RegExp(contraction, "g"), contractionTemplate[contraction])
}
return str;
}
// 同步方式显示选择模态框 // 同步方式显示选择模态框
asyncShowSelectModal(option, type) { asyncShowSelectModal(option, type) {
return new Promise((resovle, reject) => { return new Promise((resovle, reject) => {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment