forked from ysc/QuestionAnsweringSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandidateAnswerCollection.java
More file actions
93 lines (80 loc) · 2.9 KB
/
CandidateAnswerCollection.java
File metadata and controls
93 lines (80 loc) · 2.9 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
/**
*
* 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/>.
*
*/
package org.apdplat.qa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 候选答案集合 包含多个候选答案
*
* @author 杨尚川
*/
public class CandidateAnswerCollection {
private static final Logger LOG = LoggerFactory.getLogger(CandidateAnswerCollection.class);
private final List<CandidateAnswer> candidateAnswers = new ArrayList<>();
public boolean isEmpty() {
return candidateAnswers.isEmpty();
}
/**
* 获取所有候选答案
*
* @return
*/
public List<CandidateAnswer> getAllCandidateAnswer() {
//按CandidateAnswer的分值排序
Collections.sort(candidateAnswers);
Collections.reverse(candidateAnswers);
return candidateAnswers;
}
public void showAll() {
for (CandidateAnswer candidateAnswer : getAllCandidateAnswer()) {
LOG.debug(candidateAnswer.getAnswer() + " " + candidateAnswer.getScore());
}
}
public void showTopN(int topN) {
for (CandidateAnswer candidateAnswer : getTopNCandidateAnswer(topN)) {
LOG.debug(candidateAnswer.getAnswer() + " " + candidateAnswer.getScore());
}
}
public List<CandidateAnswer> getTopNCandidateAnswer(int topN) {
//按CandidateAnswer的分值排序,返回topN
List<CandidateAnswer> result = new ArrayList<>();
Collections.sort(candidateAnswers);
Collections.reverse(candidateAnswers);
int len = candidateAnswers.size();
if (topN > len) {
topN = len;
}
for (int i = 0; i < candidateAnswers.size(); i++) {
result.add(candidateAnswers.get(i));
}
return result;
}
public void addAnswer(CandidateAnswer candidateAnswer) {
if (!candidateAnswers.contains(candidateAnswer)) {
candidateAnswers.add(candidateAnswer);
}
}
public void removeAnswer(CandidateAnswer candidateAnswer) {
candidateAnswers.remove(candidateAnswer);
}
}