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
04bd4be9
Commit
04bd4be9
authored
Apr 23, 2019
by
赵国君
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
殷勤穿过来的表单,你我替换
parent
3e9933cf
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
35 deletions
+66
-35
EngineUtils.java
...om/qiwu/chatbotbackend/actiongenerate/DB/EngineUtils.java
+19
-0
ActionUtils.java
...qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
+16
-6
SimpleUtil.java
...n/java/com/qiwu/chatbotbackend/processing/SimpleUtil.java
+2
-0
GetAnswerServlet.java
...ava/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java
+22
-19
BasicBotUtil.java
...java/com/qiwu/chatbotbackend/task/utils/BasicBotUtil.java
+6
-9
GameBotUtil.java
.../java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java
+1
-1
No files found.
src/main/java/com/qiwu/chatbotbackend/actiongenerate/DB/EngineUtils.java
View file @
04bd4be9
...
@@ -178,7 +178,26 @@ public class EngineUtils {
...
@@ -178,7 +178,26 @@ public class EngineUtils {
return
botAccount
;
return
botAccount
;
}
}
public
String
queryBotNickNameByName
(
String
userName
){
String
sql
=
"select nickname from users where username= ?"
;
String
nickname
=
""
;
try
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
ps
.
setString
(
1
,
userName
);
ResultSet
rs
=
ps
.
executeQuery
();
if
(
rs
.
next
())
nickname
=
rs
.
getString
(
"nickname"
);
ps
.
close
();
rs
.
close
();
conn
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
nickname
;
}
...
...
src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
View file @
04bd4be9
...
@@ -847,18 +847,18 @@ public class ActionUtils {
...
@@ -847,18 +847,18 @@ public class ActionUtils {
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_tail"
,
new
HashSet
<
String
>());
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_tail"
,
new
HashSet
<
String
>());
String
condTemple
=
patternConditionJson
.
toJSONString
();
String
condTemple
=
patternConditionJson
.
toJSONString
();
for
(
int
i
=
0
;
i
<
100
;
i
++){
int
i
=
0
;
boolean
beEnd
=
false
;
while
(
true
)
{
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
if
(
i
==
0
)
if
(
i
==
0
)
postfix
=
""
;
postfix
=
""
;
else
else
postfix
=
"_"
+
String
.
valueOf
(
i
);
postfix
=
"_"
+
String
.
valueOf
(
i
);
activeFlag
=
"0"
;
conditionJson
=
(
JSONObject
)
JSON
.
parse
(
condTemple
);
conditionJson
=
(
JSONObject
)
JSON
.
parse
(
condTemple
);
// conditionJson = (JSONObject) patternConditionJson.clone(
);
String
originName
=
conditionJson
.
getString
(
"conditionName"
);
conditionName
=
conditionJson
.
getString
(
"conditionName"
)
+
postfix
;
conditionName
=
originName
+
postfix
;
conditionName2
=
conditionName
+
"_indep"
;
conditionName2
=
conditionName
+
"_indep"
;
if
(
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
))
{
if
(
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
))
{
...
@@ -868,13 +868,20 @@ public class ActionUtils {
...
@@ -868,13 +868,20 @@ public class ActionUtils {
conditionJson
.
put
(
"conditionName"
,
conditionName2
);
conditionJson
.
put
(
"conditionName"
,
conditionName2
);
conditionAppendKeyword2
(
conditionName2
,
conditionJson
,
conditionExtraKeywords
,
macroAppendMap
);
conditionAppendKeyword2
(
conditionName2
,
conditionJson
,
conditionExtraKeywords
,
macroAppendMap
);
conditionName
=
conditionName2
;
conditionName
=
conditionName2
;
}
else
{
}
else
if
(
i
>
1
&&
!
conditionExtraKeywords
.
containsKey
(
originName
+
"_tail"
))
{
conditionName
=
originName
;
beEnd
=
true
;
}
else
if
(
i
==
0
)
{
++
i
;
continue
;
continue
;
}
else
{
break
;
}
}
if
(
conditionJson
.
getBoolean
(
"active"
)
&&
!
conditionName
.
equals
(
startCondition
))
if
(
conditionJson
.
getBoolean
(
"active"
)
&&
!
conditionName
.
equals
(
startCondition
))
conditionJson
.
put
(
"active"
,
false
);
conditionJson
.
put
(
"active"
,
false
);
activeFlag
=
"0"
;
actionText
=
generateSingleActionText
(
conditionName
,
conditionJson
);
actionText
=
generateSingleActionText
(
conditionName
,
conditionJson
);
if
(
startCondition
.
equals
(
conditionName
))
{
if
(
startCondition
.
equals
(
conditionName
))
{
conditionJson
.
put
(
"active"
,
true
);
conditionJson
.
put
(
"active"
,
true
);
...
@@ -894,6 +901,9 @@ public class ActionUtils {
...
@@ -894,6 +901,9 @@ public class ActionUtils {
add
(
finalRelationName
);
add
(
finalRelationName
);
}
}
});
});
++
i
;
if
(
beEnd
==
true
)
break
;
}
}
}
}
parameters
.
put
(
"conditionData"
,
conditionData
);
parameters
.
put
(
"conditionData"
,
conditionData
);
...
...
src/main/java/com/qiwu/chatbotbackend/processing/SimpleUtil.java
View file @
04bd4be9
...
@@ -203,6 +203,8 @@ public class SimpleUtil {
...
@@ -203,6 +203,8 @@ public class SimpleUtil {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
jobj
.
put
(
"status_code"
,
0
);
jobj
.
put
(
"status_code"
,
0
);
jobj
.
put
(
"post_status"
,
0
);
jobj
.
put
(
"post_status"
,
0
);
System
.
out
.
println
(
"respContent:"
);
System
.
out
.
println
(
respContent
);
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
src/main/java/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java
View file @
04bd4be9
...
@@ -20,6 +20,8 @@ import java.io.OutputStream;
...
@@ -20,6 +20,8 @@ import java.io.OutputStream;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.*;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.*;
import
static
com
.
qiwu
.
chatbotbackend
.
processing
.
ChatCacheController
.
COMBINE_PUNC2
;
import
static
com
.
qiwu
.
chatbotbackend
.
processing
.
ChatCacheController
.
COMBINE_PUNC2
;
...
@@ -30,28 +32,37 @@ public class GetAnswerServlet extends HttpServlet {
...
@@ -30,28 +32,37 @@ public class GetAnswerServlet extends HttpServlet {
/**
/**
* GetAnswerServlet就是处理post请求并返回答案的入口
* GetAnswerServlet就是处理post请求并返回答案的入口
*/
*/
//String LOG_PATH = "/home/hxw/source/logs/";
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
request
.
setCharacterEncoding
(
"UTF-8"
);
request
.
setCharacterEncoding
(
"UTF-8"
);
Map
<
String
,
String
[]>
receiveParamters
=
new
HashMap
<>(
request
.
getParameterMap
());
Map
<
String
,
String
[]>
requestParamters
=
new
HashMap
<>(
request
.
getParameterMap
());
Map
<
String
,
String
>
curInfoPoint
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
receiveParamters
=
new
HashMap
<>();
Set
<
Entry
<
String
,
String
[]>>
entrySet
=
requestParamters
.
entrySet
();
String
tmpStr
;
for
(
Map
.
Entry
<
String
,
String
[]>
entry
:
entrySet
)
{
if
(
entry
.
getValue
().
length
>
0
)
{
tmpStr
=
entry
.
getValue
()[
0
];
if
(
tmpStr
==
null
||
tmpStr
.
equals
(
""
))
continue
;
tmpStr
=
tmpStr
.
replace
(
"qiwu"
,
"我"
);
//tmpStr = tmpStr.replace("qiwu", "你");
receiveParamters
.
put
(
entry
.
getKey
(),
tmpStr
);
}
}
String
botName
=
receiveParamters
.
get
(
"bot_name"
);
Map
<
String
,
String
>
curInfoPoint
=
new
HashMap
<
String
,
String
>();
Solution
bestMatch
=
null
;
Solution
bestMatch
=
null
;
BasicBotUtil
botUtil
=
null
;
BasicBotUtil
botUtil
=
null
;
Action
ansAction
=
null
;
Action
ansAction
=
null
;
boolean
debugFlag
=
false
;
boolean
debugFlag
=
false
;
String
ansJ
=
""
,
return_str
=
""
,
state
=
""
,
chatKey
=
""
,
botType
=
""
,
userKey
=
""
,
randKey
=
""
;
String
ansJ
=
""
,
return_str
=
""
,
state
=
""
,
chatKey
=
""
,
botType
=
""
,
userKey
=
""
,
randKey
=
""
;
String
botName
=
receiveParamters
.
get
(
"bot_name"
)[
0
];
OutputStream
out
=
response
.
getOutputStream
();
OutputStream
out
=
response
.
getOutputStream
();
ServletContext
context
=
this
.
getServletContext
();
ServletContext
context
=
this
.
getServletContext
();
//如果有client_id,会用@分隔
//如果有client_id,会用@分隔
chatKey
=
receiveParamters
.
get
(
"chat_key"
)
[
0
]
;
chatKey
=
receiveParamters
.
get
(
"chat_key"
);
String
chatKeys
[]
=
receiveParamters
.
get
(
"chat_key"
)
[
0
]
.
split
(
COMBINE_PUNC2
);
String
chatKeys
[]
=
receiveParamters
.
get
(
"chat_key"
).
split
(
COMBINE_PUNC2
);
if
(
chatKeys
.
length
==
1
){
if
(
chatKeys
.
length
==
1
){
userKey
=
chatKeys
[
0
];
userKey
=
chatKeys
[
0
];
randKey
=
chatKeys
[
0
];
randKey
=
chatKeys
[
0
];
...
@@ -60,23 +71,19 @@ public class GetAnswerServlet extends HttpServlet {
...
@@ -60,23 +71,19 @@ public class GetAnswerServlet extends HttpServlet {
randKey
=
chatKeys
[
1
];
randKey
=
chatKeys
[
1
];
}
}
receiveParamters
.
put
(
"userKey"
,
new
String
[]{
userKey
});
receiveParamters
.
put
(
"userKey"
,
userKey
);
receiveParamters
.
put
(
"randKey"
,
new
String
[]{
randKey
});
receiveParamters
.
put
(
"randKey"
,
randKey
);
try
{
try
{
LogWriter
logWriter
=
new
LogWriter
(
LOG_PATH
,
chatKey
);
LogWriter
logWriter
=
new
LogWriter
(
LOG_PATH
,
chatKey
);
UserInfo
userinfo
=
null
;
UserInfo
userinfo
=
null
;
UserInfoController
uiController
=
new
UserInfoController
();
UserInfoController
uiController
=
new
UserInfoController
();
logWriter
.
record
(
"query bot config"
,
0
);
logWriter
.
record
(
"query bot config"
,
0
);
userinfo
=
uiController
.
userInfoQuery
(
request
.
getParameter
(
"bot_name"
),
context
);
userinfo
=
uiController
.
userInfoQuery
(
request
.
getParameter
(
"bot_name"
),
context
);
if
(
userinfo
!=
null
)
{
if
(
userinfo
!=
null
)
{
//获得用户历史信息
//获得用户历史信息
ChatCache
chatCache
=
null
;
ChatCache
chatCache
=
null
;
...
@@ -97,15 +104,11 @@ public class GetAnswerServlet extends HttpServlet {
...
@@ -97,15 +104,11 @@ public class GetAnswerServlet extends HttpServlet {
throw
(
new
Exception
(
"chatCache初始化失败"
));
throw
(
new
Exception
(
"chatCache初始化失败"
));
}
}
/**
/**
* 如果读档成功,则返回存档前的状态(包括最后一个condition和最后的回答)
* 如果读档成功,则返回存档前的状态(包括最后一个condition和最后的回答)
* 如果读档失败,则开始新的游戏,读档失败的判断标准是除了初始化数据外没有其他任何数据
* 如果读档失败,则开始新的游戏,读档失败的判断标准是除了初始化数据外没有其他任何数据
*/
*/
//historyInfoPoint = chatCache.getInfoPoint();
switch
(
botType
)
{
switch
(
botType
)
{
case
"game"
:
case
"game"
:
WorldController
worldController
=
new
WorldController
(
logWriter
,
userinfo
);
WorldController
worldController
=
new
WorldController
(
logWriter
,
userinfo
);
...
...
src/main/java/com/qiwu/chatbotbackend/task/utils/BasicBotUtil.java
View file @
04bd4be9
...
@@ -35,7 +35,7 @@ public class BasicBotUtil {
...
@@ -35,7 +35,7 @@ public class BasicBotUtil {
this
.
chatCache
=
chatCache
;
this
.
chatCache
=
chatCache
;
}
}
public
boolean
preprocessing
(
Map
<
String
,
String
[]
>
receiveParameters
,
ServletContext
context
)
throws
IOException
{
public
boolean
preprocessing
(
Map
<
String
,
String
>
receiveParameters
,
ServletContext
context
)
throws
IOException
{
return
infoPointPreprocessing
(
receiveParameters
,
context
,
true
);
return
infoPointPreprocessing
(
receiveParameters
,
context
,
true
);
...
@@ -51,7 +51,7 @@ public class BasicBotUtil {
...
@@ -51,7 +51,7 @@ public class BasicBotUtil {
* @return
* @return
* @throws IOException
* @throws IOException
*/
*/
public
boolean
infoPointPreprocessing
(
Map
<
String
,
String
[]
>
receiveParameters
,
ServletContext
context
,
Boolean
setUnknown
)
throws
IOException
{
public
boolean
infoPointPreprocessing
(
Map
<
String
,
String
>
receiveParameters
,
ServletContext
context
,
Boolean
setUnknown
)
throws
IOException
{
String
return_str
=
""
,
k
,
botType
=
""
;
String
return_str
=
""
,
k
,
botType
=
""
;
String
receiveParameterStr
=
""
;
String
receiveParameterStr
=
""
;
...
@@ -75,18 +75,15 @@ public class BasicBotUtil {
...
@@ -75,18 +75,15 @@ public class BasicBotUtil {
receiveParameterStr
+=
"-----------------------------------------识别数据列表-------------------------------------------<br>"
;
receiveParameterStr
+=
"-----------------------------------------识别数据列表-------------------------------------------<br>"
;
while
(
iit
.
hasNext
())
{
while
(
iit
.
hasNext
())
{
k
=
iit
.
next
();
k
=
iit
.
next
();
//
receiveParameterStr
+=
k
+
": "
;
receiveParameterStr
+=
k
+
": "
;
curInfoPoint
.
put
(
k
,
receiveParameters
.
get
(
k
)
[
0
]
);
curInfoPoint
.
put
(
k
,
receiveParameters
.
get
(
k
));
if
(
k
.
equals
(
"debug_mode"
)
||
k
.
equals
(
"debug_rule"
))
if
(
k
.
equals
(
"debug_mode"
)
||
k
.
equals
(
"debug_rule"
))
debugFlag
=
true
;
debugFlag
=
true
;
String
values
[]
=
receiveParameters
.
get
(
k
);
String
values
=
receiveParameters
.
get
(
k
);
receiveParameterStr
+=
values
+
" "
+
"<br>"
;
receiveParameterStr
+=
values
[
0
]
+
" "
+
"<br>"
;
if
(
values
.
equals
(
":"
))
{
if
(
values
[
0
].
equals
(
":"
))
{
curInfoPoint
.
put
(
k
,
""
);
curInfoPoint
.
put
(
k
,
""
);
}
}
}
}
...
...
src/main/java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java
View file @
04bd4be9
...
@@ -44,7 +44,7 @@ public class GameBotUtil extends BasicBotUtil{
...
@@ -44,7 +44,7 @@ public class GameBotUtil extends BasicBotUtil{
* @throws IOException
* @throws IOException
*/
*/
@Override
@Override
public
boolean
preprocessing
(
Map
<
String
,
String
[]
>
receiveParameters
,
ServletContext
context
)
throws
IOException
{
public
boolean
preprocessing
(
Map
<
String
,
String
>
receiveParameters
,
ServletContext
context
)
throws
IOException
{
Boolean
debugFlag
=
super
.
infoPointPreprocessing
(
receiveParameters
,
context
,
false
);
Boolean
debugFlag
=
super
.
infoPointPreprocessing
(
receiveParameters
,
context
,
false
);
//将要去的地点的别名替换为真名
//将要去的地点的别名替换为真名
...
...
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