<commit_before>package com.bbn.kbp.events2014.transformers;

import com.bbn.bue.common.scoring.Scored;
import com.bbn.kbp.events2014.*;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;

public final class MakeAllRealisActual {
    private MakeAllRealisActual() {
        throw new UnsupportedOperationException();
    }

    public static Function<AnswerKey, AnswerKey> forAnswerKey() {
        return new Function<AnswerKey, AnswerKey>() {
            @Override
            public AnswerKey apply(AnswerKey input) {
                final ImmutableList.Builder<Response> newUnannotated = ImmutableList.builder();

                for (final Response response : input.unannotatedResponses()) {
                    newUnannotated.add(response.copyWithSwappedRealis(KBPRealis.Actual));
                }

                final ImmutableList.Builder<AssessedResponse> newAssessed = ImmutableList.builder();

                for (final AssessedResponse response : input.annotatedResponses()) {
                    newAssessed.add(AssessedResponse.from(
                            response.response().copyWithSwappedRealis(KBPRealis.Actual),
                            response.assessment().copyWithModifiedRealisAssessment(Optional.of(KBPRealis.Actual))));
                }

                return AnswerKey.from(input.docId(), newAssessed.build(), newUnannotated.build());
            }
        };
    }

    public static Function<SystemOutput, SystemOutput> forSystemOutput() {
        return new Function<SystemOutput, SystemOutput>() {
            @Override
            public SystemOutput apply(SystemOutput input) {
                final ImmutableList.Builder<Scored<Response>> newResponses = ImmutableList.builder();

                for (final Scored<Response> response : input.scoredResponses()) {
                    newResponses.add(Scored.from(response.item().copyWithSwappedRealis(KBPRealis.Actual),
                            response.score()));
                }

                return SystemOutput.from(input.docId(), newResponses.build());
            }
        };
    }
}<commit_msg>Bugfix: neutralizing realis could result in inconsistent assessments<commit_after>package com.bbn.kbp.events2014.transformers;

import com.bbn.bue.common.scoring.Scored;
import com.bbn.kbp.events2014.*;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import java.util.Set;

public final class MakeAllRealisActual {
    private MakeAllRealisActual() {
        throw new UnsupportedOperationException();
    }

    public static Function<AnswerKey, AnswerKey> forAnswerKey() {
        return new Function<AnswerKey, AnswerKey>() {
            @Override
            public AnswerKey apply(AnswerKey input) {
                // seenResponses is to ensure we don't end up with two different
                // assessments for the same response, or have the same response
                // as both assessed and unassessed
                final Set<Response> seenResponses = Sets.newHashSet();
                final ImmutableSet.Builder<AssessedResponse> newAssessed = ImmutableSet.builder();

                for (final AssessedResponse response : input.annotatedResponses()) {
                    final Response neutralizedResponse = response.response().copyWithSwappedRealis(KBPRealis.Actual);
                    if (!seenResponses.contains(neutralizedResponse)) {
                        newAssessed.add(AssessedResponse.from(neutralizedResponse,
                            response.assessment().copyWithModifiedRealisAssessment(Optional.of(KBPRealis.Actual))));
                    }
                    seenResponses.add(neutralizedResponse);
                }


                final ImmutableSet.Builder<Response> newUnannotated = ImmutableSet.builder();

                for (final Response response : input.unannotatedResponses()) {
                    final Response neutralizedResponse = response.copyWithSwappedRealis(KBPRealis.Actual);
                    if (!seenResponses.contains(neutralizedResponse)) {
                        newUnannotated.add(neutralizedResponse);
                    }
                    seenResponses.add(neutralizedResponse);
                }


                return AnswerKey.from(input.docId(), newAssessed.build(), newUnannotated.build());
            }
        };
    }

    public static Function<SystemOutput, SystemOutput> forSystemOutput() {
        return new Function<SystemOutput, SystemOutput>() {
            @Override
            public SystemOutput apply(SystemOutput input) {
                final ImmutableSet.Builder<Scored<Response>> newResponses = ImmutableSet.builder();

                for (final Scored<Response> assessedResponse : input.scoredResponses()) {
                    newResponses.add(Scored.from(assessedResponse.item().copyWithSwappedRealis(KBPRealis.Actual),
                            assessedResponse.score()));
                }

                return SystemOutput.from(input.docId(), newResponses.build());
            }
        };
    }
}
{'fraction_non_alphanumeric': 0.09161608497723824, 'fraction_numerical': 0.0030349013657056147, 'mean_word_length': 2.343690551680406, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6893742', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1302, 'n_words': 234}