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
f37b1f06
Commit
f37b1f06
authored
Apr 04, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加关键词按序匹配
parent
929dfd03
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
24 deletions
+76
-24
DG_FAF.ts
assets/DG_FAF/scene/DG_FAF.ts
+76
-24
No files found.
assets/DG_FAF/scene/DG_FAF.ts
View file @
f37b1f06
...
...
@@ -1809,7 +1809,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
configInputText
=
contentData
.
inputText
;
if
(
contentData
.
keyWordMatch
)
{
// 关键词匹配,只有回答文字中包含全部关键词,就算对
right
=
this
.
fuzzyMatchingString
(
userInputText
,
configInputText
,
contentData
.
isCaseInsensitive
);
right
=
this
.
fuzzyMatchingString
(
userInputText
,
configInputText
,
{
isCaseInsensitive
:
contentData
.
isCaseInsensitive
?
true
:
false
,
keyWordMatchInOrder
:
contentData
.
keyWordMatchInOrder
?
true
:
false
,
notAdaptContraction
:
contentData
.
notAdaptContraction
?
true
:
false
});
}
else
if
(
contentData
.
openAnswer
)
{
// 开放型回答 只要有内容就算对
right
=
userInputText
!=
""
;
...
...
@@ -1894,7 +1898,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
configInputText
=
option
.
inputText
;
if
(
option
.
keyWordMatch
)
{
// 关键词匹配,只有回答文字中包含全部关键词,就算对
right
=
this
.
fuzzyMatchingString
(
userInputText
,
configInputText
,
option
.
isCaseInsensitive
);
right
=
this
.
fuzzyMatchingString
(
userInputText
,
configInputText
,
{
isCaseInsensitive
:
option
.
isCaseInsensitive
?
true
:
false
,
keyWordMatchInOrder
:
option
.
keyWordMatchInOrder
?
true
:
false
,
notAdaptContraction
:
option
.
notAdaptContraction
?
true
:
false
});
}
else
if
(
option
.
openAnswer
)
{
// 开放型回答 只要有内容就算对
right
=
userInputText
!=
""
;
...
...
@@ -2420,14 +2428,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
right
=
false
;
// 判断是否启用关键词匹配
if
(
contentData
.
keyWordMatch
)
{
right
=
this
.
fuzzyMatchingString
(
recordText
,
evaText
,
contentData
.
isCaseInsensitive
)
right
=
this
.
fuzzyMatchingString
(
recordText
,
evaText
,
{
isCaseInsensitive
:
contentData
.
isCaseInsensitive
?
true
:
false
,
keyWordMatchInOrder
:
contentData
.
keyWordMatchInOrder
?
true
:
false
,
notAdaptContraction
:
contentData
.
notAdaptContraction
?
true
:
false
})
}
else
if
(
contentData
.
openAnswer
)
{
// 开放型回答 只要有内容就算对
right
=
recordText
!=
""
}
else
{
if
(
contentData
.
isCaseInsensitive
)
{
// 不区分大小写
right
=
recordText
.
toLo
caleLowerCase
()
==
evaText
.
toLocale
LowerCase
();
right
=
recordText
.
toLo
werCase
()
==
evaText
.
to
LowerCase
();
}
else
{
// 区分大小写 完全相等
right
=
recordText
==
evaText
;
...
...
@@ -2910,7 +2922,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
// 模糊匹配字符串 1,2,3
fuzzyMatchingString
(
testString
,
matchString
,
isCaseInsensitive
){
fuzzyMatchingString
(
testString
,
matchString
,
options
){
const
{
isCaseInsensitive
,
keyWordMatchInOrder
,
notAdaptContraction
}
=
options
;
matchString
.
replace
(
/,/g
,
"
,
"
);
const
_keyWordGroup
=
matchString
.
split
(
"
|
"
);
// 大的分组 任何一个组匹配了 都算对
...
...
@@ -2921,27 +2939,61 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
let
rightInGroup
=
false
;
keyWordGroup
.
forEach
(
gpKeys
=>
{
// 如果没有正确分组 进行查找
if
(
!
rightInGroup
)
{
// 分组查找
const
result
=
gpKeys
.
find
(
key
=>
{
// console.log(key)
// console.log(testString.toLocaleLowerCase())
// console.log(testString.toLocaleLowerCase().indexOf(key.toLocaleLowerCase()))
if
(
isCaseInsensitive
)
{
// 不区分大小写
return
testString
.
toLocaleLowerCase
().
indexOf
(
key
.
toLocaleLowerCase
())
==
-
1
}
else
{
// 区分大小写
return
testString
.
indexOf
(
key
)
==
-
1
if
(
keyWordMatchInOrder
)
{
// 关键词按序匹配
keyWordGroup
.
forEach
(
gpKeys
=>
{
// 如果没有正确分组 进行查找
if
(
!
rightInGroup
)
{
// 分组查找
let
keyIndex
=
-
1
;
let
matched
=
true
;
const
result
=
gpKeys
.
forEach
(
key
=>
{
// 判断当前组是否还符合匹配顺序
if
(
matched
)
{
let
_keyIndex
=
-
1
;
if
(
isCaseInsensitive
)
{
// 不区分大小写
_keyIndex
=
testString
.
toLowerCase
().
indexOf
(
key
.
toLowerCase
())
}
else
{
// 区分大小写
_keyIndex
=
testString
.
indexOf
(
key
)
}
// 如果找到的索引 比 上一次找到的索引小 则认为不符合
if
(
_keyIndex
<
keyIndex
)
{
matched
=
false
;
}
else
{
keyIndex
=
_keyIndex
;
}
}
})
// 如果符合 并且索引大于0
if
(
matched
&&
keyIndex
>=
0
)
{
rightInGroup
=
true
;
}
})
if
(
result
==
undefined
)
{
rightInGroup
=
true
;
}
}
});
});
}
else
{
keyWordGroup
.
forEach
(
gpKeys
=>
{
// 如果没有正确分组 进行查找
if
(
!
rightInGroup
)
{
// 分组查找
const
result
=
gpKeys
.
find
(
key
=>
{
if
(
isCaseInsensitive
)
{
// 不区分大小写
return
testString
.
toLowerCase
().
indexOf
(
key
.
toLowerCase
())
==
-
1
}
else
{
// 区分大小写
return
testString
.
indexOf
(
key
)
==
-
1
}
})
if
(
result
==
undefined
)
{
rightInGroup
=
true
;
}
}
});
}
return
rightInGroup
;
}
...
...
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