use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.CoreferenceView in project cogcomp-nlp by CogComp.
the class StanfordCorefHandler method addView.
@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
Annotation document = new Annotation(ta.text);
pipeline.annotate(document);
CoreferenceView vu = new CoreferenceView(viewName, ta);
Map corefChain = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);
for (Object key : corefChain.keySet()) {
CorefChain chain = (CorefChain) corefChain.get(key);
Constituent representative = createConstituentGivenMention(document, chain, chain.getRepresentativeMention(), ta);
List<Constituent> consList = new ArrayList<>();
for (CorefChain.CorefMention m : chain.getMentionsInTextualOrder()) {
consList.add(createConstituentGivenMention(document, chain, m, ta));
}
// remove the representative itself
consList.remove(representative);
vu.addCorefEdges(representative, consList);
}
ta.addView(viewName, vu);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.CoreferenceView in project cogcomp-nlp by CogComp.
the class CorefAccuracyEvaluator method evaluate.
public void evaluate(ClassificationTester tester, View goldView, View predictionView) {
int overlapCount = 0;
int predCount = 0;
int goldCount = 0;
CoreferenceView gold = (CoreferenceView) goldView;
CoreferenceView prediction = (CoreferenceView) predictionView;
List<Constituent> allGoldConstituents = gold.getConstituents();
for (Constituent cons1 : allGoldConstituents) {
HashSet<Constituent> coreferents1gold = gold.getOverlappingChainsCanonicalMentions(cons1);
HashSet<Constituent> coreferents1pred = prediction.getOverlappingChainsCanonicalMentions(cons1);
for (Constituent c : coreferents1gold) coreferents1gold.addAll(gold.getCoreferentMentionsViaRelations(c));
for (Constituent c : coreferents1gold) coreferents1pred.addAll(prediction.getCoreferentMentionsViaRelations(c));
for (Constituent cons2 : allGoldConstituents) {
// are the two constituents in the same cluster, in gold annotation?
boolean coreferents1goldContains = false;
for (Constituent goldC : coreferents1gold) if (goldC.equalsWithoutAttributeEqualityCheck(cons2))
coreferents1goldContains = true;
if (coreferents1goldContains) {
// are the two constituents in the same cluster, in pred annotation?
boolean coreferents1predContains = false;
for (Constituent predC : coreferents1pred) if (predC.equalsWithoutAttributeEqualityCheck(cons2))
coreferents1predContains = true;
if (coreferents1predContains) {
overlapCount += 1;
}
goldCount += 1;
}
// are the two constituents in the same cluster, in pred annotation?
boolean coreferents1predContainsCons2 = false;
for (Constituent predC : coreferents1pred) if (predC.equalsWithoutAttributeEqualityCheck(cons2))
coreferents1predContainsCons2 = true;
if (coreferents1predContainsCons2)
predCount += 1;
}
tester.recordCount("coref", goldCount, predCount, overlapCount);
}
}
Aggregations