def process_document(worker, archive, filename, doc):
    interface = worker.interface
    # Resolve coreference, passing in PTB parse trees as strings
    coref_result = interface.gateway.entry_point.resolveCoreference(doc)
    if coref_result is None:
        # Coref failed, return an invalid doc
        # Fetch all output from stdout and stderr
        stdout = _get_full_queue(interface.stdout_queue)
        stderr = _get_full_queue(interface.stderr_queue)
        return InvalidDocument(
            u"opennlp_coref", u"Error running coref\nJava stdout:\n%s\nJava stderr:\n%s" % (stdout, stderr)
        )

    outputs = []
    for output_name in worker.info.output_names:
        if output_name == "coref":
            # Pull all of the information out of the java objects to get ready to store as JSON
            outputs.append([Entity.from_java_object(e) for e in get_field(coref_result, "entities")])
        elif output_name == "tokenized":
            outputs.append([sentence.split() for sentence in get_field(coref_result, "tokenizedSentences")])
        elif output_name == "pos":
            tokens = [sentence.split() for sentence in get_field(coref_result, "tokenizedSentences")]
            pos_tags = [sentence.split() for sentence in get_field(coref_result, "posTags")]
            outputs.append(list(zip(tokens, pos_tags)))
        elif output_name == "parse":
            outputs.append(list(coref_result.getParseTrees()))
    return tuple(outputs)