#!/usr/bin/env python
# -*- coding: utf-8 -*-
import nltk
from geotext import GeoText

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

# create a list to store location names
loc_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() == 'GPE':
            loc = ' '.join(leave[0] for leave in chunk.leaves())
            loc_names.append(loc)
print(loc_names)  # print all location names from the text

places = GeoText(text)
print(places.nationalities)  # print nationalities
print(places.countries)  # print countries
print(places.cities)  # print cities