我有来自文档的列表分数句子,每个最高分数将被插入到每个索引中。例如:
指数0 = 0.1
指数1 = 0.3
指数2 = 0.2
指数3 = 0.5
指数4 = 0.4
指数5 = 0.6
列表分数索引将设置为Map
value
,列表文档的key
为:
Doc 1
Doc 2
Doc 3
在我使用Map<listDocuments, Index>
循环后,我得到了诸如
Doc 1 = Index 0
Doc 1 = Index 1
Doc 1 = Index 2
Doc 2 = Index 3
Doc 2 = Index 4
Doc 3 = Index 5
问题是,我无法显示具有最大值的文档,而且我只获得这样的每个文档的最后value
。
Doc 1 = Index 2
Doc 2 = Index 4
Doc 3 = Index 5
虽然我想根据下面的最大值显示它。
Doc 1 = Index 1(0.3)
Doc 2 =索引3(0.5)
Doc 3 = Index 5(0.6)
这是我的代码
int index = 0;
int index2 = 0;
double max = 0.0;
double max2 = 0.0;
LinkedHashMap< List<Integer>, Integer> data = new LinkedHashMap< List<Integer>, Integer>();
for (int d1 = 0; d1 < d - 1; d1++) {
for (int d2 = d1 + 1; d2 < d; d2++) {
//...Other code.....
}
listSentence.add(ste.maxScore());
listSentence2.add(ste.maxScore2());
max = Collections.max(listSentence);
max2 = Collections.max(listSentence2);
index = listSentence.indexOf(max);
index2 = listSentence.indexOf(max2);
data.put(d1, index);
data.put(d2, index2);
}
//code for displaying it
for (Map.Entry list : data.entrySet()) {
System.out.println("" + stemmings
.get(list.getKey().hashCode())
.get(list.getValue().hashCode()));
}
任何答案都将不胜感激。谢谢
答案 0 :(得分:0)
好的一个简单的例子:
Map<Integer, Set<Integer>> data = new HashMap<Integer, Set<Integer>>();
for(;;) // use your loop here
{
int document;
int index;
// Do some stuff to get index and so on
if(!data.containsKey(document))
{
data.put(document, new HashSet<Integer>());
}
data.get(document).add(index);
}
// Output
for(Map.Entry<Integer, Set<Integer>> entry : data.entrySet())
{
int maxIndex = -1;
int maxScore = Integer.MIN_VALUE;
for(Integer index : entry.getValue())
{
int score;
//get the score for index
if(score > maxScore)
{
maxScore = score;
maxIndex = index;
}
}
System.out.println("Document: "+entry.getKey()+" Index with max score: "+maxIndex);
}