0
for (a = 0; a < filename; a++) {
try {
System.out
.println(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
System.out.println("\n");
System.out.println("The word inputted : " + word2);
File file = new File(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc" + a
+ ".txt");
System.out.println(" _________________");
System.out.print("| File = abc" + a + ".txt | \t\t \n");
for (int i = 0; i < array2.length; i++) {
totalCount = 0;
wordCount = 0;
Scanner s = new Scanner(file);
{
while (s.hasNext()) {
totalCount++;
if (s.next().equals(array2[i]))
wordCount++;
}
System.out.print(array2[i] + " --> Word count = "
+ "\t " + "|" + wordCount + "|");
System.out.print(" Total count = " + "\t " + "|"
+ totalCount + "|");
System.out.printf(" Term Frequency = | %8.4f |",
(double) wordCount/totalCount);
System.out.println("\t ");
double inverseTF = Math.log10((float) numDoc
/(numofDoc[i]));
System.out.println(" --> IDF = " + inverseTF);
double TFIDF = (((double) wordCount/totalCount) * inverseTF);
System.out.println(" --> TF/IDF = " + TFIDF + "\n");
}
}
} catch (FileNotFoundException e) {
System.out.println("File is not found");
}
}
}
这是输出示例:
字输入:你怎么样
| File = abc0.txt |
how - > Word count = | 4 |总计数= | 957 |术语频率= | 0.0042 |
--> IDF = 0.5642714398516419
--> TF/IDF = 0.0023585013159943234
是 - >字数= | 7 |总计数= | 957 |术语频率= | 0.0073 |
--> IDF = 0.1962946357308887
--> TF/IDF = 0.00143580193324579
you - > Word count = | 10 |总计数= | 957 |术语频率= | 0.0104 |
--> IDF = 0.1962946357308887
--> TF/IDF = 0.002051145618922557
我如何总结每个文本文件的整个3 TF/IDF?
谢谢先生,但我需要总计它,并显示在每个字的TF/IDF下。先生可以指导我吗? –
你的意思是你会显示TFIDF的第一个字两次,TFIDF的第二个,其次是总和TFIDF?您可以在每次迭代时打印runningTfIDF,它会在那个时间点给出总和。 – dmcnelis
我的意思是给第一个字的整个[3字总和] ..让它变得如此混乱.. –