def extract_output(output_dir):
    sentences_glob = os.path.join(output_dir, '*-preprocessed.xml.gz')
    sentences_filename_candidates = glob.glob(sentences_glob)
    if len(sentences_filename_candidates) != 1:
        m = 'Looking for exactly one file matching %s but found %d matches'
        raise Exception(m % (
            sentences_glob, len(sentences_filename_candidates)))
        return None, None, None
    sentence_segmentation_filename = sentences_filename_candidates[0]
    with gzip.GzipFile(sentences_filename_candidates[0], 'r') as f:
        sentence_segmentations = f.read().decode('utf-8')
    tmp_dir = tempfile.mkdtemp(suffix='indra_tees_processor')
    try:
        tarfile_glob = os.path.join(output_dir, '*-events.tar.gz')
        candidate_tarfiles = glob.glob(tarfile_glob)
        if len(candidate_tarfiles) != 1:
            raise Exception('Expected exactly one match for glob %s' %
                            tarfile_glob)
            return None, None, None
        tar_file = tarfile.open(candidate_tarfiles[0])
        a1_file = None
        a2_file = None
        extract_these = []
        for m in tar_file.getmembers():
            if re.match('[a-zA-Z0-9].*.a[12]', m.name):
                extract_these.append(m)
                if m.name.endswith('.a1'):
                    a1_file = m.name
                elif m.name.endswith('.a2'):
                    a2_file = m.name
                else:
                    assert(False)
        if len(extract_these) != 2 or a1_file is None or a2_file is None:
            raise Exception('We thought there would be one .a1 and one .a2' +
                            ' file in the tarball, but we got %d files total' %
                            len(extract_these))
            return None, None, None
        tar_file.extractall(path=tmp_dir, members=extract_these)
        with codecs.open(os.path.join(tmp_dir, a1_file), 'r',
                         encoding='utf-8') as f:
            a1_text = f.read()
        with codecs.open(os.path.join(tmp_dir, a2_file), 'r',
                         encoding='utf-8') as f:
            a2_text = f.read()
        shutil.rmtree(tmp_dir)
        return a1_text, a2_text, sentence_segmentations
    except BaseException as e:
        print('Not removing temporary directory: ' + tmp_dir)
        shutil.rmtree(tmp_dir)
        raise e
        return None, None, None