def write_conll(self, fname):
        """
        Serializes the dataset in CONLL format to fname
        """
        if 'label' not in self.fields:
            raise InvalidFieldsException("dataset is not in CONLL format: missing label field")

        def instance_to_conll(inst):
            tab = [v for k, v in inst.items() if k != 'label']
            return '{}\n{}'.format(inst['label'], '\n'.join(['\t'.join(['-' if e is None else str(e) for e in row]) for row in zip(*tab)]))

        with open(fname, 'wb') as f:
            f.write('# {}'.format('\t'.join([k for k in self.fields if k != 'label'])))
            for i, d in enumerate(self):
                f.write('\n{}'.format(instance_to_conll(d)))
                if i != len(self) - 1:
                    f.write('\n')
def write_conll ( self , fname ) : if 'label' not in self . fields : raise InvalidFieldsException ( "dataset is not in CONLL format: missing label field" ) def instance_to_conll ( inst ) : tab = [ v for k , v in inst . items ( ) if k != 'label' ] return '{}\n{}' . format ( inst [ 'label' ] , '\n' . join ( [ '\t' . join ( [ '-' if e is None else str ( e ) for e in row ] ) for row in zip ( * tab ) ] ) ) with open ( fname , 'wb' ) as f : f . write ( '# {}' . format ( '\t' . join ( [ k for k in self . fields if k != 'label' ] ) ) ) for i , d in enumerate ( self ) : f . write ( '\n{}' . format ( instance_to_conll ( d ) ) ) if i != len ( self ) - 1 : f . write ( '\n' )
Serializes the dataset in CONLL format to fname