/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package seekfeel.datareaders;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import seekfeel.dataholders.DataUnit;
import seekfeel.dataholders.MovieReview;
import seekfeel.utilities.PropertiesGetter;
/**
*
* @author Ahmed
*/
public class MovieReview_Reader implements Reader {
public ArrayList<DataUnit> readReviews(int polarity) {
String dirName = polarity == 1 ? PropertiesGetter.getProperty("PosReviewsDir") : PropertiesGetter.getProperty("NegReviewsDir");
File dir = new File(dirName);
String reviewBody;
ArrayList<DataUnit> theReviews = new ArrayList<DataUnit>();
String[] fileNames = dir.list();
MovieReview tempReview;
if (fileNames != null) {
for (String fileName : fileNames) {
tempReview = new MovieReview();
tempReview.setSentiment(polarity);
reviewBody = readFile(dirName + "//" + fileName);
tempReview.setDataBody(reviewBody);
theReviews.add(tempReview);
}
}
return theReviews;
}
private String readFile(String path) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(path));
StringBuilder sb = new StringBuilder();
String nextLine;
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
}
br.close();
return sb.toString();
} catch (Exception ex) {
Logger.getLogger(MovieReview_Reader.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
br.close();
} catch (IOException ex) {
Logger.getLogger(MovieReview_Reader.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
@Override
public ArrayList<DataUnit> getData(String dataParam) {
// TODO Auto-generated method stub
return null;
}
}