Search in sources :

Example 1 with ACEMentionReader

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);
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) BatchTrainer(edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer) Datastore(org.cogcomp.Datastore) Lexicon(edu.illinois.cs.cogcomp.lbjava.learn.Lexicon) LbjGen.relation_classifier(org.cogcomp.re.LbjGen.relation_classifier) ResourceConfigurator(edu.illinois.cs.cogcomp.core.resources.ResourceConfigurator) File(java.io.File) ACEMentionReader(org.cogcomp.re.ACEMentionReader) Learner(edu.illinois.cs.cogcomp.lbjava.learn.Learner) Test(org.junit.Test)

Aggregations

Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)1 ResourceConfigurator (edu.illinois.cs.cogcomp.core.resources.ResourceConfigurator)1 BatchTrainer (edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer)1 Learner (edu.illinois.cs.cogcomp.lbjava.learn.Learner)1 Lexicon (edu.illinois.cs.cogcomp.lbjava.learn.Lexicon)1 File (java.io.File)1 Datastore (org.cogcomp.Datastore)1 ACEMentionReader (org.cogcomp.re.ACEMentionReader)1 LbjGen.relation_classifier (org.cogcomp.re.LbjGen.relation_classifier)1 Test (org.junit.Test)1