Returns a projection of the categories

        :param term_doc_mat: a TermDocMatrix
        :return: CategoryProjection
8498
def project(self, term_doc_mat, x_dim=0, y_dim=1):
        '''
        
        '''
        return self._project_category_corpus(self._get_category_metadata_corpus(term_doc_mat),
                                             x_dim, y_dim)
914721
def get_one_meth_category(self, category, all_codes, code_types):
        
        categories = Series(code_types[code_types[category] == True].index)
        cond = all_codes['dtype'].isin(categories)
        codes = all_codes[cond]
        return codes
279394
def term_group_freq_df(self, group_col):
        # type: (str) -> pd.DataFrame
        '''
        
        '''
        group_idx_store = IndexStore()
        X = self._X
        group_idx_to_cat_idx, row_group_cat \
            = self._get_group_docids_and_index_store(X, group_col, group_idx_store)
        newX = self._change_document_type_in_matrix(X, row_group_cat)
        newX = self._make_all_positive_data_ones(newX)
        category_row = newX.tocoo().row
        for group_idx, cat_idx in group_idx_to_cat_idx.items():
            category_row[category_row == group_idx] = cat_idx
        catX = self._change_document_type_in_matrix(newX, category_row)
        return self._term_freq_df_from_matrix(catX)
140431
def _modeldesc_from_dict(self, d):
        """"""
        lhs_termlist = [Term([LookupFactor(d['lhs_termlist'][0])])]
        rhs_termlist = []
        for name in d['rhs_termlist']:
            if name == '':
                rhs_termlist.append(Term([]))
            else:
                rhs_termlist.append(Term([LookupFactor(name)]))

        md = ModelDesc(lhs_termlist, rhs_termlist)
        return md
915563
def obtain_category_list(sub_only = false)

      segments = params[:slug].split('/')
      category_url = Setting.get('category_slug')
      # variables and data

      # check to see if we are on the category term type, that we just want the sub cateogries and the segments actually exist
      if segments[1] == category_url && sub_only && !segments[2].blank?

        # get the current category
        parent_term = Term.where(roroacms_term_anatomies: {taxonomy: 'category'}, :structured_url => "/" +  segments.drop(2).join('/')).includes(:term_anatomy).first

        terms =
          if !parent_term.blank?
            # get all the records with the current category as its parent
            Term.where(:parent_id => parent_term.id)
          else
            []
          end

      else
        # get all the categories
        terms = Term.where(roroacms_term_anatomies: {taxonomy: 'category'}, :parent_id => nil).includes(:term_anatomy)
      end

      li_loop_for_terms(terms.arrange, category_url)

    end
256577
def get_term_count_mat(self):
        '''
        
        '''
        freq_mat = np.zeros(shape=(self.get_num_terms(), self.get_num_categories()), dtype=int)
        for cat_i in range(self.get_num_categories()):
            X = (self._X[self._y == cat_i, :] > 0).astype(int)
            freq_mat[:, cat_i] = X.sum(axis=0)
        return freq_mat
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
584285
def _get_projection(el):
    
    result = None
    if hasattr(el, 'crs'):
        result = (int(el._auxiliary_component), el.crs)
    return result
114254
def list_categories(self, package_keyname, **kwargs):
        
        get_kwargs = {}
        get_kwargs['mask'] = kwargs.get('mask', CATEGORY_MASK)

        if 'filter' in kwargs:
            get_kwargs['filter'] = kwargs['filter']

        package = self.get_package_by_key(package_keyname, mask='id')
        categories = self.package_svc.getConfiguration(id=package['id'], **get_kwargs)
        return categories
119585
def _get_representation_doc(self):
        
        if not self.representation:
            return 'N/A'
        fields = {}
        for name, field in self.representation.fields.items():
            fields[name] = self._get_field_doc(field)
        return fields
528546
def get_term_freq_df(self, label_append=' freq'):
        '''
        
        '''

        '''
        row = self._row_category_ids()
        newX = csr_matrix((self._X.data, (row, self._X.indices)))
        return self._term_freq_df_from_matrix(newX)
        '''
        mat = self.get_term_freq_mat()
        return pd.DataFrame(mat,
                            index=pd.Series(self.get_terms(), name='term'),
                            columns=[c + label_append for c in self.get_categories()])
1212210
def get_ranks(self):
		'''
		

		'''
		if self._use_non_text_features:
			return self._term_doc_matrix.get_metadata_freq_df()
		else:
			return self._term_doc_matrix.get_term_freq_df()
774695
def _lexical_chains(self, doc, term_concept_map):
        
        concepts = list({c for c in term_concept_map.values()})

        # Build an adjacency matrix for the graph
        # Using the encoding:
        # 1 = identity/synonymy, 2 = hypernymy/hyponymy, 3 = meronymy, 0 = no edge
        n_cons = len(concepts)
        adj_mat = np.zeros((n_cons, n_cons))

        for i, c in enumerate(concepts):
            # TO DO can only do i >= j since the graph is undirected
            for j, c_ in enumerate(concepts):
                edge = 0
                if c == c_:
                    edge = 1
                # TO DO when should simulate root be True?
                elif c_ in c._shortest_hypernym_paths(simulate_root=False).keys():
                    edge = 2
                elif c in c_._shortest_hypernym_paths(simulate_root=False).keys():
                    edge = 2
                elif c_ in c.member_meronyms() + c.part_meronyms() + c.substance_meronyms():
                    edge = 3
                elif c in c_.member_meronyms() + c_.part_meronyms() + c_.substance_meronyms():
                    edge = 3

                adj_mat[i,j] = edge

        # Group connected concepts by labels
        concept_labels = connected_components(adj_mat, directed=False)[1]
        lexical_chains = [([], []) for i in range(max(concept_labels) + 1)]
        for i, concept in enumerate(concepts):
            label = concept_labels[i]
            lexical_chains[label][0].append(concept)
            lexical_chains[label][1].append(i)

        # Return the lexical chains as (concept list, adjacency sub-matrix) tuples
        return [(chain, adj_mat[indices][:,indices]) for chain, indices in lexical_chains]
1204005
def split_by_category(biom_cols, mapping, category_id):
    
    columns = defaultdict(list)
    for i, col in enumerate(biom_cols):
        columns[mapping[col['id']][category_id]].append((i, col))

    return columns
79474
def _todict(matobj):
    
    dictionary = {}
    #noinspection PyProtectedMember
    for strg in matobj._fieldnames:
        elem = matobj.__dict__[strg]
        if isinstance(elem, matlab.mio5_params.mat_struct):
            dictionary[strg] = _todict(elem)
        else:
            dictionary[strg] = elem
    return dictionary
1015167
def categorize_array(array, dim):
    
    return np.array([dim.pprint_value(x) for x in array])
359481
def title(self, category):
        
        return sum(
            [self.getWidth(category, x) for x in self.fields])