use of org.cogcomp.re.ACEMentionReader in project cogcomp-nlp by CogComp.
the class RelationExtractionTest method testSimpleTraining.
@Test
public void testSimpleTraining() {
File modelDir = null;
try {
Datastore ds = new Datastore(new ResourceConfigurator().getDefaultConfig());
modelDir = ds.getDirectory("org.cogcomp.re", "ACE_TEST_DOCS", 1.1, false);
} catch (Exception e) {
e.printStackTrace();
}
ACEMentionReader train_parser = new ACEMentionReader(modelDir.getPath() + File.separator + "ACE_TEST_DOCS", "relations_bi");
relation_classifier classifier = new relation_classifier();
classifier.setLexiconLocation("src/test/tmp.lex");
BatchTrainer trainer = new BatchTrainer(classifier, train_parser);
Learner preExtractLearner = trainer.preExtract("src/test/tmp.ex", true, Lexicon.CountPolicy.none);
preExtractLearner.saveLexicon();
Lexicon lexicon = preExtractLearner.getLexicon();
classifier.setLexicon(lexicon);
int examples = train_parser.relations_bi.size();
classifier.initialize(examples, preExtractLearner.getLexicon().size());
for (Relation r : train_parser.relations_bi) {
classifier.learn(r);
}
classifier.doneWithRound();
classifier.doneLearning();
train_parser.reset();
int correct = 0;
for (Relation r : train_parser.relations_bi) {
String tag = classifier.discreteValue(r);
if (tag.equals(r.getAttribute("RelationSubtype"))) {
correct++;
}
}
assertTrue(correct > 0);
}
Aggregations