prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bag of Words: crashes if < 11 tokens on the input
  <!--
  This is an issue template. Please fill in the relevant details in the
  sections below.
  -->
  
  ##### Text version
  <!-- From menu _Options→Add-ons→Orange3-Text_ or code `orangecontrib.text.version.full_version` -->
  0.3.0
  
  ##### Orange version
  <!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
  3.14.dev
  
  ##### Expected behavior
  Bag of Words doesn't crash on few tokens
  
  
  ##### Actual behavior
  BoW crashes if less then 11 tokens on the input and Binary option selected.
  
  
  ##### Steps to reproduce the behavior
  Corpus  - Preprocess Text (have it output less than 11 types) - Bag of Words (Binary)
  
  
  ##### Additional info (worksheets, data, screenshots, ...)
  
  
  
  
  </issue>
  <code>
  [start of orangecontrib/text/vectorization/bagofwords.py]
  1 """ This module constructs a new corpus with tokens as features.
  2 
  3 First create a corpus::
  4 
  5     >>> from orangecontrib.text import Corpus
  6     >>> corpus = Corpus.from_file('deerwester')
  7     >>> corpus.domain
  8     [ | Category] {Text}
  9 
  10 Then create :class:`BowVectorizer` object and call transform:
  11 
  12     >>> from orangecontrib.text.vectorization.bagofwords import BowVectorizer
  13     >>> bow = BowVectorizer()
  14     >>> new_corpus = bow.transform(corpus)
  15     >>> new_corpus.domain
  16     [a, abc, and, applications, binary, computer, engineering, eps, error, for,
  17     generation, graph, human, in, interface, intersection, iv, lab, machine,
  18     management, measurement, minors, of, opinion, ordering, paths, perceived,
  19     quasi, random, relation, response, survey, system, testing, the, time, to,
  20     trees, unordered, user, well, widths | Category] {Text}
  21 
  22 """
  23 
  24 from collections import OrderedDict
  25 from functools import partial
  26 
  27 import numpy as np
  28 from gensim import corpora, models, matutils
  29 from sklearn.preprocessing import normalize
  30 
  31 from orangecontrib.text.vectorization.base import BaseVectorizer,\
  32     SharedTransform, VectorizationComputeValue
  33 
  34 
  35 class BowVectorizer(BaseVectorizer):
  36     name = 'BoW Vectorizer'
  37 
  38     COUNT = 'Count'
  39     BINARY = 'Binary'
  40     SUBLINEAR = 'Sublinear'
  41     NONE = '(None)'
  42     IDF = 'IDF'
  43     SMOOTH = 'Smooth IDF'
  44     L1 = 'L1 (Sum of elements)'
  45     L2 = 'L2 (Euclidean)'
  46 
  47     wlocals = OrderedDict((
  48         (COUNT, lambda tf: tf),
  49         (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int)),
  50         (SUBLINEAR, lambda tf: 1 + np.log(tf)),
  51     ))
  52 
  53     wglobals = OrderedDict((
  54         (NONE, lambda df, N: 1),
  55         (IDF, lambda df, N: np.log(N/df)),
  56         (SMOOTH, lambda df, N: np.log(1 + N/df)),
  57     ))
  58 
  59     norms = OrderedDict((
  60         (NONE, None),
  61         (L1, partial(normalize, norm='l1')),
  62         (L2, partial(normalize, norm='l2')),
  63     ))
  64 
  65     def __init__(self, norm=NONE, wlocal=COUNT, wglobal=NONE):
  66         self.norm = norm
  67         self.wlocal = wlocal
  68         self.wglobal = wglobal
  69 
  70     def _transform(self, corpus, source_dict=None):
  71         temp_corpus = list(corpus.ngrams_iterator(' ', include_postags=True))
  72         dic = corpora.Dictionary(temp_corpus, prune_at=None) if not source_dict else source_dict
  73         temp_corpus = [dic.doc2bow(doc) for doc in temp_corpus]
  74         model = models.TfidfModel(temp_corpus, normalize=False,
  75                                   wlocal=self.wlocals[self.wlocal],
  76                                   wglobal=self.wglobals[self.wglobal])
  77 
  78         X = matutils.corpus2csc(model[temp_corpus], dtype=np.float, num_terms=len(dic)).T
  79         norm = self.norms[self.norm]
  80         if norm:
  81             X = norm(X)
  82 
  83         # set compute values
  84         shared_cv = SharedTransform(self, corpus.used_preprocessor,
  85                                     source_dict=dic)
  86         cv = [VectorizationComputeValue(shared_cv, dic[i])
  87               for i in range(len(dic))]
  88 
  89         self.add_features(corpus, X, dic, cv, var_attrs={'bow-feature': True})
  90         return corpus
  91 
  92     def report(self):
  93         return (('Term Frequency', self.wlocal),
  94                 ('Document Frequency', self.wglobal),
  95                 ('Regularization', self.norm),)
  96
  [end of orangecontrib/text/vectorization/bagofwords.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/orangecontrib/text/vectorization/bagofwords.py b/orangecontrib/text/vectorization/bagofwords.py
  --- a/orangecontrib/text/vectorization/bagofwords.py
  +++ b/orangecontrib/text/vectorization/bagofwords.py
  @@ -46,7 +46,8 @@
   
       wlocals = OrderedDict((
           (COUNT, lambda tf: tf),
  -        (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int)),
  +        (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int) if tf.size
  +                            else np.array([], dtype=np.int)),
           (SUBLINEAR, lambda tf: 1 + np.log(tf)),
       ))
  
verification_info: {"golden_diff": "diff --git a/orangecontrib/text/vectorization/bagofwords.py b/orangecontrib/text/vectorization/bagofwords.py\n--- a/orangecontrib/text/vectorization/bagofwords.py\n+++ b/orangecontrib/text/vectorization/bagofwords.py\n@@ -46,7 +46,8 @@\n \n     wlocals = OrderedDict((\n         (COUNT, lambda tf: tf),\n-        (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int)),\n+        (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int) if tf.size\n+                            else np.array([], dtype=np.int)),\n         (SUBLINEAR, lambda tf: 1 + np.log(tf)),\n     ))\n", "issue": "Bag of Words: crashes if < 11 tokens on the input\n<!--\r\nThis is an issue template. Please fill in the relevant details in the\r\nsections below.\r\n-->\r\n\r\n##### Text version\r\n<!-- From menu _Options\u2192Add-ons\u2192Orange3-Text_ or code `orangecontrib.text.version.full_version` -->\r\n0.3.0\r\n\r\n##### Orange version\r\n<!-- From menu _Help\u2192About\u2192Version_ or code `Orange.version.full_version` -->\r\n3.14.dev\r\n\r\n##### Expected behavior\r\nBag of Words doesn't crash on few tokens\r\n\r\n\r\n##### Actual behavior\r\nBoW crashes if less then 11 tokens on the input and Binary option selected.\r\n\r\n\r\n##### Steps to reproduce the behavior\r\nCorpus  - Preprocess Text (have it output less than 11 types) - Bag of Words (Binary)\r\n\r\n\r\n##### Additional info (worksheets, data, screenshots, ...)\r\n\r\n\r\n\n", "before_files": [{"content": "\"\"\" This module constructs a new corpus with tokens as features.\n\nFirst create a corpus::\n\n    >>> from orangecontrib.text import Corpus\n    >>> corpus = Corpus.from_file('deerwester')\n    >>> corpus.domain\n    [ | Category] {Text}\n\nThen create :class:`BowVectorizer` object and call transform:\n\n    >>> from orangecontrib.text.vectorization.bagofwords import BowVectorizer\n    >>> bow = BowVectorizer()\n    >>> new_corpus = bow.transform(corpus)\n    >>> new_corpus.domain\n    [a, abc, and, applications, binary, computer, engineering, eps, error, for,\n    generation, graph, human, in, interface, intersection, iv, lab, machine,\n    management, measurement, minors, of, opinion, ordering, paths, perceived,\n    quasi, random, relation, response, survey, system, testing, the, time, to,\n    trees, unordered, user, well, widths | Category] {Text}\n\n\"\"\"\n\nfrom collections import OrderedDict\nfrom functools import partial\n\nimport numpy as np\nfrom gensim import corpora, models, matutils\nfrom sklearn.preprocessing import normalize\n\nfrom orangecontrib.text.vectorization.base import BaseVectorizer,\\\n    SharedTransform, VectorizationComputeValue\n\n\nclass BowVectorizer(BaseVectorizer):\n    name = 'BoW Vectorizer'\n\n    COUNT = 'Count'\n    BINARY = 'Binary'\n    SUBLINEAR = 'Sublinear'\n    NONE = '(None)'\n    IDF = 'IDF'\n    SMOOTH = 'Smooth IDF'\n    L1 = 'L1 (Sum of elements)'\n    L2 = 'L2 (Euclidean)'\n\n    wlocals = OrderedDict((\n        (COUNT, lambda tf: tf),\n        (BINARY, lambda tf: np.greater(tf, 0, dtype=np.int)),\n        (SUBLINEAR, lambda tf: 1 + np.log(tf)),\n    ))\n\n    wglobals = OrderedDict((\n        (NONE, lambda df, N: 1),\n        (IDF, lambda df, N: np.log(N/df)),\n        (SMOOTH, lambda df, N: np.log(1 + N/df)),\n    ))\n\n    norms = OrderedDict((\n        (NONE, None),\n        (L1, partial(normalize, norm='l1')),\n        (L2, partial(normalize, norm='l2')),\n    ))\n\n    def __init__(self, norm=NONE, wlocal=COUNT, wglobal=NONE):\n        self.norm = norm\n        self.wlocal = wlocal\n        self.wglobal = wglobal\n\n    def _transform(self, corpus, source_dict=None):\n        temp_corpus = list(corpus.ngrams_iterator(' ', include_postags=True))\n        dic = corpora.Dictionary(temp_corpus, prune_at=None) if not source_dict else source_dict\n        temp_corpus = [dic.doc2bow(doc) for doc in temp_corpus]\n        model = models.TfidfModel(temp_corpus, normalize=False,\n                                  wlocal=self.wlocals[self.wlocal],\n                                  wglobal=self.wglobals[self.wglobal])\n\n        X = matutils.corpus2csc(model[temp_corpus], dtype=np.float, num_terms=len(dic)).T\n        norm = self.norms[self.norm]\n        if norm:\n            X = norm(X)\n\n        # set compute values\n        shared_cv = SharedTransform(self, corpus.used_preprocessor,\n                                    source_dict=dic)\n        cv = [VectorizationComputeValue(shared_cv, dic[i])\n              for i in range(len(dic))]\n\n        self.add_features(corpus, X, dic, cv, var_attrs={'bow-feature': True})\n        return corpus\n\n    def report(self):\n        return (('Term Frequency', self.wlocal),\n                ('Document Frequency', self.wglobal),\n                ('Regularization', self.norm),)\n", "path": "orangecontrib/text/vectorization/bagofwords.py"}]}