def doc2bow(self, document, allow_update=False, return_missing=False):
    'Convert `document` into the bag-of-words format, like [(1, 4), (150, 1), (2005, 2)].\n\n        Notes\n        -----\n        Each word is assumed to be a **tokenized and normalized** utf-8 encoded string. No further preprocessing\n        is done on the words in `document` (apply tokenization, stemming etc) before calling this method.\n\n        If `allow_update` or `self.allow_update` is set, then also update dictionary in the process: update overall\n        corpus statistics and document frequencies. For each id appearing in this document, increase its document\n        frequency (`self.dfs`) by one.\n\n        Parameters\n        ----------\n        document : list of str\n            Is a list of tokens = **tokenized and normalized** strings (either utf8 or unicode).\n        allow_update : bool, optional\n            If True - update dictionary in the process.\n        return_missing : bool, optional\n            Show token_count for missing words. HAVE NO SENSE FOR THIS CLASS, BECAUSE WE USING HASHING-TRICK.\n\n        Return\n        ------\n        list of (int, int)\n            Document in Bag-of-words (BoW) format.\n        list of (int, int), dict\n            If `return_missing=True`, return document in Bag-of-words (BoW) format + empty dictionary.\n\n        Examples\n        --------\n        >>> from gensim.corpora import HashDictionary\n        >>>\n        >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]\n        >>> dct = HashDictionary(corpus)\n        >>> dct.doc2bow(["this","is","máma"])\n        [(1721, 1), (5280, 1), (22493, 1)]\n        >>> dct.doc2bow(["this","is","máma"], return_missing=True)\n        ([(1721, 1), (5280, 1), (22493, 1)], {})\n\n        '
    result = {}
    missing = {}
    document = sorted(document)
    for (word_norm, group) in itertools.groupby(document):
        frequency = len(list(group))
        tokenid = self.restricted_hash(word_norm)
        result[tokenid] = (result.get(tokenid, 0) + frequency)
        if self.debug:
            self.dfs_debug[word_norm] = (self.dfs_debug.get(word_norm, 0) + 1)
    if (allow_update or self.allow_update):
        self.num_docs += 1
        self.num_pos += len(document)
        self.num_nnz += len(result)
        if self.debug:
            for tokenid in iterkeys(result):
                self.dfs[tokenid] = (self.dfs.get(tokenid, 0) + 1)
    result = sorted(iteritems(result))
    if return_missing:
        return (result, missing)
    else:
        return result
Convert `document` into the bag-of-words format, like [(1, 4), (150, 1), (2005, 2)].

Notes
-----
Each word is assumed to be a **tokenized and normalized** utf-8 encoded string. No further preprocessing
is done on the words in `document` (apply tokenization, stemming etc) before calling this method.

If `allow_update` or `self.allow_update` is set, then also update dictionary in the process: update overall
corpus statistics and document frequencies. For each id appearing in this document, increase its document
frequency (`self.dfs`) by one.

Parameters
----------
document : list of str
    Is a list of tokens = **tokenized and normalized** strings (either utf8 or unicode).
allow_update : bool, optional
    If True - update dictionary in the process.
return_missing : bool, optional
    Show token_count for missing words. HAVE NO SENSE FOR THIS CLASS, BECAUSE WE USING HASHING-TRICK.

Return
------
list of (int, int)
    Document in Bag-of-words (BoW) format.
list of (int, int), dict
    If `return_missing=True`, return document in Bag-of-words (BoW) format + empty dictionary.

Examples
--------
>>> from gensim.corpora import HashDictionary
>>>
>>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]
>>> dct = HashDictionary(corpus)
>>> dct.doc2bow(["this","is","máma"])
[(1721, 1), (5280, 1), (22493, 1)]
>>> dct.doc2bow(["this","is","máma"], return_missing=True)
([(1721, 1), (5280, 1), (22493, 1)], {})
def doc2bow(self, document, allow_update=False, return_missing=False):
    'Convert `document` into the bag-of-words format, like [(1, 4), (150, 1), (2005, 2)].\n\n        Notes\n        -----\n        Each word is assumed to be a **tokenized and normalized** utf-8 encoded string. No further preprocessing\n        is done on the words in `document` (apply tokenization, stemming etc) before calling this method.\n\n        If `allow_update` or `self.allow_update` is set, then also update dictionary in the process: update overall\n        corpus statistics and document frequencies. For each id appearing in this document, increase its document\n        frequency (`self.dfs`) by one.\n\n        Parameters\n        ----------\n        document : list of str\n            Is a list of tokens = **tokenized and normalized** strings (either utf8 or unicode).\n        allow_update : bool, optional\n            If True - update dictionary in the process.\n        return_missing : bool, optional\n            Show token_count for missing words. HAVE NO SENSE FOR THIS CLASS, BECAUSE WE USING HASHING-TRICK.\n\n        Return\n        ------\n        list of (int, int)\n            Document in Bag-of-words (BoW) format.\n        list of (int, int), dict\n            If `return_missing=True`, return document in Bag-of-words (BoW) format + empty dictionary.\n\n        Examples\n        --------\n        >>> from gensim.corpora import HashDictionary\n        >>>\n        >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]\n        >>> dct = HashDictionary(corpus)\n        >>> dct.doc2bow(["this","is","máma"])\n        [(1721, 1), (5280, 1), (22493, 1)]\n        >>> dct.doc2bow(["this","is","máma"], return_missing=True)\n        ([(1721, 1), (5280, 1), (22493, 1)], {})\n\n        '
    result = {}
    missing = {}
    document = sorted(document)
    for (word_norm, group) in itertools.groupby(document):
        frequency = len(list(group))
        tokenid = self.restricted_hash(word_norm)
        result[tokenid] = (result.get(tokenid, 0) + frequency)
        if self.debug:
            self.dfs_debug[word_norm] = (self.dfs_debug.get(word_norm, 0) + 1)
    if (allow_update or self.allow_update):
        self.num_docs += 1
        self.num_pos += len(document)
        self.num_nnz += len(result)
        if self.debug:
            for tokenid in iterkeys(result):
                self.dfs[tokenid] = (self.dfs.get(tokenid, 0) + 1)
    result = sorted(iteritems(result))
    if return_missing:
        return (result, missing)
    else:
        return result