我有一个包含多个文件的文件夹,其中包含数据,我需要运行我的命名实体识别器。我想打开每个文件并逐行处理,并将结果写入Results文件夹中的相应文件。我写了一些代码,但似乎什么也没做:
File file = new File(folderPath);
File[] files = file.listFiles();
for(File f: files){
String name = String.valueOf(increase);
File resultsFile = new File("C:/Users/Desktop/Data_And_Sentences/Results/File" + name + ".txt");
BufferedReader br = null;
try
{
br = new BufferedReader(new java.io.FileReader(f));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String line;
try
{
while ((line = br.readLine()) != null) {
while(resultsFile.exists()){
FileWriter fw = new FileWriter(resultsFile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
HashMap<String, Vector<String>> neMap = identifyNER(line);
for(String type : neMap.keySet())
{
bw.write(type + ": " + neMap.get(type)+"\t");
bw.newLine();
}
if(bw!=null)
bw.flush();
bw.close();
increase++;
name = String.valueOf(increase);
resultsFile = new File("C:/Users/Desktop/Data_And_Sentences/Results/File" + name + ".txt");
continue;
}
if(!resultsFile.exists()) {
resultsFile.createNewFile();
continue;
}