/*
 * Corpus.java
 *
 * Created on May 18, 2004, 9:26 PM
 */

package spamfilter.email;

import java.io.File;

/**
 *
 * @author  AaronStJ
 */
public class Corpus {  
    
    private String directory;
    private String[] files;
    private Email[] emails;
    private boolean isSpam;
    
    /** Creates a new instance of Corpus */
    public Corpus(String fn, boolean is) {
        isSpam = is;        
        
        directory = fn;
        File dir = new File(directory);
        
        if(!dir.isDirectory())
            throw new IllegalArgumentException();
        
        files = dir.list();
        
        StopList stopList = new StopList("spamfilter/email/stoplist.txt");
        
        emails = new Email[files.length];
        for(int i = 0; i < files.length; i++) {
            System.out.print(".");
            emails[i] = new Email(directory + "/" + files[i], stopList);
        }
        System.out.println("Done!");
    }
    
    public String getRandomWord() {   
        return emails[(int)(Math.random() * emails.length)].getRandomWord();
    }
    
    public Email getRandomEmail() {   
        return emails[(int)(Math.random() * emails.length)];
    }
    
    public int getNumberOfEmails() {
        return files.length;
    }
    
    public Email getEmail(int index) {
        return emails[index];
    }
    
}
