/**
* 判断候选答案中是否包含正确的答案。candidateList应该是Agenda中的stateList
* candidateList中存储的是List,从中取出一个与goldAnswer进行比较,如果相同跳出返回
* 如果不同,继续与candidateList 中的下一个List进行比较是否相同,直到与candidateList中
* 都比较过。
*/
public static boolean Include(List<String> goldAnswer, List<List<String>> candidateList){
boolean isInclude = false;
for(int i = 0; i < candidateList.size(); i++)
{
List candidateAnswer = candidateList.get(i);
for(int j = 0; j < candidateAnswer.size(); j++)
{
String gold = goldAnswer.get(j).toString();
String candidate = candidateAnswer.get(j).toString();
if(!gold.equals(candidate))
{
isInclude = false;
break;
}else if(gold.equals(candidate) && j == (candidateAnswer.size()-1))
{
isInclude = true;
}
}
}
return isInclude;
}
public static void main(String args[])
{
List<String> goldAnswer = Arrays.asList("B","I");
List<String> cand1 = Arrays.asList("B","E");
List<String> cand2 = Arrays.asList("I","E");
List<String> cand3 = Arrays.asList("B","N");
List<String> cand4 = Arrays.asList("B","I");
ArrayList<List<String>> candidateList = new ArrayList<List<String>>();
candidateList.add(cand1);
candidateList.add(cand2);
candidateList.add(cand3);
candidateList.add(cand4);
boolean tt = Include(goldAnswer, candidateList);
System.out.println(tt);
}
list比较是否相等
最新推荐文章于 2024-07-03 12:46:25 发布