def write_crf_file(filename, document, separator=' '):
    """
    Takes a tagged document (a list of tagged sentences) and writes it
    to a file which is structured like y w pos. Here y denotes the label
    of the token, w is the token itself and pos is the pos tag of the token

    Example:
    Input: [[(0, 6, 'Verden', 'O', 'NE'), (6, 7, '/', 'O', '$['), (7, 19, 'MünchenNeuer', 'O', 'NE'), (20, 32, 'gigantischer', 'O', 'ADJA'), (33, 38, 'Daten', 'O', 'NN'), ... ]]

    Output:
    O Verden NE
    O / $[
    O MünchenNeuer NE
    O gigantischer ADJA
    O Daten NN
    ...

    :param filename: the file to write the output to
    :param document: the tagged documents data that should be transformed into a crf file
    :param seperator: the seperator to use in oder to sperate the elements
    """
    output = open(filename, 'w')
    for sentence in document:
        for token in sentence:
            output.write(token[3] + separator + token[2] + separator +
                token[4] + '\n')
        output.write('\n')
    output.close()
