'Exports the model as a file for other machine learning applications,
e.g., Orange or Weka.'

def export(self, path, format=ORANGE, **kwargs):

    keys = sorted(self.vector.keys())
    s = []
    if (format.lower() == ORANGE):
        s.append(' DCTB '.join((keys + ['m#name', 'c#type'])))
        for document in self.documents:
            v = document.vector
            v = [v.get(k, 0) for k in keys]
            v = ' DCTB '.join(((((x == 0) and '0') or ('%.4f' % x)) for x in v))
            v = ('%s DCTB %s DCTB %s' % (v, (document.name or ''), (document.type or '')))
            s.append(v)
    if (format.lower() == WEKA):
        s.append(('@RELATION    %s' % kwargs.get('name', hash(self))))
        s.append('\n'.join((('@ATTRIBUTE    %s    NUMERIC' % k) for k in keys)))
        s.append(('@ATTRIBUTE    class    {%s}' % ','.join(set(((d.type or '') for d in self.documents)))))
        s.append('@DATA')
        for document in self.documents:
            v = document.vector
            v = [v.get(k, 0) for k in keys]
            v = ','.join(((((x == 0) and '0') or ('%.4f' % x)) for x in v))
            v = ('%s,%s' % (v, (document.type or '')))
            s.append(v)
    s = '\n'.join(s)
    f = open(path, 'wb', encoding='utf-8')
    f.write(decode_utf8(s))
    f.close()
