/**
   * Requests an annotation from the indicated annotation tool (running on the local node) for the
   * indicated document record. Stores the result in this object for later output through the
   * writeOutputFromLastAnnotate() method.
   *
   * @param record The document record on which we will run the annotation tool
   * @param toolToRun The type of annotation that we should get for the record
   * @postcondition lastAnnotatedRecord contains all of the record parameter's previous annotations,
   *     along with the new one
   */
  public void annotateSingleDoc(Record record, AnnotationMode toolToRun)
      throws ServiceUnavailableException, TException, AnnotationFailedException,
          ServiceSecurityException {
    // Ask the Curator to perform the annotation
    lastAnnotatedRecord = annotate(record, toolToRun);

    if (!RecordTools.hasAnnotation(lastAnnotatedRecord, toolToRun)) {
      throw new AnnotationFailedException("Annotation was unsuccessful!");
    }
  }
  /**
   * Writes the results of the last call to annotate() to the specified directory in HDFS. This is
   * equivalent to serializing the results of a call to annotate() to the directory.
   *
   * @param outputDir The directory to which the results of the last call to annotate() should be
   *     written. Each serialized document should be named with the document's hash.
   */
  public void writeOutputFromLastAnnotate(Path outputDir) throws TException, IOException {
    Path fileLoc = getLocForSerializedForm(lastAnnotatedRecord, outputDir);

    try {
      if (!transport.isOpen()) {
        transport.open();
      }
      serializer.serialize(lastAnnotatedRecord, fileLoc, hdfs);

      Record reconstructed = serializer.deserialize(fileLoc, hdfs);
      if (!RecordTools.hasAnnotations(reconstructed)) {
        throw new IOException(
            "Reconstructed record has no annotations, but original has the following: "
                + RecordTools.getContents(lastAnnotatedRecord));
      }
    } finally {
      if (transport.isOpen()) {
        transport.close();
      }
    }
  }