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

import com.bbn.bue.common.TextGroupPublicImmutable;
import com.bbn.bue.common.collections.CollectionUtils;
import com.bbn.bue.common.symbols.Symbol;

import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import org.immutables.func.Functional;
import org.immutables.value.Value;

import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.in;
import static com.google.common.collect.Iterables.concat;

/**
 * A linking of {@link Response}s into a document-level event.
 *
 * The IDs on a response linking have no canonical form; they would change due to various filtering
 * steps (e.g. filtering {@link Response}'s in quote regions) and not be easily mappable to original
 * participant input.
 */
@Value.Immutable(prehash = true)
@TextGroupPublicImmutable
@Functional
abstract class _ResponseLinking {
  public abstract Symbol docID();
  public abstract ImmutableSet<ResponseSet> responseSets();
  public abstract ImmutableSet<Response> incompleteResponses();

  public abstract Optional<ImmutableBiMap<String, ResponseSet>> responseSetIds();

  @Value.Derived
  public ImmutableMultimap<Response, ResponseSet> responsesToContainingResponseSets() {
    final ImmutableMultimap.Builder<Response, ResponseSet> ret = ImmutableMultimap.builder();
    for (final ResponseSet responseSet : responseSets()) {
      for (final Response response : responseSet) {
        ret.put(response, responseSet);
      }
    }
    return ret.build();
  }

  @Value.Check
  protected void checkValidity() {
    // no incomplete response may appear in any response set
    final ImmutableSet<Response> allResponsesInSets = ImmutableSet.copyOf(
        concat(responseSets()));
    for (final Response incompleteResponse : incompleteResponses()) {
      checkArgument(!allResponsesInSets.contains(incompleteResponse),
          "A response may not be both completed and incomplete");
    }
    if (responseSetIds().isPresent()) {
      for (final String id : responseSetIds().get().keySet()) {
        checkArgument(!id.contains("-"), "Event frame IDs may not contain -s");
        checkArgument(!id.contains("\t"), "Event frame IDs may not contain tabs");
      }
      checkArgument(responseSetIds().get().keySet().size() == responseSets().size(),
          "All response set IDs must be unique");
      CollectionUtils.assertSameElementsOrIllegalArgument(responseSets(),
          responseSetIds().get().values(), "Response sets did not match IDs",
          "Response sets in list", "Response sets in ID map");
    }<commit_msg>Better error when response set IDs are missing<commit_after>package com.bbn.kbp.events2014;

import com.bbn.bue.common.TextGroupPublicImmutable;
import com.bbn.bue.common.collections.CollectionUtils;
import com.bbn.bue.common.symbols.Symbol;

import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import org.immutables.func.Functional;
import org.immutables.value.Value;

import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.in;
import static com.google.common.collect.Iterables.concat;

/**
 * A linking of {@link Response}s into a document-level event.
 *
 * The IDs on a response linking have no canonical form; they would change due to various filtering
 * steps (e.g. filtering {@link Response}'s in quote regions) and not be easily mappable to original
 * participant input.
 */
@Value.Immutable(prehash = true)
@TextGroupPublicImmutable
@Functional
abstract class _ResponseLinking {
  public abstract Symbol docID();
  public abstract ImmutableSet<ResponseSet> responseSets();
  public abstract ImmutableSet<Response> incompleteResponses();

  public abstract Optional<ImmutableBiMap<String, ResponseSet>> responseSetIds();

  @Value.Derived
  public ImmutableMultimap<Response, ResponseSet> responsesToContainingResponseSets() {
    final ImmutableMultimap.Builder<Response, ResponseSet> ret = ImmutableMultimap.builder();
    for (final ResponseSet responseSet : responseSets()) {
      for (final Response response : responseSet) {
        ret.put(response, responseSet);
      }
    }
    return ret.build();
  }

  @Value.Check
  protected void checkValidity() {
    // no incomplete response may appear in any response set
    final ImmutableSet<Response> allResponsesInSets = ImmutableSet.copyOf(
        concat(responseSets()));
    for (final Response incompleteResponse : incompleteResponses()) {
      checkArgument(!allResponsesInSets.contains(incompleteResponse),
          "A response may not be both completed and incomplete");
    }
    if (responseSetIds().isPresent()) {
      for (final String id : responseSetIds().get().keySet()) {
        checkArgument(!id.contains("-"), "Event frame IDs may not contain -s");
        checkArgument(!id.contains("\t"), "Event frame IDs may not contain tabs");
      }
      checkArgument(!responseSetIds().get().isEmpty(), "Response set IDs are missing");
      checkArgument(responseSetIds().get().keySet().size() == responseSets().size(),
          "All response set IDs must be unique");
      CollectionUtils.assertSameElementsOrIllegalArgument(responseSets(),
          responseSetIds().get().values(), "Response sets did not match IDs",
          "Response sets in list", "Response sets in ID map");
    }
{'fraction_non_alphanumeric': 0.10859208148513225, 'fraction_numerical': 0.0013142763265976672, 'mean_word_length': 4.534545454545454, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6001366', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1664, 'n_words': 441}