Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qwgame
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
赵国君
qwgame
Commits
6321ac3c
Commit
6321ac3c
authored
Apr 16, 2019
by
hxw2303632
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of 192.168.1.81:hxw2303632/webapp
parents
947af96a
f79bd39c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
609 additions
and
554 deletions
+609
-554
ActionUtils.java
...qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
+3
-3
ConfigTermUtils.java
.../chatbotbackend/actiongenerate/utils/ConfigTermUtils.java
+319
-318
ConfigTermText.java
...n/java/com/qiwu/chatbotbackend/entity/ConfigTermText.java
+15
-13
Premise.java
src/main/java/com/qiwu/chatbotbackend/entity/Premise.java
+123
-63
ListeningConstructor.java
.../qiwu/chatbotbackend/gameDesign/ListeningConstructor.java
+126
-124
PlotConstructor2.java
.../com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java
+23
-33
功能文档.docx
参数和接口文档/功能文档.docx
+0
-0
No files found.
src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
View file @
6321ac3c
...
@@ -846,18 +846,18 @@ public class ActionUtils {
...
@@ -846,18 +846,18 @@ public class ActionUtils {
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_head"
,
new
HashSet
<
String
>());
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_head"
,
new
HashSet
<
String
>());
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_tail"
,
new
HashSet
<
String
>());
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_tail"
,
new
HashSet
<
String
>());
for
(
int
i
=
1
;
i
<
10
;
i
++){
for
(
int
i
=
1
;
i
<
10
0
;
i
++){
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
if
(
i
==
1
)
if
(
i
==
1
)
postfix
=
""
;
postfix
=
""
;
else
else
postfix
=
String
.
valueOf
(
i
);
postfix
=
"_"
+
String
.
valueOf
(
i
);
activeFlag
=
"0"
;
activeFlag
=
"0"
;
conditionJson
=
(
JSONObject
)
patternConditionJson
.
clone
();
conditionJson
=
(
JSONObject
)
patternConditionJson
.
clone
();
conditionName
=
conditionJson
.
getString
(
"conditionName"
)
+
postfix
;
conditionName
=
conditionJson
.
getString
(
"conditionName"
)
+
postfix
;
conditionName2
=
conditionName
+
"_indep
endent
"
;
conditionName2
=
conditionName
+
"_indep"
;
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
)){
//如果没有用到这个condition,就跳过
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
)){
//如果没有用到这个condition,就跳过
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName2
+
"_tail"
))
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName2
+
"_tail"
))
...
...
src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ConfigTermUtils.java
View file @
6321ac3c
package
com
.
qiwu
.
chatbotbackend
.
actiongenerate
.
utils
;
package
com
.
qiwu
.
chatbotbackend
.
actiongenerate
.
utils
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.qiwu.chatbotbackend.actiongenerate.entity.ConfigTerm
;
import
com.qiwu.chatbotbackend.actiongenerate.entity.ConfigTerm
;
import
com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus
;
import
com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus
;
import
com.qiwu.chatbotbackend.db.SqlHelper
;
import
com.qiwu.chatbotbackend.db.SqlHelper
;
import
com.qiwu.chatbotbackend.entity.ConfigTermText
;
import
com.qiwu.chatbotbackend.entity.ConfigTermText
;
import
com.qiwu.chatbotbackend.entity.Premise
;
import
com.qiwu.chatbotbackend.entity.Premise
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.processing.UserInfoController
;
import
com.qiwu.chatbotbackend.processing.UserInfoController
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContext
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.*
;
import
java.util.*
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.
CONFIG_INSERT_ERROR
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.
CONFIG_INSERT_ERROR
;
public
class
ConfigTermUtils
{
public
class
ConfigTermUtils
{
SqlHelper
helper
=
null
;
SqlHelper
helper
=
null
;
String
botAccount
=
""
;
String
botAccount
=
""
;
ServletContext
context
=
null
;
ServletContext
context
=
null
;
UserInfo
userInfo
=
null
;
UserInfo
userInfo
=
null
;
public
IntervalStatus
intervalStatus
=
new
IntervalStatus
(
1
,
""
);
public
IntervalStatus
intervalStatus
=
new
IntervalStatus
(
1
,
""
);
public
ConfigTermUtils
(
String
botAccount
,
SqlHelper
helper
,
ServletContext
context
)
throws
IOException
,
SQLException
{
public
ConfigTermUtils
(
String
botAccount
,
SqlHelper
helper
,
ServletContext
context
)
throws
IOException
,
SQLException
{
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
context
=
context
;
this
.
context
=
context
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
UserInfoController
uiController
=
new
UserInfoController
();
UserInfoController
uiController
=
new
UserInfoController
();
this
.
userInfo
=
uiController
.
userInfoQuery
(
botAccount
,
context
);
this
.
userInfo
=
uiController
.
userInfoQuery
(
botAccount
,
context
);
}
}
public
ConfigTermUtils
(
SqlHelper
helper
){
public
ConfigTermUtils
(
SqlHelper
helper
){
this
.
helper
=
helper
;
this
.
helper
=
helper
;
}
}
public
void
insertConfigTerm
(
JSONObject
parameters
)
throws
IOException
{
public
void
insertConfigTerm
(
JSONObject
parameters
)
throws
IOException
{
Boolean
insertFlag
=
true
;
Boolean
insertFlag
=
true
;
List
<
JSONObject
>
configList
=
new
ArrayList
<
JSONObject
>();
List
<
JSONObject
>
configList
=
new
ArrayList
<
JSONObject
>();
List
<
Integer
>
idList
=
new
ArrayList
<
Integer
>();
List
<
Integer
>
idList
=
new
ArrayList
<
Integer
>();
int
botId
=
parameters
.
getInteger
(
"botId"
);
int
botId
=
parameters
.
getInteger
(
"botId"
);
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
//处理特殊字符
//处理特殊字符
ConfigTermText
configText
=
configPreprocessing
(
parameters
.
getJSONObject
(
"configData"
));
ConfigTermText
configText
=
configPreprocessing
(
parameters
.
getJSONObject
(
"configData"
));
configList
.
add
(
parameters
.
getJSONObject
(
"configData"
));
configList
.
add
(
parameters
.
getJSONObject
(
"configData"
));
insertFlag
=
helper
.
batchInsertConfigByBotId
(
botId
,
configList
,
idList
,
categoryId
);
insertFlag
=
helper
.
batchInsertConfigByBotId
(
botId
,
configList
,
idList
,
categoryId
);
//generateSingleConfigText();
//generateSingleConfigText();
if
(
insertFlag
){
if
(
insertFlag
){
UserInfoController
.
insertConfig
(
botAccount
,
String
.
valueOf
(
idList
.
get
(
0
)),
configText
.
toString
()
+
idList
.
get
(
0
),
context
);
UserInfoController
.
insertConfig
(
botAccount
,
String
.
valueOf
(
idList
.
get
(
0
)),
configText
.
toString
()
+
idList
.
get
(
0
),
context
);
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
intervalStatus
=
new
IntervalStatus
(
1
,
""
);
intervalStatus
=
new
IntervalStatus
(
1
,
""
);
}
else
{
}
else
{
intervalStatus
=
new
IntervalStatus
(
0
,
CONFIG_INSERT_ERROR
);
intervalStatus
=
new
IntervalStatus
(
0
,
CONFIG_INSERT_ERROR
);
}
}
}
}
/**
/**
* 数据预处理
* 数据预处理
* @param configJson
* @param configJson
*/
*/
public
ConfigTermText
configPreprocessing
(
JSONObject
configJson
){
public
ConfigTermText
configPreprocessing
(
JSONObject
configJson
){
int
premiseNum
=
0
,
knowledgeNum
=
0
,
nextStepNum
;
int
premiseNum
=
0
,
knowledgeNum
=
0
,
nextStepNum
;
Premise
premise
=
null
;
Premise
premise
=
null
;
String
reply
,
auxiliaryPriority
=
"0"
,
nextStepStatus
,
configName
;
String
reply
,
auxiliaryPriority
=
"0"
,
nextStepStatus
,
configName
;
StringBuffer
nextStepText
=
new
StringBuffer
(),
featureText
=
new
StringBuffer
();
StringBuffer
nextStepText
=
new
StringBuffer
(),
featureText
=
new
StringBuffer
();
JSONObject
premiseJson
=
null
,
knowledgeJson
=
null
,
nextStep
;
JSONObject
premiseJson
=
null
,
knowledgeJson
=
null
,
nextStep
;
ConfigTermText
configTermText
=
null
;
ConfigTermText
configTermText
=
null
;
List
<
Premise
>
curPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
curPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
hisPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
hisPremiseList
=
new
ArrayList
<
Premise
>();
Map
<
String
,
String
>
updateKnowledge
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
updateKnowledge
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
punctReplaceMap
=
new
LinkedHashMap
<
String
,
String
>();
Map
<
String
,
String
>
punctReplaceMap
=
new
LinkedHashMap
<
String
,
String
>();
punctReplaceMap
.
put
(
","
,
","
);
punctReplaceMap
.
put
(
","
,
","
);
punctReplaceMap
.
put
(
"|"
,
""
);
punctReplaceMap
.
put
(
"|"
,
""
);
punctReplaceMap
.
put
(
"\r\n"
,
""
);
punctReplaceMap
.
put
(
"\r\n"
,
""
);
punctReplaceMap
.
put
(
"\n"
,
""
);
punctReplaceMap
.
put
(
"\n"
,
""
);
punctReplaceMap
.
put
(
"\t"
,
""
);
punctReplaceMap
.
put
(
"\t"
,
""
);
//解析当前信息的前置条件
//解析当前信息的前置条件
premiseNum
=
configJson
.
getJSONArray
(
"currentPremiseList"
).
size
();
premiseNum
=
configJson
.
getJSONArray
(
"currentPremiseList"
).
size
();
for
(
int
i
=
0
;
i
<
premiseNum
;
i
++){
for
(
int
i
=
0
;
i
<
premiseNum
;
i
++){
premiseJson
=
configJson
.
getJSONArray
(
"currentPremiseList"
).
getJSONObject
(
i
);
premiseJson
=
configJson
.
getJSONArray
(
"currentPremiseList"
).
getJSONObject
(
i
);
premise
=
new
Premise
(
premiseJson
.
getString
(
"actionName"
),
premiseJson
.
getString
(
"cmpType"
),
premise
=
new
Premise
(
premiseJson
.
getString
(
"actionName"
),
premiseJson
.
getString
(
"cmpType"
),
premiseJson
.
getString
(
"operator"
),
premiseJson
.
getString
(
"keywords"
));
premiseJson
.
getString
(
"operator"
),
premiseJson
.
getString
(
"keywords"
));
if
(!
premise
.
getConditionName
().
equals
(
""
)
||
!
premise
.
getKeyword
().
equals
(
""
)){
if
(!
premise
.
getConditionName
().
equals
(
""
)
||
!
premise
.
getKeyword
().
equals
(
""
)){
premise
.
setKeyword
(
textReplace
(
premise
.
getKeyword
(),
punctReplaceMap
));
premise
.
setKeyword
(
textReplace
(
premise
.
getKeyword
(),
punctReplaceMap
));
curPremiseList
.
add
(
premise
);
curPremiseList
.
add
(
premise
);
}
}
premiseJson
.
put
(
"keywords"
,
textReplace
(
premiseJson
.
getString
(
"keywords"
),
punctReplaceMap
));
premiseJson
.
put
(
"keywords"
,
textReplace
(
premiseJson
.
getString
(
"keywords"
),
punctReplaceMap
));
}
}
//解析已知信息的前置条件
//解析已知信息的前置条件
premiseNum
=
configJson
.
getJSONArray
(
"historyPremiseList"
).
size
();
premiseNum
=
configJson
.
getJSONArray
(
"historyPremiseList"
).
size
();
for
(
int
i
=
0
;
i
<
premiseNum
;
i
++){
for
(
int
i
=
0
;
i
<
premiseNum
;
i
++){
premiseJson
=
configJson
.
getJSONArray
(
"historyPremiseList"
).
getJSONObject
(
i
);
premiseJson
=
configJson
.
getJSONArray
(
"historyPremiseList"
).
getJSONObject
(
i
);
premise
=
new
Premise
(
premiseJson
.
getString
(
"actionName"
),
premiseJson
.
getString
(
"cmpType"
),
premise
=
new
Premise
(
premiseJson
.
getString
(
"actionName"
),
premiseJson
.
getString
(
"cmpType"
),
premiseJson
.
getString
(
"operator"
),
premiseJson
.
getString
(
"keywords"
));
premiseJson
.
getString
(
"operator"
),
premiseJson
.
getString
(
"keywords"
));
if
(!
premise
.
getConditionName
().
equals
(
""
)
||
!
premise
.
getKeyword
().
equals
(
""
)){
if
(!
premise
.
getConditionName
().
equals
(
""
)
||
!
premise
.
getKeyword
().
equals
(
""
)){
premise
.
setKeyword
(
textReplace
(
premise
.
getKeyword
(),
punctReplaceMap
));
premise
.
setKeyword
(
textReplace
(
premise
.
getKeyword
(),
punctReplaceMap
));
hisPremiseList
.
add
(
premise
);
hisPremiseList
.
add
(
premise
);
}
}
premiseJson
.
put
(
"keywords"
,
textReplace
(
premiseJson
.
getString
(
"keywords"
),
punctReplaceMap
));
premiseJson
.
put
(
"keywords"
,
textReplace
(
premiseJson
.
getString
(
"keywords"
),
punctReplaceMap
));
}
}
//获得辅助优先级
//获得辅助优先级
if
(
configJson
.
get
(
"auxiliaryPriority"
)
!=
null
){
if
(
configJson
.
get
(
"auxiliaryPriority"
)
!=
null
){
auxiliaryPriority
=
String
.
valueOf
(
configJson
.
getInteger
(
"auxiliaryPriority"
));
auxiliaryPriority
=
String
.
valueOf
(
configJson
.
getInteger
(
"auxiliaryPriority"
));
}
}
//获得回答
//获得回答
reply
=
textReplace
(
configJson
.
getString
(
"reply"
),
punctReplaceMap
);
reply
=
textReplace
(
configJson
.
getString
(
"reply"
),
punctReplaceMap
);
configJson
.
put
(
"reply"
,
textReplace
(
configJson
.
getString
(
"reply"
),
punctReplaceMap
));
configJson
.
put
(
"reply"
,
textReplace
(
configJson
.
getString
(
"reply"
),
punctReplaceMap
));
//获得更新知识单元
//获得更新知识单元
if
(
configJson
.
getJSONArray
(
"updateKnowledge"
)
!=
null
)
{
if
(
configJson
.
getJSONArray
(
"updateKnowledge"
)
!=
null
)
{
knowledgeNum
=
configJson
.
getJSONArray
(
"updateKnowledge"
).
size
();
knowledgeNum
=
configJson
.
getJSONArray
(
"updateKnowledge"
).
size
();
for
(
int
i
=
0
;
i
<
knowledgeNum
;
i
++)
{
for
(
int
i
=
0
;
i
<
knowledgeNum
;
i
++)
{
knowledgeJson
=
configJson
.
getJSONArray
(
"updateKnowledge"
).
getJSONObject
(
i
);
knowledgeJson
=
configJson
.
getJSONArray
(
"updateKnowledge"
).
getJSONObject
(
i
);
updateKnowledge
.
put
(
knowledgeJson
.
getString
(
"variableName"
),
textReplace
(
knowledgeJson
.
getString
(
"keyword"
),
punctReplaceMap
));
updateKnowledge
.
put
(
knowledgeJson
.
getString
(
"variableName"
),
textReplace
(
knowledgeJson
.
getString
(
"keyword"
),
punctReplaceMap
));
knowledgeJson
.
put
(
"keyword"
,
textReplace
(
knowledgeJson
.
getString
(
"keyword"
),
punctReplaceMap
));
knowledgeJson
.
put
(
"keyword"
,
textReplace
(
knowledgeJson
.
getString
(
"keyword"
),
punctReplaceMap
));
}
}
}
}
//多个下一步激活问题的处理
//多个下一步激活问题的处理
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
){
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
){
nextStepNum
=
configJson
.
getJSONArray
(
"nextStepList"
).
size
();
nextStepNum
=
configJson
.
getJSONArray
(
"nextStepList"
).
size
();
for
(
int
i
=
0
;
i
<
nextStepNum
;
i
++){
for
(
int
i
=
0
;
i
<
nextStepNum
;
i
++){
if
(
i
!=
0
)
if
(
i
!=
0
)
nextStepText
.
append
(
","
);
nextStepText
.
append
(
","
);
nextStep
=
configJson
.
getJSONArray
(
"nextStepList"
).
getJSONObject
(
i
);
nextStep
=
configJson
.
getJSONArray
(
"nextStepList"
).
getJSONObject
(
i
);
nextStepText
.
append
(
nextStep
.
getString
(
"nextStep"
));
nextStepText
.
append
(
nextStep
.
getString
(
"nextStep"
));
if
(
nextStep
.
get
(
"except"
)
!=
null
&&
nextStep
.
getJSONArray
(
"except"
).
size
()
!=
0
){
if
(
nextStep
.
get
(
"except"
)
!=
null
&&
nextStep
.
getJSONArray
(
"except"
).
size
()
!=
0
){
nextStepText
.
append
(
":"
).
append
(
Joiner
.
on
(
"-"
).
join
(
nextStep
.
getJSONArray
(
"except"
)));
nextStepText
.
append
(
":"
).
append
(
Joiner
.
on
(
"-"
).
join
(
nextStep
.
getJSONArray
(
"except"
)));
}
}
}
}
}
}
if
(
curPremiseList
.
size
()
!=
0
||
hisPremiseList
.
size
()
!=
0
)
if
(
curPremiseList
.
size
()
!=
0
||
hisPremiseList
.
size
()
!=
0
)
//match表示需要条件匹配
//match表示需要条件匹配
featureText
.
append
(
"match"
);
featureText
.
append
(
"match"
);
//是否提交表单
//是否提交表单
if
(
configJson
.
getBoolean
(
"doPost"
)){
if
(
configJson
.
getBoolean
(
"doPost"
)){
featureText
.
append
(
"post::"
).
append
(
configJson
.
getString
(
"postType"
));
featureText
.
append
(
"post::"
).
append
(
configJson
.
getString
(
"postType"
));
featureText
.
append
(
"("
).
append
(
configJson
.
getString
(
"postURL"
)).
append
(
")"
);
featureText
.
append
(
"("
).
append
(
configJson
.
getString
(
"postURL"
)).
append
(
")"
);
}
}
//判断下一步是选择新的问题,还是留在原来的问题,或是返回上一个问题
//判断下一步是选择新的问题,还是留在原来的问题,或是返回上一个问题
if
(!
configJson
.
containsKey
(
"nextStepStatus"
))
if
(!
configJson
.
containsKey
(
"nextStepStatus"
))
featureText
.
append
(
",return-0"
);
featureText
.
append
(
",return-0"
);
else
{
else
{
nextStepStatus
=
configJson
.
getString
(
"nextStepStatus"
);
nextStepStatus
=
configJson
.
getString
(
"nextStepStatus"
);
switch
(
nextStepStatus
){
switch
(
nextStepStatus
){
case
"stay"
:
case
"stay"
:
featureText
.
append
(
",return-0"
);
featureText
.
append
(
",return-0"
);
break
;
break
;
case
"back"
:
case
"back"
:
featureText
.
append
(
",return-1"
);
featureText
.
append
(
",return-1"
);
break
;
break
;
case
"return"
:
case
"return"
:
case
"jump"
:
case
"jump"
:
//存在多个下一步
//存在多个下一步
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
&&
configJson
.
getJSONArray
(
"nextStepList"
).
size
()
>
1
){
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
&&
configJson
.
getJSONArray
(
"nextStepList"
).
size
()
>
1
){
featureText
.
append
(
",newNext"
);
featureText
.
append
(
",newNext"
);
}
}
break
;
break
;
case
"activate"
:
case
"activate"
:
//下一步激活,且激活不为空
//下一步激活,且激活不为空
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
&&
!
configJson
.
getJSONArray
(
"nextStepList"
).
getJSONObject
(
0
).
getString
(
"nextStep"
).
equals
(
""
)){
if
(
configJson
.
get
(
"nextStepList"
)
!=
null
&&
!
configJson
.
getJSONArray
(
"nextStepList"
).
getJSONObject
(
0
).
getString
(
"nextStep"
).
equals
(
""
)){
featureText
.
append
(
",activate"
);
featureText
.
append
(
",activate"
);
}
}
break
;
break
;
}
}
}
}
configTermText
=
new
ConfigTermText
(
curPremiseList
,
hisPremiseList
,
updateKnowledge
,
""
,
""
,
""
,
featureText
.
toString
(),
reply
,
nextStepText
.
toString
(),
auxiliaryPriority
);
Map
<
String
,
Integer
>
gNameCount
=
new
HashMap
<
String
,
Integer
>();
configTermText
=
new
ConfigTermText
(
curPremiseList
,
hisPremiseList
,
updateKnowledge
,
""
,
""
,
""
,
featureText
.
toString
(),
reply
,
nextStepText
.
toString
(),
auxiliaryPriority
,
gNameCount
);
configName
=
configJson
.
getString
(
"configName"
);
if
(
configName
!=
null
&&
!
configName
.
equals
(
""
))
{
configName
=
configJson
.
getString
(
"configName"
);
configTermText
.
setConfigName
(
configName
,
false
);
if
(
configName
!=
null
&&
!
configName
.
equals
(
""
))
{
}
configTermText
.
setConfigName
(
configName
,
false
);
}
return
configTermText
;
return
configTermText
;
}
}
public
void
deleteConfig
(
JSONObject
parameters
)
throws
IOException
{
Boolean
deleteFlag
=
true
;
public
void
deleteConfig
(
JSONObject
parameters
)
throws
IOException
{
int
botId
=
parameters
.
getInteger
(
"botId"
);
Boolean
deleteFlag
=
true
;
int
configId
=
parameters
.
getInteger
(
"configId"
);
int
botId
=
parameters
.
getInteger
(
"botId"
);
int
configId
=
parameters
.
getInteger
(
"configId"
);
deleteFlag
=
helper
.
deleteConfigByConfigId
(
botId
,
configId
);
deleteFlag
=
helper
.
deleteConfigByConfigId
(
botId
,
configId
);
if
(
deleteFlag
){
UserInfoController
.
deleteConfig
(
botAccount
,
String
.
valueOf
(
configId
),
""
,
context
);
if
(
deleteFlag
){
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
UserInfoController
.
deleteConfig
(
botAccount
,
String
.
valueOf
(
configId
),
""
,
context
);
}
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
}
}
}
public
void
updateConfig
(
JSONObject
parameters
)
throws
IOException
{
Boolean
updateFlag
=
true
;
public
void
updateConfig
(
JSONObject
parameters
)
throws
IOException
{
int
botId
=
parameters
.
getInteger
(
"botId"
);
Boolean
updateFlag
=
true
;
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
int
botId
=
parameters
.
getInteger
(
"botId"
);
int
configId
=
parameters
.
getInteger
(
"configId"
);
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
int
configId
=
parameters
.
getInteger
(
"configId"
);
ConfigTermText
configText
=
configPreprocessing
(
parameters
.
getJSONObject
(
"configData"
));
ConfigTermText
configText
=
configPreprocessing
(
parameters
.
getJSONObject
(
"configData"
));
ConfigTerm
configTerm
=
helper
.
queryConfigByConfigId
(
botId
,
configId
);
ConfigTerm
configTerm
=
helper
.
queryConfigByConfigId
(
botId
,
configId
);
updateFlag
=
helper
.
updateConfig
(
new
ConfigTerm
(
botId
,
configId
,
categoryId
,
parameters
.
getJSONObject
(
"configData"
)));
if
(!
updateFlag
){
updateFlag
=
helper
.
updateConfig
(
new
ConfigTerm
(
botId
,
configId
,
categoryId
,
parameters
.
getJSONObject
(
"configData"
)));
if
(
parameters
.
getJSONObject
(
"configData"
).
toJSONString
().
equals
(
configTerm
.
getConfigJsonText
())){
if
(!
updateFlag
){
updateFlag
=
true
;
if
(
parameters
.
getJSONObject
(
"configData"
).
toJSONString
().
equals
(
configTerm
.
getConfigJsonText
())){
}
updateFlag
=
true
;
}
}
}
if
(
updateFlag
){
//更新配置条目
if
(
updateFlag
){
UserInfoController
.
deleteConfig
(
botAccount
,
String
.
valueOf
(
configId
),
""
,
context
);
//更新配置条目
UserInfoController
.
insertConfig
(
botAccount
,
String
.
valueOf
(
configId
),
configText
.
toString
()
+
configId
,
context
);
UserInfoController
.
deleteConfig
(
botAccount
,
String
.
valueOf
(
configId
),
""
,
context
);
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
UserInfoController
.
insertConfig
(
botAccount
,
String
.
valueOf
(
configId
),
configText
.
toString
()
+
configId
,
context
);
}
UserInfoController
.
writeConfigText
(
botAccount
,
userInfo
);
}
}
}
public
void
queryConfig
(
JSONObject
parameters
){
int
botId
=
parameters
.
getInteger
(
"botId"
);
public
void
queryConfig
(
JSONObject
parameters
){
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
int
botId
=
parameters
.
getInteger
(
"botId"
);
JSONArray
configDataList
=
new
JSONArray
();
int
categoryId
=
parameters
.
getInteger
(
"categoryId"
);
JSONObject
configJson
=
null
;
JSONArray
configDataList
=
new
JSONArray
();
JSONObject
configJson
=
null
;
List
<
ConfigTerm
>
configTermList
=
helper
.
queryConfigByCategoryId
(
botId
,
categoryId
);
List
<
ConfigTerm
>
configTermList
=
helper
.
queryConfigByCategoryId
(
botId
,
categoryId
);
for
(
ConfigTerm
configTerm:
configTermList
){
configJson
=
JSONObject
.
parseObject
(
configTerm
.
getConfigJsonText
());
for
(
ConfigTerm
configTerm:
configTermList
){
configJson
.
put
(
"configId"
,
configTerm
.
getConfigId
());
configJson
=
JSONObject
.
parseObject
(
configTerm
.
getConfigJsonText
());
configJson
.
put
(
"categoryId"
,
configTerm
.
getCategoryId
());
configJson
.
put
(
"configId"
,
configTerm
.
getConfigId
());
configJson
.
put
(
"categoryId"
,
configTerm
.
getCategoryId
());
configDataList
.
add
(
configJson
);
}
configDataList
.
add
(
configJson
);
}
intervalStatus
=
new
IntervalStatus
(
1
,
""
,
configDataList
);
}
intervalStatus
=
new
IntervalStatus
(
1
,
""
,
configDataList
);
}
public
void
querySleepingConfig
(
JSONObject
parameters
){
public
void
querySleepingConfig
(
JSONObject
parameters
){
int
botId
=
parameters
.
getInteger
(
"botId"
);
JSONArray
sleepingConfigs
=
new
JSONArray
();
int
botId
=
parameters
.
getInteger
(
"botId"
);
JSONObject
configJson
=
null
;
JSONArray
sleepingConfigs
=
new
JSONArray
();
JSONObject
configJson
=
null
;
List
<
ConfigTerm
>
configTermList
=
helper
.
querySleepingConfig
(
botId
);
List
<
ConfigTerm
>
configTermList
=
helper
.
querySleepingConfig
(
botId
);
for
(
ConfigTerm
configTerm:
configTermList
){
sleepingConfigs
.
add
(
new
JSONArray
(){
for
(
ConfigTerm
configTerm:
configTermList
){
{
sleepingConfigs
.
add
(
new
JSONArray
(){
add
(
configTerm
.
getConfigId
());
{
add
(
configTerm
.
getConfigName
());
add
(
configTerm
.
getConfigId
());
}
add
(
configTerm
.
getConfigName
());
});
}
}
});
}
intervalStatus
=
new
IntervalStatus
(
1
,
""
,
sleepingConfigs
);
}
intervalStatus
=
new
IntervalStatus
(
1
,
""
,
sleepingConfigs
);
}
/**
* 将文本中的一些特殊字符过滤掉
/**
* @param text
* 将文本中的一些特殊字符过滤掉
* @param replaceMap
* @param text
* @return
* @param replaceMap
*/
* @return
public
static
String
textReplace
(
String
text
,
Map
<
String
,
String
>
replaceMap
){
*/
for
(
String
key:
replaceMap
.
keySet
()){
public
static
String
textReplace
(
String
text
,
Map
<
String
,
String
>
replaceMap
){
text
=
text
.
replace
(
key
,
replaceMap
.
get
(
key
));
for
(
String
key:
replaceMap
.
keySet
()){
}
text
=
text
.
replace
(
key
,
replaceMap
.
get
(
key
));
}
return
text
;
}
return
text
;
}
public
void
generateSingleConfigText
(
JSONObject
configJson
){
public
void
generateSingleConfigText
(
JSONObject
configJson
){
}
}
}
}
src/main/java/com/qiwu/chatbotbackend/entity/ConfigTermText.java
View file @
6321ac3c
...
@@ -167,9 +167,9 @@ public class ConfigTermText implements Cloneable{
...
@@ -167,9 +167,9 @@ public class ConfigTermText implements Cloneable{
}
}
public
ConfigTermText
(
List
<
Premise
>
curPremise
,
List
<
Premise
>
hisPremise
,
Map
<
String
,
String
>
updateKnowledge
,
String
extraCP
,
String
extraHP
,
String
extraUK
,
String
feature
,
String
reply
,
String
nextStep
,
String
auxiliaryPriority
)
{
public
ConfigTermText
(
List
<
Premise
>
curPremise
,
List
<
Premise
>
hisPremise
,
Map
<
String
,
String
>
updateKnowledge
,
String
extraCP
,
String
extraHP
,
String
extraUK
,
String
feature
,
String
reply
,
String
nextStep
,
String
auxiliaryPriority
,
Map
<
String
,
Integer
>
gNameCount
)
{
this
.
curPremise
=
appendPremiseStr
(
curPremise
,
extraCP
);
this
.
curPremise
=
appendPremiseStr
(
curPremise
,
extraCP
,
gNameCount
);
this
.
hisPremise
=
appendPremiseStr
(
hisPremise
,
extraHP
);
this
.
hisPremise
=
appendPremiseStr
(
hisPremise
,
extraHP
,
gNameCount
);
this
.
updateKnowledge
=
appendKnowledgeStr
(
updateKnowledge
,
extraUK
);
this
.
updateKnowledge
=
appendKnowledgeStr
(
updateKnowledge
,
extraUK
);
this
.
feature
=
feature
;
this
.
feature
=
feature
;
this
.
reply
=
reply
;
this
.
reply
=
reply
;
...
@@ -177,26 +177,28 @@ public class ConfigTermText implements Cloneable{
...
@@ -177,26 +177,28 @@ public class ConfigTermText implements Cloneable{
this
.
auxiliaryPriority
=
auxiliaryPriority
;
this
.
auxiliaryPriority
=
auxiliaryPriority
;
}
}
public
String
appendPremiseStr
(
List
<
Premise
>
premises
,
String
extraPremise
)
{
public
String
appendPremiseStr
(
List
<
Premise
>
premises
,
String
extraPremise
,
Map
<
String
,
Integer
>
gNameCount
)
{
StringBuffer
sb
=
new
StringBuffer
();
StringBuffer
sb
=
new
StringBuffer
();
String
premiseStr
=
""
,
conditionName
;
String
premiseStr
=
""
,
conditionName
;
Map
<
String
,
Integer
>
nameCount
=
new
HashMap
<
String
,
Integer
>();
for
(
Premise
premise
:
premises
){
for
(
Premise
premise
:
premises
){
conditionName
=
premise
.
getConditionName
();
conditionName
=
premise
.
getConditionName
();
if
(
conditionName
.
startsWith
(
"npc_"
)
||
if
(
conditionName
.
startsWith
(
"npc_"
)
||
conditionName
.
startsWith
(
"goods_"
)
||
conditionName
.
startsWith
(
"goods_"
)
||
conditionName
.
startsWith
(
"globalVariable_"
)
||
conditionName
.
startsWith
(
"globalVariable_"
)
||
conditionName
.
startsWith
(
"map_"
))
conditionName
.
startsWith
(
"map_"
)
||
conditionName
.
startsWith
(
"start_options"
)
||
conditionName
.
startsWith
(
"load_game_by_site"
)
)
{}
{}
else
{
else
{
nameCount
.
putIfAbsent
(
conditionName
,
0
);
gNameCount
.
putIfAbsent
(
conditionName
,
0
);
//nameCount加一
gNameCount
.
put
(
conditionName
,
gNameCount
.
get
(
conditionName
)
+
1
);
nameCount
.
put
(
conditionName
,
nameCount
.
get
(
conditionName
)
+
1
);
if
(
gNameCount
.
get
(
conditionName
)
>
1
&&
premise
.
getAccurateMatch
())
{
//在conditionName后添加count
premise
.
setConditionName
(
conditionName
+
"_"
+
gNameCount
.
get
(
conditionName
));
if
(
nameCount
.
get
(
conditionName
)
>
1
)
{
premise
.
setAccurateName
();
premise
.
setConditionName
(
conditionName
+
nameCount
.
get
(
conditionName
)
+
"_independent"
);
}
}
}
}
sb
.
append
(
","
);
sb
.
append
(
","
);
...
...
src/main/java/com/qiwu/chatbotbackend/entity/Premise.java
View file @
6321ac3c
package
com
.
qiwu
.
chatbotbackend
.
entity
;
package
com
.
qiwu
.
chatbotbackend
.
entity
;
public
class
Premise
{
public
class
Premise
{
private
String
conditionName
=
""
;
private
String
conditionName
=
""
;
private
String
cmpType
=
""
;
private
String
cmpType
=
""
;
private
String
operator
=
""
;
private
String
operator
=
""
;
private
String
keyword
=
""
;
private
String
keyword
=
""
;
private
Boolean
accurateMatch
=
false
;
public
Premise
(
String
conditionName
,
String
cmpType
,
String
operator
,
String
keyword
)
{
private
String
plot
=
""
;
private
int
branch
=
0
;
this
.
conditionName
=
conditionName
;
this
.
cmpType
=
cmpType
;
public
String
getPlot
()
{
this
.
operator
=
operator
;
return
plot
;
this
.
keyword
=
keyword
;
}
if
(
cmpType
==
null
){
public
void
setPlot
(
String
plot
)
{
this
.
cmpType
=
"match"
;
this
.
plot
=
plot
;
}
else
{
}
this
.
cmpType
=
cmpType
;
}
public
int
getBranch
()
{
return
branch
;
if
(
operator
==
null
){
}
this
.
operator
=
"Include"
;
}
else
{
public
void
setBranch
(
int
branch
)
{
this
.
operator
=
operator
;
this
.
branch
=
branch
;
}
}
if
(
cmpType
.
equals
(
"any"
)){
this
.
operator
=
"Include"
;
public
Boolean
getAccurateMatch
()
{
}
return
accurateMatch
;
}
}
public
String
getConditionName
()
{
public
void
setAccurateMatch
(
Boolean
accurateMatch
)
{
return
conditionName
;
this
.
accurateMatch
=
accurateMatch
;
}
}
public
void
setConditionName
(
String
conditionName
)
{
public
Premise
(
String
conditionName
,
String
cmpType
,
String
operator
,
String
keyword
,
Boolean
accurateMatch
)
{
this
.
conditionName
=
conditionName
;
}
this
.
conditionName
=
conditionName
;
this
.
cmpType
=
cmpType
;
public
String
getCmpType
()
{
this
.
operator
=
operator
;
return
cmpType
;
this
.
keyword
=
keyword
;
}
this
.
accurateMatch
=
accurateMatch
;
public
void
setCmpType
(
String
cmpType
)
{
if
(
cmpType
==
null
){
this
.
cmpType
=
cmpType
;
this
.
cmpType
=
"match"
;
}
}
else
{
this
.
cmpType
=
cmpType
;
public
String
getOperator
()
{
}
return
operator
;
}
if
(
operator
==
null
){
this
.
operator
=
"Include"
;
public
void
setOperator
(
String
operator
)
{
}
else
{
this
.
operator
=
operator
;
this
.
operator
=
operator
;
}
}
if
(
cmpType
.
equals
(
"any"
)){
public
String
getKeyword
()
{
this
.
operator
=
"Include"
;
return
keyword
;
}
}
if
(
accurateMatch
==
null
)
{
public
void
setKeyword
(
String
keyword
)
{
this
.
accurateMatch
=
false
;
this
.
keyword
=
keyword
;
}
}
}
}
public
Premise
(
String
conditionName
,
String
cmpType
,
String
operator
,
String
keyword
)
{
this
.
conditionName
=
conditionName
;
this
.
cmpType
=
cmpType
;
this
.
operator
=
operator
;
this
.
keyword
=
keyword
;
this
.
accurateMatch
=
false
;
if
(
cmpType
==
null
){
this
.
cmpType
=
"match"
;
}
else
{
this
.
cmpType
=
cmpType
;
}
if
(
operator
==
null
){
this
.
operator
=
"Include"
;
}
else
{
this
.
operator
=
operator
;
}
if
(
cmpType
.
equals
(
"any"
)){
this
.
operator
=
"Include"
;
}
}
public
String
getConditionName
()
{
return
conditionName
;
}
public
void
setConditionName
(
String
conditionName
)
{
this
.
conditionName
=
conditionName
;
}
public
String
getCmpType
()
{
return
cmpType
;
}
public
void
setCmpType
(
String
cmpType
)
{
this
.
cmpType
=
cmpType
;
}
public
String
getOperator
()
{
return
operator
;
}
public
void
setOperator
(
String
operator
)
{
this
.
operator
=
operator
;
}
public
String
getKeyword
()
{
return
keyword
;
}
public
void
setKeyword
(
String
keyword
)
{
this
.
keyword
=
keyword
;
}
public
void
setAccurateName
()
{
this
.
conditionName
=
this
.
conditionName
+
"_indep"
;
}
}
src/main/java/com/qiwu/chatbotbackend/gameDesign/ListeningConstructor.java
View file @
6321ac3c
package
com
.
qiwu
.
chatbotbackend
.
gameDesign
;
package
com
.
qiwu
.
chatbotbackend
.
gameDesign
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.qiwu.chatbotbackend.db.SqlHelper
;
import
com.qiwu.chatbotbackend.db.SqlHelper
;
import
com.qiwu.chatbotbackend.entity.ConfigTermText
;
import
com.qiwu.chatbotbackend.entity.ConfigTermText
;
import
com.qiwu.chatbotbackend.entity.Premise
;
import
com.qiwu.chatbotbackend.entity.Premise
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
java.util.*
;
import
java.util.*
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.*;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.*;
public
class
ListeningConstructor
extends
ElementConstructor
{
public
class
ListeningConstructor
extends
ElementConstructor
{
public
ListeningConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
ListeningConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
keywordMap
=
keywordMap
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
public
void
construct
(
JSONObject
jsonObject
,
UserInfo
userinfo
)
{
public
void
construct
(
JSONObject
jsonObject
,
UserInfo
userinfo
)
{
}
}
public
static
void
cc
(
String
botAccount
,
JSONObject
gameELments
,
HashMap
<
String
,
JSONObject
>
plotIndex
,
List
<
ConfigTermText
>
configTermTextList
){
public
static
void
cc
(
String
botAccount
,
JSONObject
gameELments
,
HashMap
<
String
,
JSONObject
>
plotIndex
,
List
<
ConfigTermText
>
configTermTextList
){
int
size
=
0
;
int
size
=
0
;
String
feature
,
nextPlotId
,
reply
=
""
,
nextCondition
=
""
,
nextLocation
=
""
,
priority
;
String
feature
,
nextPlotId
,
reply
=
""
,
nextCondition
=
""
,
nextLocation
=
""
,
priority
;
String
nTaskLineName
,
lastTaskCondition
,
lastTaskReply
,
nextGameStep
;
String
nTaskLineName
,
lastTaskCondition
,
lastTaskReply
,
nextGameStep
;
Boolean
autoJump
=
false
;
Boolean
autoJump
=
false
;
List
<
Premise
>
curPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
curPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
hisPremiseList
=
new
ArrayList
<
Premise
>();
List
<
Premise
>
hisPremiseList
=
new
ArrayList
<
Premise
>();
JSONArray
listeningActions
=
gameELments
.
getJSONArray
(
"listeningActions"
);
JSONArray
listeningActions
=
gameELments
.
getJSONArray
(
"listeningActions"
);
JSONObject
plotNode
=
null
;
JSONObject
plotNode
=
null
;
if
(
listeningActions
==
null
)
if
(
listeningActions
==
null
)
return
;
return
;
size
=
listeningActions
.
size
();
size
=
listeningActions
.
size
();
JSONObject
config
=
null
;
JSONObject
config
=
null
;
for
(
int
i
=
0
;
i
<
size
;
i
++){
for
(
int
i
=
0
;
i
<
size
;
i
++){
plotNode
=
null
;
plotNode
=
null
;
autoJump
=
false
;
autoJump
=
false
;
priority
=
"2"
;
priority
=
"2"
;
feature
=
"match"
;
feature
=
"match"
;
config
=
listeningActions
.
getJSONObject
(
i
);
config
=
listeningActions
.
getJSONObject
(
i
);
curPremiseList
=
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"curPremise"
).
toJSONString
(),
Premise
.
class
);
curPremiseList
=
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"curPremise"
).
toJSONString
(),
Premise
.
class
);
hisPremiseList
=
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"hisPremise"
).
toJSONString
(),
Premise
.
class
);
hisPremiseList
=
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"hisPremise"
).
toJSONString
(),
Premise
.
class
);
Map
<
String
,
String
>
updateKnowledge
=
JSONObject
.
parseObject
(
config
.
getJSONObject
(
"updateKnowledge"
).
toJSONString
(),
Map
.
class
);
Map
<
String
,
String
>
updateKnowledge
=
JSONObject
.
parseObject
(
config
.
getJSONObject
(
"updateKnowledge"
).
toJSONString
(),
Map
.
class
);
nextPlotId
=
config
.
getString
(
"nextPlotId"
);
nextPlotId
=
config
.
getString
(
"nextPlotId"
);
if
(
nextPlotId
!=
null
){
if
(
nextPlotId
!=
null
){
plotNode
=
plotIndex
.
get
(
nextPlotId
);
plotNode
=
plotIndex
.
get
(
nextPlotId
);
}
}
if
(
plotNode
!=
null
){
if
(
plotNode
!=
null
){
reply
=
plotNode
.
getString
(
"plotText"
);
reply
=
plotNode
.
getString
(
"plotText"
);
nextCondition
=
plotNode
.
getString
(
"conditionName"
);
nextCondition
=
plotNode
.
getString
(
"conditionName"
);
nextLocation
=
plotNode
.
getString
(
"place"
);
nextLocation
=
plotNode
.
getString
(
"place"
);
autoJump
=
plotNode
.
getBoolean
(
"autoJump"
);
autoJump
=
plotNode
.
getBoolean
(
"autoJump"
);
if
(
nextCondition
==
null
||
nextCondition
.
equals
(
""
)){
if
(
nextCondition
==
null
||
nextCondition
.
equals
(
""
)){
nextCondition
=
DEFAULT_CONDITION
;
nextCondition
=
DEFAULT_CONDITION
;
}
}
if
(
autoJump
){
if
(
autoJump
){
feature
=
"match,activate:after"
;
feature
=
"match,activate:after"
;
updateKnowledge
.
put
(
"plot_jump_text"
,
"str+"
+
reply
);
updateKnowledge
.
put
(
"plot_jump_text"
,
"str+"
+
reply
);
nextCondition
=
"plot_"
+
nextPlotId
;
nextCondition
=
"plot_"
+
nextPlotId
;
reply
=
""
;
reply
=
""
;
}
else
{
}
else
{
feature
=
"match"
;
feature
=
"match"
;
}
}
if
(
config
.
getString
(
"priority"
)
!=
null
)
if
(
config
.
getString
(
"priority"
)
!=
null
)
priority
=
config
.
getString
(
"priority"
);
priority
=
config
.
getString
(
"priority"
);
updateKnowledge
.
put
(
nextLocation
+
"_activate_by"
,
""
);
updateKnowledge
.
put
(
nextLocation
+
"_activate_by"
,
""
);
updateKnowledge
.
put
(
nextLocation
+
"_activate_ready"
,
"0"
);
updateKnowledge
.
put
(
nextLocation
+
"_activate_ready"
,
"0"
);
updateKnowledge
.
put
(
"site"
,
nextLocation
);
updateKnowledge
.
put
(
"site"
,
nextLocation
);
nTaskLineName
=
String
.
format
(
TASK_LINE
,
nextLocation
);
nTaskLineName
=
String
.
format
(
TASK_LINE
,
nextLocation
);
//任务线最后一个condition
//任务线最后一个condition
lastTaskCondition
=
String
.
format
(
TASK_CONDITION
,
nextLocation
);
lastTaskCondition
=
String
.
format
(
TASK_CONDITION
,
nextLocation
);
lastTaskReply
=
String
.
format
(
TASK_REPLY
,
nextLocation
);
lastTaskReply
=
String
.
format
(
TASK_REPLY
,
nextLocation
);
nextGameStep
=
String
.
format
(
GAME_STEP_FORMAT
,
botAccount
,
nextPlotId
);
nextGameStep
=
String
.
format
(
GAME_STEP_FORMAT
,
botAccount
,
nextPlotId
);
updateKnowledge
.
put
(
lastTaskCondition
,
nextCondition
);
updateKnowledge
.
put
(
lastTaskCondition
,
nextCondition
);
updateKnowledge
.
put
(
lastTaskReply
,
reply
);
updateKnowledge
.
put
(
lastTaskReply
,
reply
);
updateKnowledge
.
put
(
nextPlotId
,
"1"
);
//下一步设为1
updateKnowledge
.
put
(
nextPlotId
,
"1"
);
//下一步设为1
updateKnowledge
.
put
(
nTaskLineName
,
nextGameStep
);
updateKnowledge
.
put
(
nTaskLineName
,
nextGameStep
);
updateKnowledge
.
put
(
"game_step"
,
nextGameStep
);
updateKnowledge
.
put
(
"game_step"
,
nextGameStep
);
}
else
{
}
else
{
feature
=
"match,return-0"
;
feature
=
"match,return-0"
;
}
}
ConfigTermText
configTermText
=
new
ConfigTermText
(
Map
<
String
,
Integer
>
gNameCount
=
new
HashMap
<
String
,
Integer
>();
curPremiseList
,
hisPremiseList
,
ConfigTermText
configTermText
=
new
ConfigTermText
(
updateKnowledge
,
curPremiseList
,
""
,
""
,
""
,
feature
,
reply
,
nextCondition
,
priority
hisPremiseList
,
);
updateKnowledge
,
""
,
""
,
""
,
feature
,
reply
,
nextCondition
,
priority
,
gNameCount
// System.out.println("生成:" + curPremiseList.get(0));
);
configTermTextList
.
add
(
configTermText
);
}
// System.out.println("生成:" + curPremiseList.get(0));
}
configTermTextList
.
add
(
configTermText
);
}
}
}
}
src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java
View file @
6321ac3c
...
@@ -220,6 +220,9 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -220,6 +220,9 @@ public class PlotConstructor2 extends ElementConstructor {
int
branchSize
;
int
branchSize
;
List
<
Premise
>
curPremiseList
,
historyPremiseList
;
List
<
Premise
>
curPremiseList
,
historyPremiseList
;
//condition name 计数
Map
<
String
,
Integer
>
gNameCount
=
new
HashMap
<
String
,
Integer
>();
//设置初始化unknown文本
//设置初始化unknown文本
...
@@ -487,16 +490,12 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -487,16 +490,12 @@ public class PlotConstructor2 extends ElementConstructor {
}
}
//下一部剧情在不同地点时,为了防止到配置文件重复执行,需要加一个标志表示下一步剧情是否已经发生过
//下一部剧情在不同地点时,为了防止到配置文件重复执行,需要加一个标志表示下一步剧情是否已经发生过
// activate_by 下一个地点的剧情是由当前剧情激活的
// activate_by 下一个地点的剧情是由当前剧情激活的
//_activate_ready 下一个地点的剧情等待被激活
//_activate_ready 下一个地点的剧情等待被激活
appendKnowledge
(
extraUK
,
nextLocation
+
"_activate_by"
,
id
);
appendKnowledge
(
extraUK
,
nextLocation
+
"_activate_by"
,
id
);
appendKnowledge
(
extraUK
,
nextLocation
+
"_activate_ready"
,
"1"
);
appendKnowledge
(
extraUK
,
nextLocation
+
"_activate_ready"
,
"1"
);
// 如果不能直接到达所在地点,说明剧情1-1和1-2直接存在一个中间结点,这些更新操作会放在中间结点执行(动态生成,方法名:arriveActivatePlot2 这个中间结点会被当做一个监听剧情来处理)
// 如果不能直接到达所在地点,说明剧情1-1和1-2直接存在一个中间结点,这些更新操作会放在中间结点执行(动态生成,方法名:arriveActivatePlot2 这个中间结点会被当做一个监听剧情来处理)
arriveActivatePlot2
(
jsonObject
,
id
,
nextId
,
nextLocation
);
arriveActivatePlot2
(
jsonObject
,
id
,
nextId
,
nextLocation
);
...
@@ -506,13 +505,12 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -506,13 +505,12 @@ public class PlotConstructor2 extends ElementConstructor {
}
}
}
}
//System.out.println(branchNode);
//取出作者设定的剧情条件
//取出作者设定的剧情条件
curPremiseList
=
JSONArray
.
parseArray
(
branchNode
.
getJSONArray
(
"curPremise"
).
toJSONString
(),
Premise
.
class
);
curPremiseList
=
JSONArray
.
parseArray
(
branchNode
.
getJSONArray
(
"curPremise"
).
toJSONString
(),
Premise
.
class
);
historyPremiseList
=
JSONArray
.
parseArray
(
branchNode
.
getJSONArray
(
"hisPremise"
).
toJSONString
(),
Premise
.
class
);
historyPremiseList
=
JSONArray
.
parseArray
(
branchNode
.
getJSONArray
(
"hisPremise"
).
toJSONString
(),
Premise
.
class
);
addContext
(
curPremiseList
,
node
.
getString
(
"id"
),
i
);
addContext
(
historyPremiseList
,
node
.
getString
(
"id"
),
i
);
//是否将当前识别到的数据加入到已知数据列表
//是否将当前识别到的数据加入到已知数据列表
if
((
Boolean
)
branchNode
.
get
(
"includeCurInfo"
)){
if
((
Boolean
)
branchNode
.
get
(
"includeCurInfo"
)){
...
@@ -525,7 +523,6 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -525,7 +523,6 @@ public class PlotConstructor2 extends ElementConstructor {
appendFeature
(
extraFT
,
branchNode
.
getString
(
"extraFeature"
));
appendFeature
(
extraFT
,
branchNode
.
getString
(
"extraFeature"
));
}
}
//如果符合激活下一个剧情配置文件的操作
//如果符合激活下一个剧情配置文件的操作
if
(
doActivatePlot
(
nextAutoJump
,
location
,
nextLocation
,
moveWithPlot
)
){
if
(
doActivatePlot
(
nextAutoJump
,
location
,
nextLocation
,
moveWithPlot
)
){
//在配置文件中添加激活的操作
//在配置文件中添加激活的操作
...
@@ -540,7 +537,7 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -540,7 +537,7 @@ public class PlotConstructor2 extends ElementConstructor {
historyPremiseList
,
historyPremiseList
,
updateKnowledge
,
updateKnowledge
,
""
,
extraHP
.
toString
(),
extraUK
.
toString
(),
""
,
extraHP
.
toString
(),
extraUK
.
toString
(),
extraFT
.
toString
(),
reply
,
nextCondition
,
"1"
extraFT
.
toString
(),
reply
,
nextCondition
,
"1"
,
gNameCount
);
);
configTermText
.
setConfigName
(
"plot_"
+
id
,
false
);
configTermText
.
setConfigName
(
"plot_"
+
id
,
false
);
...
@@ -569,8 +566,6 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -569,8 +566,6 @@ public class PlotConstructor2 extends ElementConstructor {
configTermText
.
setAuxiliaryPriority
(
"3"
);
configTermText
.
setAuxiliaryPriority
(
"3"
);
configTermTextList
.
add
(
configTermText
);
configTermTextList
.
add
(
configTermText
);
//将子结点加入队列
//将子结点加入队列
adjId
=
nextId
;
adjId
=
nextId
;
plotEnQueue
(
queue
,
id
,
adjId
,
nextUnknownText
,
curAutoJump
);
plotEnQueue
(
queue
,
id
,
adjId
,
nextUnknownText
,
curAutoJump
);
...
@@ -585,19 +580,8 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -585,19 +580,8 @@ public class PlotConstructor2 extends ElementConstructor {
extraUK
.
setLength
(
0
);
extraUK
.
setLength
(
0
);
skipText
.
setLength
(
0
);
skipText
.
setLength
(
0
);
arriveUK
.
setLength
(
0
);
arriveUK
.
setLength
(
0
);
}
}
}
}
/**
/**
* ----------------------------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------------------------
* 剧情不设条件时的处理
* 剧情不设条件时的处理
...
@@ -923,10 +907,10 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -923,10 +907,10 @@ public class PlotConstructor2 extends ElementConstructor {
//激活下一步剧情的几个条件:1. condition 到沙滩 2. 沙滩_activate_by 沙滩的剧情是有当前剧情激活的 3. 沙滩的剧情处于等待激活的状态 4. 当前地点和沙滩地点相邻或可以直接到达
//激活下一步剧情的几个条件:1. condition 到沙滩 2. 沙滩_activate_by 沙滩的剧情是有当前剧情激活的 3. 沙滩的剧情处于等待激活的状态 4. 当前地点和沙滩地点相邻或可以直接到达
// 2.3 两个条件是特意加的
// 2.3 两个条件是特意加的
curPremiseList
.
add
(
new
Premise
(
GOTO_CONDITION
,
"match"
,
"Include"
,
nextLocation
));
curPremiseList
.
add
(
new
Premise
(
GOTO_CONDITION
,
"match"
,
"Include"
,
nextLocation
,
false
));
hisPremiseList
.
add
(
new
Premise
(
nextLocation
+
"_activate_by"
,
"match"
,
"Include"
,
plotId
));
hisPremiseList
.
add
(
new
Premise
(
nextLocation
+
"_activate_by"
,
"match"
,
"Include"
,
plotId
,
false
));
hisPremiseList
.
add
(
new
Premise
(
nextLocation
+
"_activate_ready"
,
"match"
,
"Include"
,
"1"
));
hisPremiseList
.
add
(
new
Premise
(
nextLocation
+
"_activate_ready"
,
"match"
,
"Include"
,
"1"
,
false
));
hisPremiseList
.
add
(
new
Premise
(
"isNeighbour:"
+
GOTO_CONDITION
,
"match"
,
"Include"
,
"1+3+4"
));
hisPremiseList
.
add
(
new
Premise
(
"isNeighbour:"
+
GOTO_CONDITION
,
"match"
,
"Include"
,
"1+3+4"
,
false
));
//无匹配次数清零
//无匹配次数清零
...
@@ -1003,20 +987,26 @@ public class PlotConstructor2 extends ElementConstructor {
...
@@ -1003,20 +987,26 @@ public class PlotConstructor2 extends ElementConstructor {
}
}
private
ConfigTermText
createTermExtra2
(
ConfigTermText
term
)
{
private
ConfigTermText
createTermExtra2
(
ConfigTermText
term
)
{
String
hPremise
=
"qa_score::number-Smaller=98"
;
String
hPremise
=
"qa_score::number-Smaller=98"
;
String
featureStr
=
"match"
;
// String featureStr = ",match,includeCurInfo,activate:after";
String
nextStr
=
" "
;
String
configName
=
term
.
getConfigName
()+
"_qa2"
;
String
configName
=
term
.
getConfigName
()+
"_qa2"
;
if
(
term
.
getFeature
().
indexOf
(
"activate"
)
!=
-
1
)
{
String
nextStr
=
term
.
getNextStep
();
nextStr
=
term
.
getNextStep
()
+
","
+
nextStr
;
}
ConfigTermText
newTerm
=
(
ConfigTermText
)
term
.
clone
();
ConfigTermText
newTerm
=
(
ConfigTermText
)
term
.
clone
();
newTerm
.
setHisPremise
(
hPremise
);
newTerm
.
setHisPremise
(
hPremise
);
newTerm
.
setConfigName
(
configName
,
false
);
newTerm
.
setConfigName
(
configName
,
false
);
newTerm
.
setFeature
(
featureStr
);
//
newTerm.setFeature(featureStr);
newTerm
.
setNextStep
(
nextStr
);
newTerm
.
setNextStep
(
nextStr
);
newTerm
.
setStatus
(
"sleeping"
);
newTerm
.
setStatus
(
"sleeping"
);
//newTerm.setReply("");
return
newTerm
;
return
newTerm
;
}
}
private
void
addContext
(
List
<
Premise
>
premises
,
String
plot
,
int
branch
)
{
for
(
Premise
pre
:
premises
)
{
pre
.
setPlot
(
plot
);
pre
.
setBranch
(
branch
);
}
}
}
}
参数和接口文档/功能文档.docx
deleted
100644 → 0
View file @
947af96a
File deleted
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