我有比较相似度的得分列表,我希望在得到Array
之后像这样array[][]
制作Array
多维,它将是总和列和行。但我不知道要宣布这一点。
这是我的代码:
List<List<Sentence>> collect = Arrays.asList(new File(p).listFiles()).stream()
.map((x) -> configSentenceByLine(x.getAbsolutePath()))
.map((x) -> tokenizingWord(x))
.map((x) -> stemmingWord(x))
.map((x) -> countWordBased(x))
.collect(Collectors.toList());
double sim = 0.0;
for (int k = 0; k < collect.size(); k++) {
for (int i = 0; i < collect.get(k).size(); i++) {
for (int m = k + 1; m < collect.size(); m++) {
for (int j = 0; j < collect.get(m).size(); j++) {
SimilarityMeasure ss = new SimilarityMeasure();
sim = ss.getSimilarity(collect.get(k).get(i).getSentence(), collect.get(m).get(j).getSentence());
}
}
}
}
如果有2个文件我可以申报,我可以得到总和列和行。
在声明2个文件的代码下方。
double[][] simMat = new double[collect.get(0).size()][collect.get(1).size()];
for (int k = 0; k < collect.get(0).size(); k++) {
for (int i = 0; i < collect.get(1).size(); i++) {
simMat[k][i] = (double) (nc.getSimilarity(collect.get(0).get(k).getSentence(), collect.get(1).get(i).getSentence()));
}
}
但是如果文件有5个或更多,我都不知道要宣布这个。
答案 0 :(得分:0)
也许你可以拆分成单独的数组并创建一个数组数组,然后从那里进行操作。下面的例子只是剪切和粘贴并保存为html文件并在浏览器中运行。希望它有所帮助。
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
///// array of arrays /////
///// create array [a] with three elements /////
var a=[1,2,3];
///// create array [b] with three elements /////
var b=[4,5,6];
///// create array c with two elements [array a and array b] /////
var c=[a,b];
///// create variable d /////
var d;
///// put element 0 of array c into variable d /////
///// as element 0 of array c is array a /////
///// array a is passed into variable d a=[1,2,3] /////
d=c[0]
///// proof print out 2nd element of variable d /////
///// prints out 2 which is 2nd element of array a /////
///// which was stored as first element of array c /////
document.getElementById("demo").innerHTML = d[1];
</script>
</body>
</html>