本指南由我的一位讲师提供,我想用java实现。 但我不太了解它,但如何在Java上实现。 有人可以尝试为我进一步解释吗?我欣赏一个很好的教程。 :)需要帮助了解本指南
“为文本文件创建一个数组,通过每个文本文件查找该术语,一旦得到该术语,就会打破内部循环,更改文件名并再次循环搜索该术语。创建一个计数器来计算包含该术语的文本文件的数量。最后,您将从计数器值中获取包含该术语的文档数量。“
我有一个文本文件的集合,我需要检查是否在文件中找到特定的术语。如果找到该术语,我需要将fileFound增加到1.
或者更具体地说是逆文档频率。
为了达到上述目的,我需要什么?我的意思是代码观点。对不起,我的编码很慢。不,我不希望获得免费代码。我只想了解指南的内容。我已经问过我的讲师,但这还不够。我只是想知道如何在java中实现。谢谢你的时间。
System.out.println("Please enter the required word :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan.nextLine();
String[] array2 = word2.split(" ");
int numofDoc = 0;
for (int i = 0; i < filename; i++) {
for (int b = 0; b < array2.length; b++) {
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().contains(word2))
matchedWord++;
}
}
if (matchedWord > 0)
numofDoc++;
System.out.println("This file contain the term "
+ numofDoc);
} catch (IOException e) {
System.out.println("File not found.");
}
}
}
的输出是:
请输入所需的词语:
the
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File not found
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
我想输出印出单输出,其示出了包含术语文件的数目是10。这意味着它已经总结了总数。并且只在输出中打印出一行。任何想法先生?
到目前为止你有什么?即使是伪代码也可以。哪些部件有问题? – Farrell 2011-03-10 14:51:26
问题的所有部分都是自我解释性的。一步一步地做好工作。 – Deepak 2011-03-10 14:54:07
是的,上面的文本几乎是伪代码,只是做他在那里写的东西,只是在java代码;) – Tobias 2011-03-10 15:01:25