//remove the null argument from relations
aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveNullArgumentRelations.class));
Function<BinaryTextRelation, ?> getSpan = new Function<BinaryTextRelation, HashableArguments>() {
public HashableArguments apply(BinaryTextRelation relation) {
return new HashableArguments(relation);
}
};
Function<BinaryTextRelation, String> getOutcome = AnnotationStatistics.annotationToFeatureValue("category");
AnnotationStatistics<String> stats = new AnnotationStatistics<>();
JCasIterable jcasIter =new JCasIterable(collectionReader, aggregateBuilder.createAggregate());
JCas jCas = null;
while(jcasIter.hasNext()) {
jCas = jcasIter.next();
JCas goldView = jCas.getView(GOLD_VIEW_NAME);
JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
Collection<BinaryTextRelation> goldRelations = Lists.newArrayList();
for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(goldView, BinaryTextRelation.class))){
if(relation.getArg1().getArgument() != null && relation.getArg2().getArgument() != null && relation.getCategory() != null){
goldRelations.add(relation);
}
}
Collection<BinaryTextRelation> systemRelations = Lists.newArrayList();
for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(systemView, BinaryTextRelation.class))){
if(relation.getArg1().getArgument() != null && relation.getArg2().getArgument() != null && relation.getCategory() != null){
systemRelations.add(relation);
}
}
//newly add
// systemRelations = removeNonGoldRelations(systemRelations, goldRelations);//for removing non-gold pairs
// systemRelations = correctArgOrder(systemRelations, goldRelations);//change the argument order of "OVERLAP" relation, if the order is flipped
//find duplicates in gold relations:
// Collection<BinaryTextRelation> duplicateGoldRelations = getDuplicateRelations(goldRelations, getSpan);
// if(!duplicateGoldRelations.isEmpty()){
// System.err.println("******Duplicate gold relations in : " + ViewURIUtil.getURI(jCas).toString());
// for (BinaryTextRelation rel : duplicateGoldRelations){
// System.err.println("Duplicate : "+ formatRelation(rel));
// }
// }
//end newly add
stats.add(goldRelations, systemRelations, getSpan, getOutcome);
if(this.printRelations){
URI uri = ViewURIUtil.getURI(jCas);
String[] path = uri.getPath().split("/");
printRelationAnnotations(path[path.length - 1], systemRelations);
}
if(this.printErrors){
Map<HashableArguments, BinaryTextRelation> goldMap = Maps.newHashMap();
for (BinaryTextRelation relation : goldRelations) {
goldMap.put(new HashableArguments(relation), relation);
}
Map<HashableArguments, BinaryTextRelation> systemMap = Maps.newHashMap();
for (BinaryTextRelation relation : systemRelations) {
systemMap.put(new HashableArguments(relation), relation);
}
Set<HashableArguments> all = Sets.union(goldMap.keySet(), systemMap.keySet());
List<HashableArguments> sorted = Lists.newArrayList(all);
Collections.sort(sorted);
for (HashableArguments key : sorted) {