i have a file containing the index of the document and publication date:
0, 2012-05-26T00:00:00Z
1, 2012-05-26T00:00:00Z
5, 2010-06-26T00:00:00Z
10, 2014-05-26T00:00:00Z
and a second text file containing the term frequency and the index of the doc that belongs to him:
was, 15, 1
kill, 10,1
tunisia, 5, 5
peace, 1, 0
i have this method that match both of the files so i can get a third file with this form:
was, 15, 2012-05-26T00:00:00Z
kill, 10,2012-05-26T00:00:00Z
tunisia, 5, 2010-06-26T00:00:00Z
peace, 1, 2012-05-26T00:00:00Z
I tested the method of a test file and it work fine but my file's size is 1T so my program has been in execution for 4 days and still working. would you plz help me to optimize it or give me another method.
public void matchingDateTerme (String pathToDateFich, String pathTotermeFich) {
try {
BufferedReader inTerme = new BufferedReader(new FileReader(pathTotermeFich));
BufferedReader inDate = new BufferedReader(new FileReader(pathToDateFich));
String lineTerme,lineDate;
String idFich, idFichDate,dateterm,key;
Hashtable<String, String> table = new Hashtable<String, String>();
String[] tokens,dates;
Enumeration ID=null;
File tempFile = new File(pathTotermeFich.replace("fichierTermes", "fichierTermes_final"));
FileWriter fileWriter =new FileWriter(tempFile);
BufferedWriter writer = new BufferedWriter(fileWriter);
//read file date
while ((lineDate = inDate.readLine()) != null) {
dates = lineDate.split(", ");
idFichDate = dates[0].toLowerCase();
dateterm=dates[1];
table.put(idFichDate, dateterm);
}
while ((lineTerme = inTerme.readLine()) != null) {
tokens = lineTerme.split(", ");
idFich = tokens[2].toLowerCase();
String terme=tokens[0];
String freq=tokens[1];
//lire hachtable
ID = table.keys();
while(ID.hasMoreElements()) {
key = (String) ID.nextElement();
if(key.equalsIgnoreCase(idFich)){
String line=terme+", "+freq+", "+table.get(key);
System.out.println("Line: "+line);
writer.write(line);
writer.newLine();
}
}
}
writer.close();
inTerme.close();
inDate.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}