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
bccbf33e
Commit
bccbf33e
authored
Apr 18, 2019
by
hxw2303632
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of 192.168.1.81:hxw2303632/webapp
parents
b8c7ebf6
0e6d2062
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
471 additions
and
439 deletions
+471
-439
ActionParser.java
...iwu/chatbotbackend/actiongenerate/utils/ActionParser.java
+130
-129
ActionUtils.java
...qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
+12
-15
ConfigTermText.java
...n/java/com/qiwu/chatbotbackend/entity/ConfigTermText.java
+9
-6
Premise.java
src/main/java/com/qiwu/chatbotbackend/entity/Premise.java
+0
-3
ElementConstructor.java
...om/qiwu/chatbotbackend/gameDesign/ElementConstructor.java
+42
-7
PlotConstructor2.java
.../com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java
+10
-11
FormsPoster.java
.../java/com/qiwu/chatbotbackend/processing/FormsPoster.java
+268
-268
No files found.
src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionParser.java
View file @
bccbf33e
package
com
.
qiwu
.
chatbotbackend
.
actiongenerate
.
utils
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.Arrays
;
public
class
ActionParser
{
public
static
JSONObject
parse
(
String
actionText
){
String
name
;
JSONObject
action
=
new
JSONObject
();
for
(
String
line:
actionText
.
split
(
"\r\n"
)){
name
=
line
.
trim
().
split
(
"="
)[
0
];
if
(
name
.
equals
(
""
)
||
name
.
equals
(
"#actions"
)){
//
}
else
{
switch
(
name
)
{
case
"name"
:
//parseName(line, action);
break
;
case
"status"
:
parseStatus
(
line
,
action
);
break
;
case
"condition"
:
parseCondition
(
line
,
action
);
break
;
case
"style"
:
parseStyle
(
line
,
action
);
break
;
case
"action"
:
parseAction
(
line
,
action
);
break
;
case
"conflict"
:
break
;
case
"process"
:
break
;
default
:
;
}
}
}
if
(!
action
.
containsKey
(
"styleList"
)){
action
.
put
(
"styleList"
,
new
JSONArray
());
}
return
action
;
}
public
static
void
parseName
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"actionName"
,
elem
[
1
]);
}
public
static
void
parseAction
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"actionType"
,
elem
[
1
]);
}
public
static
void
parseStatus
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"status"
,
elem
[
1
]);
}
public
static
void
parseStyle
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
String
subElem
[]
=
elem
[
1
].
split
(
","
);
action
.
put
(
"styleList"
,
new
JSONArray
(
Arrays
.
asList
(
subElem
)));
}
public
static
void
parseConflict
(
String
text
,
JSONObject
action
){
//
}
public
static
void
parseCondition
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"\\|"
,
4
);
String
condition
=
elem
[
0
];
String
relation
=
elem
[
1
];
String
questionText
=
elem
[
2
];
String
repeatStr
=
elem
[
3
];
String
conditionName
=
""
,
relationList
[],
questionElem
[];
JSONArray
questionList
=
new
JSONArray
();
JSONArray
repeatList
=
new
JSONArray
();
String
conditionElem
[]
=
condition
.
split
(
"="
);
conditionElem
=
conditionElem
[
1
].
split
(
":"
);
action
.
put
(
"conditionName"
,
conditionElem
[
0
]);
if
(
conditionElem
.
length
>=
2
)
action
.
put
(
"dataType"
,
conditionElem
[
1
]);
relationList
=
relation
.
split
(
","
);
action
.
put
(
"relationHead"
,
relationList
[
0
]);
action
.
put
(
"relationName"
,
relationList
[
1
]);
action
.
put
(
"relationTail"
,
relationList
[
2
]);
for
(
String
question:
questionText
.
split
(
"~"
)){
questionElem
=
question
.
split
(
":"
);
JSONObject
iterDict
=
new
JSONObject
();
iterDict
.
put
(
"que_start_time"
,
questionElem
[
0
]);
iterDict
.
put
(
"que_stop_time"
,
questionElem
[
1
]);
iterDict
.
put
(
"que_sen"
,
questionElem
[
2
]);
if
(
questionElem
.
length
==
4
&&
questionElem
[
3
].
equals
(
"base"
))
iterDict
.
put
(
"base"
,
1
);
else
iterDict
.
put
(
"base"
,
0
);
questionList
.
add
(
iterDict
);
}
action
.
put
(
"questionList"
,
questionList
);
for
(
String
repeat:
repeatStr
.
split
(
"~"
)){
JSONObject
repeatDict
=
new
JSONObject
();
elem
=
repeat
.
split
(
"="
,
2
);
repeatDict
.
put
(
"repeatString"
,
elem
[
0
]);
repeatDict
.
put
(
"repeatKeywords"
,
elem
[
1
]);
repeatList
.
add
(
repeatDict
);
}
action
.
put
(
"repeatList"
,
repeatList
);
}
}
package
com
.
qiwu
.
chatbotbackend
.
actiongenerate
.
utils
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.Arrays
;
public
class
ActionParser
{
public
static
JSONObject
parse
(
String
actionText
){
String
name
;
JSONObject
action
=
new
JSONObject
();
for
(
String
line:
actionText
.
split
(
"\r\n"
)){
name
=
line
.
trim
().
split
(
"="
)[
0
];
if
(
name
.
equals
(
""
)
||
name
.
equals
(
"#actions"
)){
//
}
else
{
switch
(
name
)
{
case
"name"
:
//parseName(line, action);
break
;
case
"status"
:
parseStatus
(
line
,
action
);
break
;
case
"condition"
:
parseCondition
(
line
,
action
);
break
;
case
"style"
:
parseStyle
(
line
,
action
);
break
;
case
"action"
:
parseAction
(
line
,
action
);
break
;
case
"conflict"
:
break
;
case
"process"
:
break
;
default
:
;
}
}
}
if
(!
action
.
containsKey
(
"styleList"
)){
action
.
put
(
"styleList"
,
new
JSONArray
());
}
return
action
;
}
public
static
void
parseName
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"actionName"
,
elem
[
1
]);
}
public
static
void
parseAction
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"actionType"
,
elem
[
1
]);
}
public
static
void
parseStatus
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
action
.
put
(
"status"
,
elem
[
1
]);
}
public
static
void
parseStyle
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"="
);
String
subElem
[]
=
elem
[
1
].
split
(
","
);
action
.
put
(
"styleList"
,
new
JSONArray
(
Arrays
.
asList
(
subElem
)));
}
public
static
void
parseConflict
(
String
text
,
JSONObject
action
){
//
}
public
static
void
parseCondition
(
String
text
,
JSONObject
action
){
String
elem
[]
=
text
.
split
(
"\\|"
,
4
);
String
condition
=
elem
[
0
];
String
relation
=
elem
[
1
];
String
questionText
=
elem
[
2
];
String
repeatStr
=
elem
[
3
];
String
conditionName
=
""
,
relationList
[],
questionElem
[];
JSONArray
questionList
=
new
JSONArray
();
JSONArray
repeatList
=
new
JSONArray
();
String
conditionElem
[]
=
condition
.
split
(
"="
);
conditionElem
=
conditionElem
[
1
].
split
(
":"
);
action
.
put
(
"conditionName"
,
conditionElem
[
0
]);
if
(
conditionElem
.
length
>=
2
)
action
.
put
(
"dataType"
,
conditionElem
[
1
]);
relationList
=
relation
.
split
(
","
);
action
.
put
(
"relationHead"
,
relationList
[
0
]);
action
.
put
(
"relationName"
,
relationList
[
1
]);
action
.
put
(
"relationTail"
,
relationList
[
2
]);
for
(
String
question:
questionText
.
split
(
"~"
)){
questionElem
=
question
.
split
(
":"
);
JSONObject
iterDict
=
new
JSONObject
();
iterDict
.
put
(
"que_start_time"
,
questionElem
[
0
]);
iterDict
.
put
(
"que_stop_time"
,
questionElem
[
1
]);
//to-do 数组可能越界,数据不对
iterDict
.
put
(
"que_sen"
,
questionElem
[
2
]);
if
(
questionElem
.
length
==
4
&&
questionElem
[
3
].
equals
(
"base"
))
iterDict
.
put
(
"base"
,
1
);
else
iterDict
.
put
(
"base"
,
0
);
questionList
.
add
(
iterDict
);
}
action
.
put
(
"questionList"
,
questionList
);
for
(
String
repeat:
repeatStr
.
split
(
"~"
)){
JSONObject
repeatDict
=
new
JSONObject
();
elem
=
repeat
.
split
(
"="
,
2
);
repeatDict
.
put
(
"repeatString"
,
elem
[
0
]);
repeatDict
.
put
(
"repeatKeywords"
,
elem
[
1
]);
repeatList
.
add
(
repeatDict
);
}
action
.
put
(
"repeatList"
,
repeatList
);
}
}
src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java
View file @
bccbf33e
...
...
@@ -362,7 +362,7 @@ public class ActionUtils {
conditionJson
=
JSONObject
.
parseObject
(
condition
.
getConditionJsonText
());
conditionIdElem
=
new
JSONArray
();
conditionIdElem
.
add
(
conditionJson
.
get
(
"originConditionId"
));
conditionIdElem
.
add
(
conditionJson
.
getString
(
"relationName"
).
replace
(
"
-"
,
"b0"
).
replace
(
"0"
,
"a
0"
));
conditionIdElem
.
add
(
conditionJson
.
getString
(
"relationName"
).
replace
(
"
0"
,
"a0"
).
replace
(
"-"
,
"b
0"
));
ape
.
getConditionIdPair
().
add
(
conditionIdElem
);
}
...
...
@@ -845,34 +845,31 @@ public class ActionUtils {
relationName
=
patternConditionJson
.
getString
(
"relationName"
).
replace
(
"0"
,
"a0"
).
replace
(
"-"
,
"b0"
);
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_head"
,
new
HashSet
<
String
>());
conditionExtraKeywords
.
putIfAbsent
(
DEFAULT_CONDITION
+
"_tail"
,
new
HashSet
<
String
>());
String
condTemple
=
patternConditionJson
.
toJSONString
();
for
(
int
i
=
1
;
i
<
100
;
i
++){
for
(
int
i
=
0
;
i
<
100
;
i
++){
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
if
(
i
==
1
)
if
(
i
==
0
)
postfix
=
""
;
else
postfix
=
"_"
+
String
.
valueOf
(
i
);
activeFlag
=
"0"
;
conditionJson
=
(
JSONObject
)
JSON
.
parse
(
condTemple
);
// conditionJson = (JSONObject) patternConditionJson.clone();
conditionName
=
conditionJson
.
getString
(
"conditionName"
)
+
postfix
;
conditionName2
=
conditionName
+
"_indep"
;
conditionJson
=
(
JSONObject
)
patternConditionJson
.
clone
();
conditionName
=
conditionJson
.
getString
(
"conditionName"
)
+
postfix
;
conditionName2
=
conditionName
+
"_indep"
;
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
)){
//如果没有用到这个condition,就跳过
if
(!
conditionExtraKeywords
.
containsKey
(
conditionName2
+
"_tail"
))
break
;
}
if
(
conditionExtraKeywords
.
containsKey
(
conditionName
+
"_tail"
))
{
conditionJson
.
put
(
"conditionName"
,
conditionName
);
conditionAppendKeyword
(
conditionName
,
conditionJson
,
conditionExtraKeywords
,
macroAppendMap
);
}
if
(
conditionExtraKeywords
.
containsKey
(
conditionName2
+
"_tail"
))
{
}
else
if
(
conditionExtraKeywords
.
containsKey
(
conditionName2
+
"_tail"
))
{
conditionJson
.
put
(
"conditionName"
,
conditionName2
);
conditionAppendKeyword2
(
conditionName2
,
conditionJson
,
conditionExtraKeywords
,
macroAppendMap
);
conditionName
=
conditionName2
;
}
else
{
continue
;
}
if
(
conditionJson
.
getBoolean
(
"active"
)
&&
!
conditionName
.
equals
(
startCondition
))
...
...
src/main/java/com/qiwu/chatbotbackend/entity/ConfigTermText.java
View file @
bccbf33e
...
...
@@ -189,15 +189,18 @@ public class ConfigTermText implements Cloneable{
conditionName
.
startsWith
(
"map_"
)
||
conditionName
.
startsWith
(
"start_options"
)
||
conditionName
.
startsWith
(
"load_game_by_site"
)
)
{}
else
{
gNameCount
.
putIfAbsent
(
conditionName
,
0
);
gNameCount
.
put
(
conditionName
,
gNameCount
.
get
(
conditionName
)
+
1
);
if
(
gNameCount
.
get
(
conditionName
)
>
1
&&
premise
.
getAccurateMatch
())
{
premise
.
setConditionName
(
conditionName
+
"_"
+
gNameCount
.
get
(
conditionName
));
premise
.
setAccurateName
();
Integer
count
=
gNameCount
.
get
(
conditionName
);
if
(
count
==
null
)
{
gNameCount
.
put
(
conditionName
,
0
);
count
=
0
;
}
if
(
premise
.
getAccurateMatch
())
{
count
=
count
+
1
;
gNameCount
.
put
(
conditionName
,
count
);
premise
.
setConditionName
(
conditionName
+
"_"
+
count
+
"_indep"
);
}
}
...
...
src/main/java/com/qiwu/chatbotbackend/entity/Premise.java
View file @
bccbf33e
...
...
@@ -117,7 +117,4 @@ public class Premise {
this
.
keyword
=
keyword
;
}
public
void
setAccurateName
()
{
this
.
conditionName
=
this
.
conditionName
+
"_indep"
;
}
}
src/main/java/com/qiwu/chatbotbackend/gameDesign/ElementConstructor.java
View file @
bccbf33e
...
...
@@ -95,13 +95,10 @@ public class ElementConstructor {
*/
public
void
parseKeyword
(
JSONObject
config
,
Map
<
String
,
HashSet
<
String
>>
relationKeywords
,
HashSet
<
String
>
exceptRelation
,
String
botName
){
String
conditionName
,
pair
[];
for
(
Map
premise:
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"currentPremiseList"
).
toJSONString
(),
Map
.
class
)){
for
(
Map
<
String
,
Object
>
premise:
JSONArray
.
parseArray
(
config
.
getJSONArray
(
"currentPremiseList"
).
toJSONString
(),
Map
.
class
)){
conditionName
=
(
String
)
premise
.
get
(
"actionName"
);
if
(!
exceptRelation
.
contains
(
conditionName
))
{
//初始化
if
(!
relationKeywords
.
containsKey
(
conditionName
+
"_head"
))
{
relationKeywords
.
put
(
conditionName
+
"_head"
,
new
HashSet
<
String
>());
...
...
@@ -109,14 +106,14 @@ public class ElementConstructor {
}
//visitorname和bot的替换
premise
.
put
(
"keywords"
,
((
String
)
premise
.
get
(
"keywords"
)).
replace
(
"qiwu"
,
"#visitorname"
).
replace
(
botName
,
"#botname"
));
//
premise.put("keywords", ((String)premise.get("keywords")).replace("qiwu", "#visitorname").replace(botName, "#botname"));
premise
.
put
(
"keywords"
,
replaceKeywords
((
String
)
premise
.
get
(
"keywords"
)));
for
(
String
keyword
:
((
String
)
premise
.
get
(
"keywords"
)).
split
(
"\\+"
))
{
if
(
keyword
.
equals
(
""
)){
continue
;
}
else
if
(
keyword
.
contains
(
":"
)){
//有些配置条目要求三元组两边的值都匹配,需要把两边的值分别加入题头和值域
pair
=
keyword
.
split
(
":"
,
2
);
...
...
@@ -152,8 +149,9 @@ public class ElementConstructor {
relationKeywords
.
put
(
conditionName
+
"_tail"
,
new
HashSet
<
String
>());
}
premise
.
put
(
"keywords"
,
((
String
)
premise
.
get
(
"keywords"
)).
replace
(
"qiwu"
,
"#visitorname"
).
replace
(
botName
,
"#botname"
));
//
premise.put("keywords", ((String)premise.get("keywords")).replace("qiwu", "#visitorname").replace(botName, "#botname"));
premise
.
put
(
"keywords"
,
replaceKeywords
((
String
)
premise
.
get
(
"keywords"
)));
for
(
String
keyword
:
((
String
)
premise
.
get
(
"keywords"
)).
split
(
"\\+"
))
{
if
(
keyword
.
equals
(
""
)){
...
...
@@ -178,6 +176,43 @@ public class ElementConstructor {
}
}
public
String
replaceKeywords
(
String
str
)
{
Boolean
startChat
=
str
.
startsWith
(
"+"
);
Map
<
String
,
String
>
keywords
=
new
HashMap
<>();
keywords
.
put
(
"qiwu"
,
"#visitorname"
);
keywords
.
put
(
"我"
,
"#visitorname"
);
keywords
.
put
(
"botName"
,
"#botname"
);
keywords
.
put
(
"你"
,
"#botname"
);
String
[]
split
=
str
.
split
(
"\\+"
);
String
_s
;
int
pos
;
String
sub1
;
String
sub2
;
for
(
int
i
=
0
;
i
<
split
.
length
;
++
i
)
{
_s
=
split
[
i
];
pos
=
_s
.
indexOf
(
":"
);
if
(
pos
==
-
1
)
{
if
(
keywords
.
get
(
_s
)
!=
null
)
{
_s
=
keywords
.
get
(
_s
);
}
}
else
{
sub1
=
_s
.
substring
(
0
,
pos
);
sub2
=
_s
.
substring
(
pos
+
1
,
_s
.
length
());
if
(
keywords
.
get
(
sub1
)
!=
null
)
{
sub1
=
keywords
.
get
(
sub1
);
}
if
(
keywords
.
get
(
sub2
)
!=
null
)
{
sub2
=
keywords
.
get
(
sub2
);
}
_s
=
sub1
+
":"
+
sub2
;
}
split
[
i
]
=
_s
;
}
str
=
String
.
join
(
"+"
,
split
);
if
(!
str
.
equals
(
""
)
&&
startChat
&&
!
str
.
startsWith
(
"+"
))
str
=
"+"
+
str
;
return
str
;
}
/**
* 根据插入的数据做后处理
...
...
src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java
View file @
bccbf33e
...
...
@@ -591,11 +591,11 @@ public class PlotConstructor2 extends ElementConstructor {
* 4. 无论哪种情况都会跳下一步剧情
*/
unknownTypeConfigTermGenerate
(
"sleeping"
,
"queryskip1"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
8
"
,
unknownTypeConfigTermGenerate
(
"sleeping"
,
"queryskip1"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
5
"
,
"match"
,
"{临时变量reply-2}"
,
"process-nextStep:var={临时变量condition-2}"
);
unknownTypeConfigTermGenerate
(
"sleeping"
,
"queryskip2"
,
"qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=9
8
"
,
unknownTypeConfigTermGenerate
(
"sleeping"
,
"queryskip2"
,
"qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=9
5
"
,
"match"
,
"{临时变量reply-2}"
,
"process-nextStep:var={临时变量condition-2}"
);
...
...
@@ -626,16 +626,16 @@ public class PlotConstructor2 extends ElementConstructor {
"match,return-0"
,
UNKNOWN_TEXT
,
""
);
unknownTypeConfigTermGenerate
(
"sleeping"
,
"unknown3"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
8
,unknownText::match-Include=null"
,
unknownTypeConfigTermGenerate
(
"sleeping"
,
"unknown3"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
5
,unknownText::match-Include=null"
,
"match,return-0"
,
UNKNOWN_TEXT
,
""
);
unknownTypeConfigTermGenerate
(
"sleeping"
,
"unknown4"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
8
"
,
unknownTypeConfigTermGenerate
(
"sleeping"
,
"unknown4"
,
"qa_status::match-Include=OK,qa_score::number-Smaller=9
5
"
,
"match,return-0"
,
"{unknownText-2}"
,
""
);
//由于剧情跳转时地点可能发生变化, qa问答的句子可能因为npc不再同一位置而被过滤掉,所以将common_answer的字符串合并放在postprocessing中
unknownTypeConfigTermGenerate
(
"sleeping"
,
"common_answer"
,
"qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=9
8
"
,
unknownTypeConfigTermGenerate
(
"sleeping"
,
"common_answer"
,
"qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=9
5
"
,
"match,return-0"
,
""
,
""
);
//---------------------------------------------------------------------------------------------------------------
...
...
@@ -774,9 +774,9 @@ public class PlotConstructor2 extends ElementConstructor {
//
//if()
if
(
activateFlag
){
configTermText
.
setNextStep
(
nextCondition
+
",queryskip*,map*,
item
*,npc*"
);
configTermText
.
setNextStep
(
nextCondition
+
",queryskip*,map*,
goods
*,npc*"
);
}
else
{
configTermText
.
setNextStep
(
"queryskip*,map*,
item
*,npc*"
);
configTermText
.
setNextStep
(
"queryskip*,map*,
goods
*,npc*"
);
}
//虽然激活了查询相关的配置文件,但返回给引擎的condition还是应该用剧情里的,所以
...
...
@@ -969,14 +969,13 @@ public class PlotConstructor2 extends ElementConstructor {
String
feature
=
newTerm
.
getFeature
();
feature
=
feature
+
",activate,post::gameQA("
+
QA_URL
+
")"
;
newTerm
.
setFeature
(
feature
);
newTerm
.
setNextStep
(
"map*,
item
*,npc*,"
+
stemStr
+
"_qa1,"
+
stemStr
+
"_qa2"
);
newTerm
.
setNextStep
(
"map*,
goods
*,npc*,"
+
stemStr
+
"_qa1,"
+
stemStr
+
"_qa2"
);
return
newTerm
;
}
private
ConfigTermText
createTermExtra1
(
ConfigTermText
term
)
{
String
hPremise
=
"qa_score::number-BiggerOrEqual=9
8
"
;
String
hPremise
=
"qa_score::number-BiggerOrEqual=9
5
"
;
String
featureStr
=
"match,return-0"
;
//String nextStr = "map*,item*,npc*";
String
nextStr
=
" "
;
String
knowledgeStr
=
UNKNOWN_COUNTER_NAME
+
":+1"
;
String
configName
=
term
.
getConfigName
()+
"_qa1"
;
...
...
@@ -988,7 +987,7 @@ public class PlotConstructor2 extends ElementConstructor {
private
ConfigTermText
createTermExtra2
(
ConfigTermText
term
)
{
String
hPremise
=
"qa_score::number-Smaller=9
8
"
;
String
hPremise
=
"qa_score::number-Smaller=9
5
"
;
// String featureStr = ",match,includeCurInfo,activate:after";
String
configName
=
term
.
getConfigName
()+
"_qa2"
;
String
nextStr
=
term
.
getNextStep
();
...
...
src/main/java/com/qiwu/chatbotbackend/processing/FormsPoster.java
View file @
bccbf33e
package
com
.
qiwu
.
chatbotbackend
.
processing
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.qiwu.chatbotbackend.GameEnvironment.GameEnv
;
import
com.qiwu.chatbotbackend.entity.Action
;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.task.utils.GameBotUtil
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.UnsupportedEncodingException
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.
QA_FETCH_ERROR
;
public
class
FormsPoster
{
LogWriter
logWriter
;
public
static
String
TALKER
=
"【(.*?)@.*?】"
;
@Value
(
"${qa.url}"
)
public
String
QA_URL
;
public
void
setQaUrl
(
String
qaUrl
)
{
QA_URL
=
qaUrl
;
}
public
FormsPoster
(
LogWriter
logWriter
)
{
this
.
logWriter
=
logWriter
;
}
HashSet
<
String
>
skipSet
=
new
HashSet
<
String
>()
{
{
add
(
"activeList"
);
add
(
"currentAction"
);
add
(
"lastUpdateTime"
);
add
(
"lastReply"
);
}
};
/**
* 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器,还有回答
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postAll
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
String
URL
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
k_iter
=
curInfoPoint
.
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
();
if
(
curInfoPoint
.
get
(
key
)
!=
null
&&
!
curInfoPoint
.
get
(
key
).
equals
(
""
))
pairList
.
add
(
new
BasicNameValuePair
(
key
,
curInfoPoint
.
get
(
key
)));
}
k_iter
=
historyInfoPoint
.
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
();
if
(
historyInfoPoint
.
get
(
key
)
!=
null
&&
!
historyInfoPoint
.
get
(
key
).
equals
(
""
))
{
if
(
skipSet
.
contains
(
key
))
continue
;
if
(
curInfoPoint
.
get
(
key
)
==
null
||
curInfoPoint
.
equals
(
""
))
{
pairList
.
add
(
new
BasicNameValuePair
(
key
,
historyInfoPoint
.
get
(
key
)));
}
else
{
pairList
.
add
(
new
BasicNameValuePair
(
key
+
"_his"
,
historyInfoPoint
.
get
(
key
)));
}
}
}
pairList
.
add
(
new
BasicNameValuePair
(
"reply"
,
ans
.
getAnswer
()));
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
Iterator
<
String
>
kit
=
jobj
.
keySet
().
iterator
();
while
(
kit
.
hasNext
())
{
keyName
=
kit
.
next
();
if
(
keyName
.
equals
(
"process"
))
{
ans
.
setNext
((
String
)
jobj
.
get
(
keyName
));
historyInfoPoint
.
put
(
"process"
,
(
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"solution"
))
{
ans
.
setAnswer
((
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"status"
)
||
keyName
.
equals
(
"qa_candidates"
)){
continue
;
}
else
{
historyInfoPoint
.
put
(
keyName
,
jobj
.
getString
(
keyName
));
}
}
}
else
{
if
(
URL
.
equals
(
QA_URL
))
ans
.
setAnswer
(
"qa_threshold, game_step, query_text 看看少了哪个"
);
else
ans
.
setAnswer
(
"提交表单出现异常"
);
}
}
/**
* 提交类型为term时只会提交最佳匹配的配置条目中包含的条件和值
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param ansAction
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postTerm
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
Action
ansAction
,
String
URL
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
pairList
.
add
(
new
BasicNameValuePair
(
"chat_key"
,
curInfoPoint
.
get
(
"chat_key"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"action_name"
,
curInfoPoint
.
get
(
"action_name"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"bot_name"
,
curInfoPoint
.
get
(
"bot_name"
)));
k_iter
=
ansAction
.
getCurrentPremise
().
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
().
split
(
"::"
)[
0
];
if
(
curInfoPoint
.
get
(
key
)
!=
null
&&
!
curInfoPoint
.
equals
(
""
))
pairList
.
add
(
new
BasicNameValuePair
(
key
,
curInfoPoint
.
get
(
key
)));
}
k_iter
=
ansAction
.
getHistoryPremise
().
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
().
split
(
"::"
)[
0
];
if
(!
historyInfoPoint
.
get
(
key
).
equals
(
""
))
{
if
(
curInfoPoint
.
get
(
key
)
==
null
||
curInfoPoint
.
equals
(
""
))
{
pairList
.
add
(
new
BasicNameValuePair
(
key
,
historyInfoPoint
.
get
(
key
)));
}
else
{
pairList
.
add
(
new
BasicNameValuePair
(
key
+
"_his"
,
historyInfoPoint
.
get
(
key
)));
}
}
}
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
Iterator
<
String
>
kit
=
jobj
.
keySet
().
iterator
();
while
(
kit
.
hasNext
())
{
keyName
=
kit
.
next
();
if
(
keyName
.
equals
(
"process"
))
{
ans
.
setNext
((
String
)
jobj
.
get
(
keyName
));
historyInfoPoint
.
put
(
"process"
,
(
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"solution"
))
{
ans
.
setAnswer
((
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"status"
)){
continue
;
}
else
{
historyInfoPoint
.
put
(
keyName
,
jobj
.
getString
(
keyName
));
}
}
}
else
{
ans
.
setAnswer
(
"提交表单出现异常"
);
}
}
/**
* 游戏专用提交表单
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param gameEnv
* @param worldController
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postGameQA1
(
String
gameStep
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
,
UserInfo
userInfo
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
String
threshold
=
"50"
;
if
(
historyInfoPoint
.
get
(
"qa_threshold"
)
!=
null
)
threshold
=
historyInfoPoint
.
get
(
"qa_threshold"
);
pairList
.
add
(
new
BasicNameValuePair
(
"game_step"
,
gameStep
));
pairList
.
add
(
new
BasicNameValuePair
(
"query_text"
,
curInfoPoint
.
get
(
"query_text"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"qa_threshold"
,
threshold
));
//设置初始值
historyInfoPoint
.
put
(
"common_answer"
,
""
);
historyInfoPoint
.
put
(
"qa_score"
,
"0"
);
historyInfoPoint
.
put
(
"qa_status"
,
"OK"
);
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
String
text
,
score
,
site
=
historyInfoPoint
.
get
(
"site"
),
npc
;
System
.
out
.
println
(
jobj
.
toJSONString
());
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
if
(
jobj
.
getJSONArray
(
"qa_candidates"
)
!=
null
&&
jobj
.
get
(
"qa_status"
).
equals
(
"OK"
))
{
List
<
JSONArray
>
candidates
=
JSON
.
toJavaObject
(
jobj
.
getJSONArray
(
"qa_candidates"
),
List
.
class
);
try
{
for
(
JSONArray
pair
:
candidates
)
{
List
textscore
=
JSON
.
toJavaObject
(
pair
,
List
.
class
);
Pattern
findTalker
=
Pattern
.
compile
(
TALKER
);
if
((
Integer
)
textscore
.
get
(
1
)
>
9
8
)
{
Matcher
m
=
findTalker
.
matcher
((
String
)
textscore
.
get
(
0
));
if
(
m
.
find
())
{
npc
=
m
.
group
(
1
);
if
((
GameBotUtil
.
sameLocation
((
String
)
textscore
.
get
(
0
),
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
historyInfoPoint
.
get
(
"site"
),
logWriter
)
==
1
))
{
historyInfoPoint
.
put
(
"common_answer"
,
(
String
)
textscore
.
get
(
0
));
historyInfoPoint
.
put
(
"qa_score"
,
String
.
valueOf
(
textscore
.
get
(
1
)));
break
;
}
}
}
}
}
catch
(
Exception
e
){
historyInfoPoint
.
put
(
"common_answer"
,
QA_FETCH_ERROR
);
historyInfoPoint
.
put
(
"qa_score"
,
"99"
);
}
}
}
else
{
historyInfoPoint
.
put
(
"error_message"
,
jobj
.
getString
(
"error_message"
));
}
}
public
void
postGameQA
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
,
UserInfo
userInfo
)
throws
UnsupportedEncodingException
{
postGameQA1
(
historyInfoPoint
.
get
(
"game_step"
),
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
URL
,
userInfo
);
if
(
historyInfoPoint
.
get
(
"common_answer"
)
!=
null
&&
(
historyInfoPoint
.
get
(
"common_answer"
).
equals
(
""
)
||
historyInfoPoint
.
get
(
"common_answer"
).
equals
(
"no answer"
))){
postGameQA1
(
curInfoPoint
.
get
(
"bot_name"
),
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
URL
,
userInfo
);
}
// historyInfoPoint.put("common_answer", "【旁白@%正常】QA暂时关闭");
// historyInfoPoint.put("qa_score", "99");
// historyInfoPoint.put("qa_status", "OK");
}
}
package
com
.
qiwu
.
chatbotbackend
.
processing
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.qiwu.chatbotbackend.GameEnvironment.GameEnv
;
import
com.qiwu.chatbotbackend.entity.Action
;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.task.utils.GameBotUtil
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.UnsupportedEncodingException
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
com
.
qiwu
.
chatbotbackend
.
Config
.
Config
.
QA_FETCH_ERROR
;
public
class
FormsPoster
{
LogWriter
logWriter
;
public
static
String
TALKER
=
"【(.*?)@.*?】"
;
@Value
(
"${qa.url}"
)
public
String
QA_URL
;
public
void
setQaUrl
(
String
qaUrl
)
{
QA_URL
=
qaUrl
;
}
public
FormsPoster
(
LogWriter
logWriter
)
{
this
.
logWriter
=
logWriter
;
}
HashSet
<
String
>
skipSet
=
new
HashSet
<
String
>()
{
{
add
(
"activeList"
);
add
(
"currentAction"
);
add
(
"lastUpdateTime"
);
add
(
"lastReply"
);
}
};
/**
* 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器,还有回答
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postAll
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
String
URL
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
k_iter
=
curInfoPoint
.
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
();
if
(
curInfoPoint
.
get
(
key
)
!=
null
&&
!
curInfoPoint
.
get
(
key
).
equals
(
""
))
pairList
.
add
(
new
BasicNameValuePair
(
key
,
curInfoPoint
.
get
(
key
)));
}
k_iter
=
historyInfoPoint
.
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
();
if
(
historyInfoPoint
.
get
(
key
)
!=
null
&&
!
historyInfoPoint
.
get
(
key
).
equals
(
""
))
{
if
(
skipSet
.
contains
(
key
))
continue
;
if
(
curInfoPoint
.
get
(
key
)
==
null
||
curInfoPoint
.
equals
(
""
))
{
pairList
.
add
(
new
BasicNameValuePair
(
key
,
historyInfoPoint
.
get
(
key
)));
}
else
{
pairList
.
add
(
new
BasicNameValuePair
(
key
+
"_his"
,
historyInfoPoint
.
get
(
key
)));
}
}
}
pairList
.
add
(
new
BasicNameValuePair
(
"reply"
,
ans
.
getAnswer
()));
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
Iterator
<
String
>
kit
=
jobj
.
keySet
().
iterator
();
while
(
kit
.
hasNext
())
{
keyName
=
kit
.
next
();
if
(
keyName
.
equals
(
"process"
))
{
ans
.
setNext
((
String
)
jobj
.
get
(
keyName
));
historyInfoPoint
.
put
(
"process"
,
(
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"solution"
))
{
ans
.
setAnswer
((
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"status"
)
||
keyName
.
equals
(
"qa_candidates"
)){
continue
;
}
else
{
historyInfoPoint
.
put
(
keyName
,
jobj
.
getString
(
keyName
));
}
}
}
else
{
if
(
URL
.
equals
(
QA_URL
))
ans
.
setAnswer
(
"qa_threshold, game_step, query_text 看看少了哪个"
);
else
ans
.
setAnswer
(
"提交表单出现异常"
);
}
}
/**
* 提交类型为term时只会提交最佳匹配的配置条目中包含的条件和值
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param ansAction
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postTerm
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
Action
ansAction
,
String
URL
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
pairList
.
add
(
new
BasicNameValuePair
(
"chat_key"
,
curInfoPoint
.
get
(
"chat_key"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"action_name"
,
curInfoPoint
.
get
(
"action_name"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"bot_name"
,
curInfoPoint
.
get
(
"bot_name"
)));
k_iter
=
ansAction
.
getCurrentPremise
().
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
().
split
(
"::"
)[
0
];
if
(
curInfoPoint
.
get
(
key
)
!=
null
&&
!
curInfoPoint
.
equals
(
""
))
pairList
.
add
(
new
BasicNameValuePair
(
key
,
curInfoPoint
.
get
(
key
)));
}
k_iter
=
ansAction
.
getHistoryPremise
().
keySet
().
iterator
();
while
(
k_iter
.
hasNext
())
{
key
=
k_iter
.
next
().
split
(
"::"
)[
0
];
if
(!
historyInfoPoint
.
get
(
key
).
equals
(
""
))
{
if
(
curInfoPoint
.
get
(
key
)
==
null
||
curInfoPoint
.
equals
(
""
))
{
pairList
.
add
(
new
BasicNameValuePair
(
key
,
historyInfoPoint
.
get
(
key
)));
}
else
{
pairList
.
add
(
new
BasicNameValuePair
(
key
+
"_his"
,
historyInfoPoint
.
get
(
key
)));
}
}
}
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
Iterator
<
String
>
kit
=
jobj
.
keySet
().
iterator
();
while
(
kit
.
hasNext
())
{
keyName
=
kit
.
next
();
if
(
keyName
.
equals
(
"process"
))
{
ans
.
setNext
((
String
)
jobj
.
get
(
keyName
));
historyInfoPoint
.
put
(
"process"
,
(
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"solution"
))
{
ans
.
setAnswer
((
String
)
jobj
.
get
(
keyName
));
}
else
if
(
keyName
.
equals
(
"status"
)){
continue
;
}
else
{
historyInfoPoint
.
put
(
keyName
,
jobj
.
getString
(
keyName
));
}
}
}
else
{
ans
.
setAnswer
(
"提交表单出现异常"
);
}
}
/**
* 游戏专用提交表单
* @param curInfoPoint
* @param historyInfoPoint
* @param ans
* @param gameEnv
* @param worldController
* @param URL
* @throws UnsupportedEncodingException
*/
public
void
postGameQA1
(
String
gameStep
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
,
UserInfo
userInfo
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
String
threshold
=
"50"
;
if
(
historyInfoPoint
.
get
(
"qa_threshold"
)
!=
null
)
threshold
=
historyInfoPoint
.
get
(
"qa_threshold"
);
pairList
.
add
(
new
BasicNameValuePair
(
"game_step"
,
gameStep
));
pairList
.
add
(
new
BasicNameValuePair
(
"query_text"
,
curInfoPoint
.
get
(
"query_text"
)));
pairList
.
add
(
new
BasicNameValuePair
(
"qa_threshold"
,
threshold
));
//设置初始值
historyInfoPoint
.
put
(
"common_answer"
,
""
);
historyInfoPoint
.
put
(
"qa_score"
,
"0"
);
historyInfoPoint
.
put
(
"qa_status"
,
"OK"
);
logWriter
.
record
(
"提交表单的数据:<br>"
+
pairList
.
toString
(),
2
);
JSONObject
jobj
=
SimpleUtil
.
postFORM
(
URL
,
pairList
);
logWriter
.
record
(
"提交表单接收到的数据:<br>"
+
jobj
.
toJSONString
(),
2
);
String
text
,
score
,
site
=
historyInfoPoint
.
get
(
"site"
),
npc
;
System
.
out
.
println
(
jobj
.
toJSONString
());
if
((
Integer
)
jobj
.
get
(
"post_status"
)
==
1
){
if
(
jobj
.
getJSONArray
(
"qa_candidates"
)
!=
null
&&
jobj
.
get
(
"qa_status"
).
equals
(
"OK"
))
{
List
<
JSONArray
>
candidates
=
JSON
.
toJavaObject
(
jobj
.
getJSONArray
(
"qa_candidates"
),
List
.
class
);
try
{
for
(
JSONArray
pair
:
candidates
)
{
List
textscore
=
JSON
.
toJavaObject
(
pair
,
List
.
class
);
Pattern
findTalker
=
Pattern
.
compile
(
TALKER
);
if
((
Integer
)
textscore
.
get
(
1
)
>
9
5
)
{
Matcher
m
=
findTalker
.
matcher
((
String
)
textscore
.
get
(
0
));
if
(
m
.
find
())
{
npc
=
m
.
group
(
1
);
if
((
GameBotUtil
.
sameLocation
((
String
)
textscore
.
get
(
0
),
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
historyInfoPoint
.
get
(
"site"
),
logWriter
)
==
1
))
{
historyInfoPoint
.
put
(
"common_answer"
,
(
String
)
textscore
.
get
(
0
));
historyInfoPoint
.
put
(
"qa_score"
,
String
.
valueOf
(
textscore
.
get
(
1
)));
break
;
}
}
}
}
}
catch
(
Exception
e
){
historyInfoPoint
.
put
(
"common_answer"
,
QA_FETCH_ERROR
);
historyInfoPoint
.
put
(
"qa_score"
,
"99"
);
}
}
}
else
{
historyInfoPoint
.
put
(
"error_message"
,
jobj
.
getString
(
"error_message"
));
}
}
public
void
postGameQA
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
,
UserInfo
userInfo
)
throws
UnsupportedEncodingException
{
postGameQA1
(
historyInfoPoint
.
get
(
"game_step"
),
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
URL
,
userInfo
);
if
(
historyInfoPoint
.
get
(
"common_answer"
)
!=
null
&&
(
historyInfoPoint
.
get
(
"common_answer"
).
equals
(
""
)
||
historyInfoPoint
.
get
(
"common_answer"
).
equals
(
"no answer"
))){
postGameQA1
(
curInfoPoint
.
get
(
"bot_name"
),
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
URL
,
userInfo
);
}
// historyInfoPoint.put("common_answer", "【旁白@%正常】QA暂时关闭");
// historyInfoPoint.put("qa_score", "99");
// historyInfoPoint.put("qa_status", "OK");
}
}
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