-
Notifications
You must be signed in to change notification settings - Fork 17
/
train.java
23 lines (22 loc) · 916 Bytes
/
train.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void train() throws IOException, ClassNotFoundException {
File trainDir;
String[] categories;
LMClassifier class;
trainDir = new File("trainDirectory");
categories = trainDir.list();
int nGram = 7; //the nGram level, any value between 7 and 12 works
class= DynamicLMClassifier.createNGramProcess(mCategories, nGram);
for (int i = 0; i < categories.length; ++i) {
String category = categories[i];
Classification classification = new Classification(category);
File file = new File(trainDir, categories[i]);
File[] trainFiles = file.listFiles();
for (int j = 0; j < trainFiles.length; ++j) {
File trainFile = trainFiles[j];
String review = Files.readFromFile(trainFile, "ISO-8859-1");
Classified classified = new Classified(review, classification);
((ObjectHandler>) class).handle(classified);
}
}
AbstractExternalizable.compileTo((Compilable) class, new File("classifier.txt"));
}