gpt4 book ai didi

java - 对数答案不准确

转载 作者:行者123 更新时间:2023-11-29 10:06:54 24 4
gpt4 key购买 nike

//Count the number of documents available

File folder = new File("C:\\Users\\user\\fypworkspace\\TextRenderer");
File[] listOfFiles = folder.listFiles();
int numDoc = 0;

for (int i = 0; i < listOfFiles.length; i++) {
if ((listOfFiles[i].getName().endsWith(".txt"))) {
numDoc++;
}
}

//Count the number of documents containing a string

System.out.println("Please enter the required word :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan2.nextLine();
String[] array2 = word2.split(" ");

for (int b = 0; b < array2.length; b++) {
int numofDoc = 0;



for (int i = 0; i < filename; i++) {

try {

BufferedReader in = new BufferedReader(new FileReader(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc"
+ i + ".txt"));

int matchedWord = 0;

Scanner s2 = new Scanner(in);

{

while (s2.hasNext()) {
if (s2.next().equals(array2[b]))
matchedWord++;
}

}
if (matchedWord > 0)
numofDoc++;

} catch (IOException e) {
System.out.println("File not found.");
}

}
System.out.println(array2[b] + " --> This number of files that contain the term " + numofDoc);
double inverseTF = Math.log ( numDoc/ numofDoc );
System.out.println(array2[b] + " --> This inverse term frequency that contain the term " + inverseTF);
}

}
}

当我尝试计算公式所在的 inverseTF 时

日志(numDoc/numofDoc),

我没有得到正确的答案。

有人有想法吗?

程序的输出是

The number of files available is 11.
is --> This number of files that contain the term is 7
is --> This inverse term frequency that contain the term 0.45198510206864073

最佳答案

Math.log()是基础 e 的登录,也许您正在寻找 Math.log10() .但是由于您没有提供有关预期结果是什么以及错误是什么的任何信息,我不能肯定地说。

也有可能因为你的两个变量是 int 而出现舍入错误。尝试:

Math.log ((float) numDoc / numofDoc);

关于java - 对数答案不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5273381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com