Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DG_FAF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
DG_FAF
Commits
7a142331
Commit
7a142331
authored
Mar 31, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加新的句子匹配方法
parent
acb6a9cc
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
252 additions
and
2 deletions
+252
-2
DG_FAF.ts
assets/DG_FAF/scene/DG_FAF.ts
+251
-1
defaultData_DG_FAF.ts
assets/DG_FAF/script/defaultData_DG_FAF.ts
+1
-1
No files found.
assets/DG_FAF/scene/DG_FAF.ts
View file @
7a142331
...
@@ -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
)
=>
{
...
...
assets/DG_FAF/script/defaultData_DG_FAF.ts
View file @
7a142331
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment