Tag named entity labels in the ``words`` layer.
505032
def tag_labels(self):
        """"""
        if not self.is_tagged(ANALYSIS):
            self.tag_analysis()
        if self.__ner_tagger is None:
            self.__ner_tagger = load_default_ner_tagger()
        self.__ner_tagger.tag_document(self)
        return self
540422
def _sub_expand(self, tags):
        
        entities = {}
        graph = self._build_graph(tags)

        # name entities
        for tag in tags:
            for entity_index in xrange(len(tag.get('entities'))):
                node_name = graph_key_from_tag(tag, entity_index)
                if not node_name in entities:
                    entities[node_name] = []
                entities[node_name] += [
                    tag.get('entities', [])[entity_index],
                    tag.get('entities', [])[entity_index].get('confidence'),
                    tag
                ]

        for clique in get_cliques(list(entities), graph):
            result = []
            for entity_name in clique:
                start_token = int(entity_name.split("-")[0])
                old_tag = entities[entity_name][2]
                tag = {
                    'start_token': start_token,
                    'entities': [entities.get(entity_name)[0]],
                    'confidence': entities.get(entity_name)[1] * old_tag.get('confidence', 1.0),
                    'end_token': old_tag.get('end_token'),
                    'match': old_tag.get('entities')[0].get('match'),
                    'key': old_tag.get('entities')[0].get('key'),
                    'from_context': old_tag.get('from_context', False)
                }
                result.append(tag)
            result = sorted(result, key=lambda e: e.get('start_token'))
            yield result
1010923
def transfer_pos_tags(self):
    """"""
    tagged_words = []
    for word,t in self.transfer_pos_tagger.annotate(self.words):
      word.pos_tag = t
      tagged_words.append((word, t))
    return tagged_words
664120
def marker_tags(self, iid):
        """"""
        tags = self._markers[iid]["tags"]
        for tag in tags:
            yield tag
559038
def named_entity_texts(self):
        """"""
        if not self.is_tagged(NAMED_ENTITIES):
            self.tag_named_entities()
        return self.texts(NAMED_ENTITIES)
721261
def entity_tags_form(self, entity, ns=None):
        """"""
        if ns is None:
            ns = self.entity_default_ns(entity)

        field = TagsField(label=_l("Tags"), ns=ns)
        cls = type("EntityNSTagsForm", (_TagsForm,), {"tags": field})
        return cls
8913
def _generate_corpus_table(self, labels, ngrams):
        """"""
        html = []
        for label in labels:
            html.append(self._render_corpus_row(label, ngrams))
        return '\n'.join(html)
603077
def tag(self, text):
        
        if self.search_method == 'ahocorasick':
            events = self._find_events_ahocorasick(text.text)
        elif self.search_method == 'naive':
            events = self._find_events_naive(text.text)

        events = self._resolve_conflicts(events)

        self._event_intervals(events, text)

        if self.return_layer:
            return events
        else:
            text[self.layer_name] = events
364556
def issue_tags(issue):
    """"""
    labels = issue.get('labels', [])
    return [label['name'].replace('tag: ', '') for label in labels if label['name'].startswith('tag: ')]
679081
def annotate(self, word, pos=None, polarity=0.0, subjectivity=0.0, intensity=1.0, label=None):
        
        w = self.setdefault(word, {})
        w[pos] = w[None] = (polarity, subjectivity, intensity)
        if label:
            self.labeler[word] = label
659075
def tag_clauses(self):
        """"""
        if not self.is_tagged(CLAUSE_ANNOTATION):
            self.tag_clause_annotations()

        def from_sentence(words):
            """Function that extracts clauses from a signle sentence."""
            clauses = defaultdict(list)
            start = words[0][START]
            end = words[0][END]
            clause = words[0][CLAUSE_IDX]
            for word in words:
                if word[CLAUSE_IDX] != clause:
                    clauses[clause].append((start, end))
                    start, clause = word[START], word[CLAUSE_IDX]
                end = word[END]
            clauses[clause].append((start, words[-1][END]))
            clauses = [(key, {START: [s for s, e in clause], END: [e for s, e in clause]}) for key, clause in clauses.items()]
            return [v for k, v in sorted(clauses)]

        clauses = []
        sentences = self.divide()
        for sentence in sentences:
            clauses.extend(from_sentence(sentence))

        self[CLAUSES] = clauses
        return self
1329036
def get_texts_and_labels(sentence_chunk):
    """"""
    words = sentence_chunk.split('\n')
    texts = []
    labels = []
    for word in words:
        word = word.strip()
        if len(word) > 0:
            toks = word.split('\t')
            texts.append(toks[0].strip())
            labels.append(toks[-1].strip())
    return texts, labels
919280
def tag(tagger, args):
  """"""
  for l in args.input:
    words = l.strip().split()
    line_annotations = [u"{:<16}{:<5}".format(w,p) for w, p in tagger.annotate(words)]
    _print(u"\n".join(line_annotations))
    _print(u"")
221659
def tag_named_entities(self):
        
        if not self.is_tagged(LABEL):
            self.tag_labels()
        nes = []
        word_start = -1
        labels = self.labels + ['O'] # last is sentinel
        words = self.words
        label = 'O'
        for i, l in enumerate(labels):
            if l.startswith('B-') or l == 'O':
                if word_start != -1:
                    nes.append({START: words[word_start][START],
                                END: words[i-1][END],
                                LABEL: label})
                if l.startswith('B-'):
                    word_start = i
                    label = l[2:]
                else:
                    word_start = -1
        self[NAMED_ENTITIES] = nes
        return self
1319461
def tag(s, tokenize=True, encoding="utf-8", **kwargs):
    
    tags = []
    for sentence in parse(s, tokenize, True, False, False, False, encoding, **kwargs).split():
        for token in sentence:
            tags.append((token[0], token[1]))
    return tags
22100
def tag_verb_chains(self):
        
        if not self.is_tagged(CLAUSES):
            self.tag_clauses()
        if self.__verbchain_detector is None:
            self.__verbchain_detector = load_default_verbchain_detector()
        sentences = self.divide()
        verbchains = []
        for sentence in sentences:
            chains = self.__verbchain_detector.detectVerbChainsFromSent( sentence )
            for chain in chains:
                # 1) Get spans for all words of the phrase
                word_spans = [ ( sentence[idx][START], sentence[idx][END] ) \
                                 for idx in sorted( chain[PHRASE] ) ]
                # 2) Assign to the chain
                chain[START] = [ span[0] for span in word_spans ]
                chain[END]   = [ span[1] for span in word_spans ]
            verbchains.extend(chains)
        self[VERB_CHAINS] = verbchains
        return self
642581
def get_labels_and_texts(self, metadata=None):
		'''
		
		'''
		to_ret = {'categories': self._corpus.get_categories(), 'labels': [], 'texts': []}
		labels = self._corpus._y.astype(int)
		texts = self._get_texts_to_display()
		if self._use_non_text_features:
			to_ret['extra'] = []
			extrafeats = self._corpus.list_extra_features()
		if metadata is not None:
			to_ret['meta'] = []
		for label_i in range(len(self._corpus._category_idx_store)):
			label_indices = np.arange(0, len(labels))[labels == label_i]
			if self.max_per_category < len(label_indices):
				label_indices = np.random.choice(label_indices, self.max_per_category, replace=False)
				to_ret['labels'] += list([int(e) for e in labels[label_indices]])
				to_ret['texts'] += list(texts[label_indices])
				if metadata is not None:
					to_ret['meta'] += [metadata[i] for i in label_indices]
				if self._use_non_text_features:
					to_ret['extra'] += [extrafeats[i] for i in label_indices]

		return to_ret