nodes: 0, module; 1, function_definition; 2, function_name:_set_labels; 3, parameters; 4, block; 5, identifier:self; 6, identifier:catalogue; 7, expression_statement; 8, with_statement; 9, return_statement; 10, comment:"""Returns a dictionary of the unique labels in `catalogue` and the
          count of all tokens associated with each, and sets the record
          of each Text to its corresponding label.
  
          Texts that do not have a label specified are set to the empty
          string.
  
          Token counts are included in the results to allow for
          semi-accurate sorting based on corpora size.
  
          :param catalogue: catalogue matching filenames to labels
          :type catalogue: `Catalogue`
          :rtype: `dict`
  
          """; 11, with_clause; 12, block; 13, identifier:labels; 14, with_item; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, attribute; 19, call; 20, assignment; 21, pattern_list; 22, call; 23, block; 24, identifier:self; 25, identifier:_conn; 26, attribute; 27, argument_list; 28, identifier:labels; 29, dictionary; 30, identifier:work; 31, identifier:label; 32, attribute; 33, argument_list; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, expression_statement; 38, attribute; 39, identifier:execute; 40, attribute; 41, list; 42, identifier:catalogue; 43, identifier:items; 44, call; 45, assignment; 46, assignment; 47, assignment; 48, identifier:self; 49, identifier:_conn; 50, identifier:constants; 51, identifier:UPDATE_LABELS_SQL; 52, string; 53, attribute; 54, argument_list; 55, identifier:cursor; 56, call; 57, identifier:token_count; 58, subscript; 59, subscript; 60, binary_operator:labels.get(label, 0) + token_count; 61, attribute; 62, identifier:execute; 63, attribute; 64, list; 65, attribute; 66, argument_list; 67, call; 68, string; 69, identifier:labels; 70, identifier:label; 71, call; 72, identifier:token_count; 73, identifier:self; 74, identifier:_conn; 75, identifier:constants; 76, identifier:UPDATE_LABEL_SQL; 77, identifier:label; 78, identifier:work; 79, attribute; 80, identifier:execute; 81, attribute; 82, list; 83, attribute; 84, argument_list; 85, string_content:token_count; 86, attribute; 87, argument_list; 88, identifier:self; 89, identifier:_conn; 90, identifier:constants; 91, identifier:SELECT_TEXT_TOKEN_COUNT_SQL; 92, identifier:work; 93, identifier:cursor; 94, identifier:fetchone; 95, identifier:labels; 96, identifier:get; 97, identifier:label; 98, integer:0
code: def _set_labels(self, catalogue):
          """Returns a dictionary of the unique labels in `catalogue` and the
          count of all tokens associated with each, and sets the record
          of each Text to its corresponding label.
  
          Texts that do not have a label specified are set to the empty
          string.
  
          Token counts are included in the results to allow for
          semi-accurate sorting based on corpora size.
  
          :param catalogue: catalogue matching filenames to labels
          :type catalogue: `Catalogue`
          :rtype: `dict`
  
          """
          with self._conn:
              self._conn.execute(constants.UPDATE_LABELS_SQL, [''])
              labels = {}
              for work, label in catalogue.items():
                  self._conn.execute(constants.UPDATE_LABEL_SQL, [label, work])
                  cursor = self._conn.execute(
                      constants.SELECT_TEXT_TOKEN_COUNT_SQL, [work])
                  token_count = cursor.fetchone()['token_count']
                  labels[label] = labels.get(label, 0) + token_count
          return labels