<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: <NAME>

"""
The ``conll`` module converts a ``DiscourseDocumentGraph`` (possibly
containing multiple annotation layers) into an CoNLL 2009 tab-separated file.

TODO: write a generic_merging_cli() and a generic write_format() function.
Coordinate this with
    issue #43: add write_formatname function for each output format
"""

import os
import sys

from discoursegraphs.util import create_dir


class Conll2009File(object):
    """
    This class converts a DiscourseDocumentGraph into a CoNLL 2009 file.
    """
    def __init__(self, docgraph):
        """
        Parameters
        ----------
        docgraph : DiscourseDocumentGraph
            the document graph to be converted
        """
        raise NotImplementedError

    def __str__(self):
        """
        returns the generated CoNLL 2009 file as a string.
        """
        raise NotImplementedError<commit_msg>conll: basic exporter works (tokens/sentences w/ dummy features)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: <NAME>

"""
The ``conll`` module converts a ``DiscourseDocumentGraph`` (possibly
containing multiple annotation layers) into an CoNLL 2009 tab-separated file.

Currently, all annotation levels are ignored; only the tokens and sentences
are exported!

TODO: write a generic_merging_cli() and a generic write_format() function.
Coordinate this with
    issue #43: add write_formatname function for each output format
"""

import os
import sys

from discoursegraphs.util import create_dir, ensure_utf8


class Conll2009File(object):
    """
    This class converts a DiscourseDocumentGraph into a CoNLL 2009 file.
    """
    def __init__(self, docgraph):
        """
        Parameters
        ----------
        docgraph : DiscourseDocumentGraph
            the document graph to be converted
        """
        self.docgraph = docgraph

    def __str__(self):
        """
        returns the generated CoNLL 2009 file as a string.
        """
        docgraph = self.docgraph
        conll_str = ''
        for sentence_id in docgraph.sentences:
            # token indices in CoNLL files start with 1!
            for i, token_id in enumerate(docgraph.node[sentence_id]['tokens'], 1):
                word = docgraph.get_token(token_id)
                conll_str += '{0}\t{1}{2}\n'.format(i,
                                                    ensure_utf8(word),
                                                    '\t_' * 13)
            conll_str += '\n'
        return conll_str
{'fraction_non_alphanumeric': 0.09401709401709402, 'fraction_numerical': 0.01825951825951826, 'mean_word_length': 2.3354922279792745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '807902', 'n_tokens_mistral': 737, 'n_tokens_neox': 670, 'n_words': 232}