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字總和] ..讓它變得如此混亂.. –