private static void updateResultWithActualReferents(
      Result result,
      List<AnaphorWithReferent> anaphorsWithReferents,
      int sentenceId,
      int pronominalIndex,
      Coref inputPronominal) {
    List<AnaphorWithReferent> anaphorsForSentence =
        getAnaphorsForSentence(anaphorsWithReferents, sentenceId);
    AnaphorWithReferent anaphorByTokenIndex =
        getAnaphorByTokenIndex(anaphorsForSentence, pronominalIndex);

    if (anaphorByTokenIndex == null) {
      result.setActualReferentSentenceId(-1);
      result.setActualReferentStartIndex(-1);
      result.setActualReferentText(null);

      return;
    }

    String actualPronominalText = anaphorByTokenIndex.getAnaphor().toString();
    if (!validateActualPronominal(inputPronominal.toString(), actualPronominalText)) {
      String errorMessage =
          String.format(
              "Actual pronominal wasn't found for: sentence %s token %s",
              result.getSentenceId(), result.getExpectedReferentStartIndex());
      System.err.println(errorMessage);

      return;
    }

    NpTreeInSentence actualReferent = anaphorByTokenIndex.getReferent();
    result.setActualReferentSentenceId(actualReferent.getSentence().getId());

    result.setActualReferentText(actualReferent.toString());

    result.setActualReferentStartIndex(actualReferent.getStartIndex());
  }
  private static List<Result> generateResultsFromParsingResults(
      InputText inputText, List<AnaphorWithReferent> anaphorsWithReferents) {
    List<Result> results = new ArrayList<>();

    for (AnaphorWithReferent anaphorWithReferent : anaphorsWithReferents) {
      Result result =
          new Result(inputText.getId(), anaphorWithReferent.getAnaphor().getSentence().getId());
      result.setSentenceText(anaphorWithReferent.getAnaphor().getSentence().getText());
      result.setPronoun(anaphorWithReferent.getAnaphor().toString());
      result.setPronounTokenIndex(anaphorWithReferent.getAnaphor().getStartIndex());

      result.setActualReferentStartIndex(anaphorWithReferent.getReferent().getStartIndex());
      result.setActualReferentText(anaphorWithReferent.getReferent().toString());
      result.setActualReferentSentenceId(anaphorWithReferent.getReferent().getSentence().getId());

      results.add(result);
    }

    return results;
  }
  private static List<Result> compareWithInputText(
      InputText inputText, List<AnaphorWithReferent> anaphorsWithReferents) {

    List<Result> results = new ArrayList<>();
    for (InputSentence inputSentence : inputText.getSentences()) {
      if (!inputSentence.isValid()) {
        continue;
      }

      List<Coref> pronominalCorefs = inputSentence.getPronominalCorefs();

      Result result;

      if (pronominalCorefs.size() == 0) {
        result = new Result(inputText.getId(), inputSentence.getSentenceId());
        result.setSentenceText(inputText.getSentenceById(inputSentence.getSentenceId()).toString());

        result.setExpectedReferentSentenceId(null);
        result.setExpectedReferentStartIndex(null);
        result.setExpectedReferentText(null);

        // Assuming only one
        List<AnaphorWithReferent> anaphorsForSentence =
            getAnaphorsForSentence(anaphorsWithReferents, inputSentence.getSentenceId());

        if (anaphorsForSentence.size() == 0) {
          continue;
        }

        AnaphorWithReferent anaphorForSentence = anaphorsForSentence.get(0);

        // TODO: check if the same anaphor
        NpTreeInSentence referent = anaphorForSentence.getReferent();
        result.setActualReferentSentenceId(referent.getSentence().getId());
        result.setActualReferentText(referent.toString());
        result.setActualReferentStartIndex(referent.getStartIndex());

        results.add(result);

        continue;
      }

      for (Coref inputPronominal : pronominalCorefs) {
        result = new Result(inputText.getId(), inputSentence.getSentenceId());
        result.setSentenceText(inputText.getSentenceById(inputSentence.getSentenceId()).toString());

        int sentenceId = inputPronominal.getSentenceId();
        int pronominalIndex = inputPronominal.getStartIndex();

        result.setPronoun(inputPronominal.toString());
        result.setPronounTokenIndex(pronominalIndex);

        List<Coref> expectedReferentsForPronominal =
            inputText.getReferentsForPronominal(inputPronominal.getId());

        if (expectedReferentsForPronominal.size() >= 1) {
          // We take the first referent from the sentence.
          List<String> corefs =
              expectedReferentsForPronominal
                  .stream()
                  .map(c -> c.toString())
                  .collect(Collectors.toList());
          List<Integer> sentenceIndices =
              expectedReferentsForPronominal
                  .stream()
                  .map(c -> c.getSentenceId())
                  .collect(Collectors.toList());
          List<Integer> startIndices =
              expectedReferentsForPronominal
                  .stream()
                  .map(c -> c.getStartIndex())
                  .collect(Collectors.toList());

          result.setExpectedReferentSentenceId(sentenceIndices);
          result.setExpectedReferentText(corefs);
          result.setExpectedReferentStartIndex(startIndices);
        } else {
          result.setExpectedReferentSentenceId(null);
          result.setExpectedReferentText(null);
          result.setExpectedReferentStartIndex(null);
        }

        updateResultWithActualReferents(
            result, anaphorsWithReferents, sentenceId, pronominalIndex, inputPronominal);

        results.add(result);
      }
    }

    return results;
  }