#!/usr/bin/env python
# -*- coding: utf-8 -*-
import nltk
from pprint import pprint  # pretty print structured data

with open("NE.txt") as file:
    text = file.read()

print(text[:1000])  # show atmost 1000 characters from the beginning of the file

# initialize an empty list to store person names
person_names = []

# tokenize sentences
for sentence in nltk.sent_tokenize(text):
    # tokenize words in each sentence
    word_tokens = nltk.word_tokenize(sentence)
    # words tagged with part-of-speech tags
    tagged_words = nltk.pos_tag(word_tokens)
    # then chunk the related words
    for chunk in nltk.ne_chunk(tagged_words):
        if hasattr(chunk, 'label') and chunk.label() == 'PERSON':
            name = ' '.join(leave[0] for leave in chunk.leaves())
            person_names.append(name)

pprint(person_names, indent=2)