use of edu.illinois.cs.cogcomp.chunker.main.ChunkerConfigurator in project cogcomp-nlp by CogComp.
the class ACERelationTester method testRandomText.
public static void testRandomText(String text) {
String corpus = "";
String textId = "";
TextAnnotationBuilder stab = new TokenizerTextAnnotationBuilder(new StatefulTokenizer());
TextAnnotation ta = stab.createTextAnnotation(corpus, textId, text);
try {
POSAnnotator pos_annotator = new POSAnnotator();
ChunkerAnnotator chunker = new ChunkerAnnotator(true);
chunker.initialize(new ChunkerConfigurator().getDefaultConfig());
Properties stanfordProps = new Properties();
stanfordProps.put("annotators", "pos, parse");
stanfordProps.put("parse.originalDependencies", true);
stanfordProps.put("parse.maxlen", Stanford331Configurator.STFRD_MAX_SENTENCE_LENGTH);
stanfordProps.put("parse.maxtime", Stanford331Configurator.STFRD_TIME_PER_SENTENCE);
POSTaggerAnnotator posAnnotator = new POSTaggerAnnotator("pos", stanfordProps);
ParserAnnotator parseAnnotator = new ParserAnnotator("parse", stanfordProps);
StanfordDepHandler stanfordDepHandler = new StanfordDepHandler(posAnnotator, parseAnnotator);
MentionAnnotator mentionAnnotator = new MentionAnnotator("ACE_TYPE");
RelationAnnotator relationAnnotator = new RelationAnnotator();
ta.addView(pos_annotator);
stanfordDepHandler.addView(ta);
chunker.addView(ta);
mentionAnnotator.addView(ta);
relationAnnotator.addView(ta);
for (Relation r : ta.getView(ViewNames.RELATION).getRelations()) {
IOHelper.printRelation(r);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.illinois.cs.cogcomp.chunker.main.ChunkerConfigurator in project cogcomp-nlp by CogComp.
the class ACERelationTester method testAnnotator.
public static void testAnnotator() {
int total_correct = 0;
int total_labeled = 0;
int total_predicted = 0;
int total_coarse_correct = 0;
try {
POSAnnotator pos_annotator = new POSAnnotator();
ChunkerAnnotator chunker = new ChunkerAnnotator(true);
chunker.initialize(new ChunkerConfigurator().getDefaultConfig());
Properties stanfordProps = new Properties();
stanfordProps.put("annotators", "pos, parse");
stanfordProps.put("parse.originalDependencies", true);
stanfordProps.put("parse.maxlen", Stanford331Configurator.STFRD_MAX_SENTENCE_LENGTH);
stanfordProps.put("parse.maxtime", Stanford331Configurator.STFRD_TIME_PER_SENTENCE);
POSTaggerAnnotator posAnnotator = new POSTaggerAnnotator("pos", stanfordProps);
ParserAnnotator parseAnnotator = new ParserAnnotator("parse", stanfordProps);
StanfordDepHandler stanfordDepHandler = new StanfordDepHandler(posAnnotator, parseAnnotator);
ACEReader aceReader = new ACEReader("data/partition_with_dev/dev", false);
MentionAnnotator mentionAnnotator = new MentionAnnotator("ACE_TYPE");
RelationAnnotator relationAnnotator = new RelationAnnotator();
for (TextAnnotation ta : aceReader) {
ta.addView(pos_annotator);
stanfordDepHandler.addView(ta);
chunker.addView(ta);
mentionAnnotator.addView(ta);
relationAnnotator.addView(ta);
total_labeled += ta.getView(ViewNames.MENTION_ACE).getRelations().size();
total_predicted += ta.getView(ViewNames.RELATION).getRelations().size();
for (Relation pr : ta.getView(ViewNames.RELATION).getRelations()) {
for (Relation gr : ta.getView(ViewNames.MENTION_ACE).getRelations()) {
Constituent prSourceHead = RelationFeatureExtractor.getEntityHeadForConstituent(pr.getSource(), ta, "");
Constituent grSourceHead = RelationFeatureExtractor.getEntityHeadForConstituent(gr.getSource(), ta, "");
Constituent prTargetHead = RelationFeatureExtractor.getEntityHeadForConstituent(pr.getTarget(), ta, "");
Constituent grTargetHead = RelationFeatureExtractor.getEntityHeadForConstituent(gr.getTarget(), ta, "");
if (prSourceHead.getStartSpan() == grSourceHead.getStartSpan() && prSourceHead.getEndSpan() == grSourceHead.getEndSpan() && prTargetHead.getEndSpan() == grTargetHead.getEndSpan() && prTargetHead.getStartSpan() == grTargetHead.getStartSpan()) {
if (pr.getAttribute("RelationType").equals(gr.getAttribute("RelationType"))) {
total_coarse_correct++;
}
if (pr.getAttribute("RelationSubtype").equals(gr.getAttribute("RelationSubtype"))) {
total_correct++;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Total labeled: " + total_labeled);
System.out.println("Total predicted: " + total_predicted);
System.out.println("Total correct: " + total_correct);
System.out.println("Total coarse correct: " + total_coarse_correct);
double p = (double) total_correct * 100.0 / (double) total_predicted;
double r = (double) total_correct * 100.0 / (double) total_labeled;
double f = 2 * p * r / (p + r);
System.out.println("Precision: " + p);
System.out.println("Recall: " + r);
System.out.println("Fine Type F1: " + f);
System.out.println("Coarse Type F1: " + f * (double) total_coarse_correct / (double) total_correct);
}
Aggregations