'An unordered bag-of-words representation of the given string, list, dict or Sentence.
Lists can contain tuples (of), strings or numbers.
Dicts can contain tuples (of), strings or numbers as keys, and floats as values.
Document.words stores a dict of (word, count)-items.
Document.vector stores a dict of (word, weight)-items,
where weight is the term frequency normalized (0.0-1.0) to remove document length bias.
Punctuation marks are stripped from the words.
Stop words in the exclude list are excluded from the document.
Only top words whose count exceeds the threshold are included in the document.'

def __init__(self, string='', **kwargs):

    kwargs.setdefault('filter', (lambda w: w.lstrip("'").isalnum()))
    kwargs.setdefault('threshold', 0)
    kwargs.setdefault('dict', readonlydict)
    if (string is None):
        w = kwargs['dict']()
        v = None
    elif isinstance(string, basestring):
        w = words(string, **kwargs)
        w = count(w, **kwargs)
        v = None
    elif (isinstance(string, (list, tuple)) and (not (string.__class__.__name__ == 'Text'))):
        w = string
        w = count(w, **kwargs)
        v = None
    elif isinstance(string, set):
        w = string
        w = kwargs['dict'].fromkeys(w, 1)
        v = None
    elif isinstance(string, Vector):
        w = string
        w = kwargs['dict'](w)
        v = Vector(w)
    elif isinstance(string, dict):
        w = string
        w = kwargs['dict'](w)
        v = None
    elif (string.__class__.__name__ == 'Sentence'):
        w = string.words
        w = [w for w in w if kwargs['filter'](w.string)]
        w = count(w, **kwargs)
        v = None
    elif (string.__class__.__name__ == 'Text'):
        w = []
        [w.extend(sentence.words) for sentence in string]
        w = [w for w in w if kwargs['filter'](w.string)]
        w = count(w, **kwargs)
        v = None
    elif isinstance(string, Document):
        for k in ('name', 'type', 'label', 'language', 'description'):
            if hasattr(string, k):
                kwargs.setdefault(k, getattr(string, k))
        w = string.terms
        w = kwargs['dict'](w)
        v = None
    else:
        raise TypeError('document    string    is    not    str,    unicode,    list,    dict,    Vector,    Sentence    or    Text.')
    self._id = _uid()
    self._name = kwargs.get('name')
    self._type = kwargs.get('type', kwargs.get('label'))
    self._language = kwargs.get('language')
    self._description = kwargs.get('description', '')
    self._terms = w
    self._vector = v
    self._count = None
    self._model = None
