forked from ysc/QuestionAnsweringSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.jsp
More file actions
130 lines (126 loc) · 5.58 KB
/
view.jsp
File metadata and controls
130 lines (126 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<%--
APDPlat - Application Product Development Platform
Copyright (c) 2013, 杨尚川, yang-shangchuan@qq.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="org.apdplat.qa.datasource.BaiduDataSource"%>
<%@page import="org.apdplat.qa.model.Question"%>
<%@page import="org.apdplat.qa.model.Evidence"%>
<%@page import="org.apdplat.qa.model.CandidateAnswer"%>
<%@page import="org.apdplat.qa.model.QuestionType"%>
<%@page import="org.apdplat.qa.system.CommonQuestionAnsweringSystem"%>
<%@page import="org.apdplat.qa.system.QuestionAnsweringSystem"%>
<%@page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
QuestionAnsweringSystem questionAnsweringSystem = (QuestionAnsweringSystem) session.getAttribute("questionAnsweringSystem");
if (questionAnsweringSystem == null) {
questionAnsweringSystem = new CommonQuestionAnsweringSystem();
session.setAttribute("questionAnsweringSystem", questionAnsweringSystem);
}
String questionStr = request.getParameter("questionStr");
Question question = null;
List<CandidateAnswer> candidateAnswers = null;
if (questionStr != null && questionStr.trim().length() > 3) {
questionStr = new String(questionStr.getBytes("ISO8859-1"), "UTF-8");
question = new BaiduDataSource().getQuestion(questionStr);
question = questionAnsweringSystem.answerQuestion(question);
if (question != null) {
candidateAnswers = question.getAllCandidateAnswer();
}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人机问答系统演示</title>
</head>
<body>
<h1><font color="blue">人机问答系统演示</font></h1>
<%
if (questionStr == null || questionStr.trim().length() <= 3) {
%>
<font color="red">请输入问题且长度大于3</font>
<%
} else if (candidateAnswers == null || candidateAnswers.size() == 0) {
%>
<font color="red">回答问题失败:<%=questionStr%></font><br/>
<%
}
if (question != null) {
%>
<font color="red">Question : <%=question.getQuestion()%></font><br/><br/>
<%
int j = 1;
for (Evidence evidence : question.getEvidences()) {
%>
<font color="red"> Title <%=j%> : </font> <%=evidence.getTitle()%><br/>
<font color="red"> Snippet <%=j%> : </font> <%=evidence.getSnippet()%><br/>
<%
j++;
}
if (candidateAnswers != null && candidateAnswers.size() > 0) {
%>
<p><font color="red">答案:</font></p>
<table>
<tr><th>序号</th><th>候选答案</th><th>答案评分</th></tr>
<%
int i = 0;
for (CandidateAnswer candidateAnswer : candidateAnswers) {
if ((++i) == 1) {
%>
<tr><td><font color="red"><%=i%></font></td><td><font color="red"><%=candidateAnswer.getAnswer()%></font></td><td><font color="red"><%=candidateAnswer.getScore()%></font></td></tr>
<%
} else {
%>
<tr><td><%=i%></td><td><%=candidateAnswer.getAnswer()%></td><td><%=candidateAnswer.getScore()%></td></tr>
<%
}
}
%>
</table>
<%
}
%>
<h1><a href="<%=request.getContextPath()%>/view.jsp">返回</a></h1>
<%
} else {
%>
<p>
<b>可以像如下提问:</b><br/>
1、APDPlat的作者是谁?<br/>
2、APDPlat的发起人是谁?<br/>
3、谁死后布了七十二疑冢?<br/>
4、习近平最爱的女人是谁?<br/>
5、BMW是哪个汽车公司制造的?<br/>
6、长城信用卡是哪家银行发行的?<br/>
7、美国历史上第一所高等学府是哪个学校?<br/>
8、前身是红色中华通讯社的是什么?<br/>
9、“海的女儿”是哪个城市的城徽?<br/>
10、世界上流经国家最多的河流是哪一条?<br/>
11、世界上最长的河流是什么?<br/>
12、汉城是哪个国家的首都?<br/>
13、全球表面积有多少平方公里?
</p>
<form action="view.jsp" method="post">
<font color="red">输入问题:</font><input name="questionStr" size="150" maxlength="150">
<p></p>
<input type="submit" value="查看证据及答案"/>
</form>
<%
}
%>
<br/>
<h1><a href="index.jsp">简要信息</a></h1>
</body>
</html>