Parameters
		----------
		cat_word_counts : np.array
			category counts
		not_cat_word_counts : np.array
			not category counts

		Returns
		-------
		np.array
			scores
340899
def get_scores(self, cat_word_counts, not_cat_word_counts):
		'''
		
		'''
		cat_scores = self.get_scores_for_category(cat_word_counts,
		                                          not_cat_word_counts)
		not_cat_scores = self.get_scores_for_category(not_cat_word_counts,
		                                              cat_word_counts)
		if self.use_score_difference_:
			scores = ((cat_scores - not_cat_scores) + 1.)/2.
		else:
			scores = ScoreBalancer.balance_scores(cat_scores, not_cat_scores)
		if self.one_to_neg_one_:
			return 2 * scores - 1
		else:
			return scores
768281
def get_metadata_count_mat(self):
        '''
        
        '''
        freq_mat = np.zeros(shape=(self.get_num_metadata(), self.get_num_categories()), dtype=int)
        for cat_i in range(self.get_num_categories()):
            mX = (self._mX[self._y == cat_i, :] > 0).astype(int)
            freq_mat[:, cat_i] = mX.sum(axis=0)
        return freq_mat
42576
def _count_words(self, words):
        
        bonus_words_count = 0
        stigma_words_count = 0

        for word in words:
            if word in self._bonus_words:
                bonus_words_count +=1
            if word in self._stigma_words:
                stigma_words_count += 1

        return bonus_words_count, stigma_words_count
825907
def cat(self, numlines=None):
        """"""
        if len(self.titles) == 1:
            lines = self.lines()
            if numlines is not None:
                lines = lines[len(lines)-numlines:]
            log("\n".join(lines))
        else:
            lines = [self._printtuple(line[0], line[1]) for line in self.lines()]
            if numlines is not None:
                lines = lines[len(lines)-numlines:]
            log("".join(lines))
1221950
def _score_chain(self, lexical_chain, adj_submat, concept_weights):
        
        scores = []

        # Compute scores for concepts in the chain
        for i, c in enumerate(lexical_chain):
            score = concept_weights[c] * self.relation_weights[0]
            rel_scores = []
            for j, c_ in enumerate(lexical_chain):
                if adj_submat[i,j] == 2:
                    rel_scores.append(self.relation_weights[1] * concept_weights[c_])

                elif adj_submat[i,j] == 3:
                    rel_scores.append(self.relation_weights[2] * concept_weights[c_])

            scores.append(score + sum(rel_scores))

        # The chain's score is just the sum of its concepts' scores
        return sum(scores)
1049760
function countWords (text, ParseTree, isWord) {
  isWord = isWord || {};
  function countWord (word) {
    if (word)
      isWord[word.toLowerCase()] = true;
  }
  function countWordsAtNodes (nodes) {
    if (nodes)
      nodes.forEach (countWordsAtNode);
  }
  function countWordsAtNode (node) {
    if (typeof(node) === 'object') {
      if (node.functag)
	countWord (ParseTree.funcChar + node.functag);
      switch (node.type) {
      case 'lookup':
	countWord (ParseTree.varChar + node.varname);
        break
      case 'assign':
	countWord (ParseTree.varChar + node.varname);
        countWordsAtNodes (node.value);
        countWordsAtNodes (node.local);
        break
      case 'alt':
        node.opts.forEach (countWordsAtNodes);
        break
      case 'rep':
        countWordsAtNodes (node.unit);
        break
      case 'func':
	countWord (ParseTree.funcChar + node.funcname);
	switch (node.funcname) {
	case 'eval':
          countWordsAtNodes (node.value);
          countWordsAtNodes (node.args);
	  break
	case 'strictquote':
	case 'quote':
	case 'unquote':
        default:
          countWordsAtNodes (node.args);
          break
	}
        break
      case 'cond':
        if (ParseTree.isTraceryExpr (node))
	  countWord (ParseTree.traceryChar + ParseTree.traceryVarName(node) + ParseTree.traceryChar);
        countWordsAtNodes (node.test);
        countWordsAtNodes (node.t);
        countWordsAtNodes (node.f);
        break
      case 'root':
      case 'alt_sampled':
        countWordsAtNodes (node.rhs);
        break
      case 'rep_sampled':
        node.reps.forEach (countWordsAtNodes);
        break
      case 'sym':
	countWord (ParseTree.symChar + ParseTree.leftBraceChar + (node.user || ParseTree.defaultUser) + '/' + node.name + ParseTree.rightBraceChar);
        countWordsAtNodes (node.rhs);
        countWordsAtNodes (node.bind);
        break
      default:
	break
      }
    } else if (typeof(node) === 'string')
      node
      .replace(/[^a-zA-Z0-9_]/g,' ')  // these are the characters we keep
      .replace(/\s+/g,' ').replace(/^ /,'').replace(/ $/,'')  // collapse all runs of space & remove start/end space
      .split(' ')
      .forEach (countWord);
  }
  
  var parsed = ParseTree.parseRhs (text);
  countWordsAtNodes (parsed);

  return isWord;
}
158532
def _word_to_score(self, ids, scores):
        
        # should be 1-D vectors
        assert len(ids.shape) == 1
        assert ids.shape == scores.shape

        w2s = {}
        for i in range(len(ids)):
            w2s[self.vocab.index2word(ids[i])] = scores[i]
        return w2s
318908
def comments_nb_counts():
    """"""
    recid = request.view_args.get('recid')

    if recid is None:
        return
    elif recid == 0:
        return 0
    else:
        return CmtRECORDCOMMENT.count(*[
            CmtRECORDCOMMENT.id_bibrec == recid,
            CmtRECORDCOMMENT.star_score == 0,
            CmtRECORDCOMMENT.status.notin_(['dm', 'da'])
        ])
541639
def count(self, table):
        
        if self._operator is None and self._operands is None:
            return self._get_table_len(table)

        return np.count_nonzero(self.mask(table))
302537
def token_count_across_categories(token)
      data.keys.inject(0){|sum, cat| sum + @data[cat][:tokens][token] }
    end
336348
static function wordCount( $selected_for_export = false ) {
		$wc = 0;
		$wc_selected_for_export = 0;
		foreach ( static::getBookStructure() as $key => $section ) {
			if ( $key === 'front-matter' || $key === 'back-matter' ) {
				foreach ( $section as $val ) {
					$wc += $val['word_count'];
					if ( $val['export'] ) {
						$wc_selected_for_export += $val['word_count'];
					}
				}
			}
			if ( $key === 'part' ) {
				foreach ( $section as $part ) {
					foreach ( $part['chapters'] as $val ) {
						$wc += $val['word_count'];
						if ( $val['export'] ) {
							$wc_selected_for_export += $val['word_count'];
						}
					}
				}
			}
		}

		return $selected_for_export ? $wc_selected_for_export : $wc;
	}
838118
def get_ngram_counts(self):
        ''' 
        '''
        ngram_counts = {
            'classes': [],
            'corpus': 0
        }
        doc_ids = self.term_count_n.keys()
        doc_ids.sort()
        for doc_id in doc_ids:
            print self.term_count_n[doc_id]
            class_ngrams = len(self.term_count_n[doc_id]['ngrams'])
            ngram_counts['classes'].append(class_ngrams)
        corpus_ngrams = len(self.corpus_count_n['ngrams'])
        ngram_counts['corpus'] = corpus_ngrams
        return ngram_counts
814356
def _get_categorical_score(
            self,
            profile: List,
            negated_classes: List,
            categories: List,
            negation_weight: Optional[float] = 1,
            ic_map: Optional[Dict[str, float]] = None) -> float:
        

        if ic_map is None:
            ic_map = self.ic_store.get_profile_ic(profile + negated_classes)

        scores = []

        for cat in categories:
            if cat not in self.ic_store.category_statistics:
                raise ValueError("statistics for {} not indexed".format(cat))

            pos_profile = [cls for cls in profile
                           if cls in self.ic_store.category_statistics[cat].descendants]
            neg_profile = [cls for cls in negated_classes
                           if cls in self.ic_store.category_statistics[cat].descendants]

            # Note that we're deviating from the publication
            # to match the reference java implementation where
            # mean_max_ic is replaced by max_max_ic
            scores.append(self._get_simple_score(
                pos_profile, neg_profile,
                self.ic_store.category_statistics[cat].mean_mean_ic,
                self.ic_store.category_statistics[cat].max_max_ic,
                self.ic_store.category_statistics[cat].mean_sum_ic,
                negation_weight, ic_map
            ))
        return mean(scores)
817450
def _count_classified_pixels(self):
        
        class_values = self.class_dictionary.values()

        classification_count = np.array([[[np.count_nonzero(prediction[np.nonzero(mask)] == class_val)
                                           for prediction, mask in zip(self.classification_masks, masktype)]
                                          for masktype in self.truth_masks]
                                         for class_val in class_values])

        classification_count = np.moveaxis(classification_count, 0, -1)
        classification_count = np.moveaxis(classification_count, 0, -2)

        if self.pixel_classification_counts is None:
            self.pixel_classification_counts = np.copy(classification_count)
        else:
            self.pixel_classification_counts = np.concatenate((self.pixel_classification_counts, classification_count))
1359371
def incr_word_count(klass, word, count)
      # Only wants strings
      klass = klass.to_s
      word  = word.to_s

      prior_count = @cassandra.get(:classes, word, klass).values.last.to_i
      new_count   = prior_count + count
      @cassandra.insert(:classes, word, {klass => new_count.to_s})

      if (prior_count == 0 && count > 0)
        #
        # we've never seen this word before and we're not trying to unlearn it
        #
        vocab_size = @cassandra.get(:totals, klass, "vocabsize").values.last.to_i
        vocab_size += 1
        @cassandra.insert(:totals, klass, {"vocabsize" => vocab_size.to_s})
      elsif new_count == 0
        #
        # we've seen this word before but we're trying to unlearn it
        #
        vocab_size = @cassandra.get(:totals, klass, "vocabsize").values.last.to_i
        vocab_size -= 1
        @cassandra.insert(:totals, klass, {"vocabsize" => vocab_size.to_s})
      end
      new_count
    end
122011
def _words_by_score(words, score, least_to_most, n=None):
    
    if words.shape != score.shape:
        raise ValueError('`words` and `score` must have the same shape')

    if n is not None and (n <= 0 or n > len(words)):
        raise ValueError('`n` must be in range [0, len(words)]')

    indices = np.argsort(score)
    if not least_to_most:
        indices = indices[::-1]

    ordered_words = words[indices]

    if n is not None:
        return ordered_words[:n]
    else:
        return ordered_words
1015167
def categorize_array(array, dim):
    
    return np.array([dim.pprint_value(x) for x in array])