ner snippets

NER with Python and NLTK

Tagged ner, python  Languages python

Code from

import nltk

def named_entities(text):
    sentences = nltk.sent_tokenize(text)
    tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
    tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
    chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)
    def extract_entity_names(t):
        entity_names = []
        if hasattr(t, 'node') and t.node:
            if t.node == 'NE':
                entity_names.append(' '.join([child[0] for child in t]))
                for child in t:
        return entity_names
    entity_names = []
    for tree in chunked_sentences:
    return set(entity_names)