I have a sentence:
firstSentence = "Gnaeus Cornelius Scipio Hispanus expels all Jews from the city of Rome."
And I want to find the name of the place ("Rome").
I tried using geography:
from geograpy import extraction
e = extraction.Extractor(text=firstSentence)
e.find_entities()
print (e.places())
But I'm receiving error of:
raise NotImplementedError("Use label() to access a node label.")
NotImplementedError: Use label() to access a node label.
I've also tried this:
import nltk
tagged = nltk.pos_tag(nltk.word_tokenize(firstSentence))
entities = nltk.chunk.ne_chunk(tagged)
print entities
But receiving:
(S
139/CD
(ORGANIZATION
BCE/NNP
Gnaeus/NNP
Cornelius/NNP
Scipio/NNP
Hispanus/NNP)
expels/VBZ
all/DT
Jews/NNS
from/IN
the/DT
city/NN
of/IN
(GPE Rome/NNP)
./.)
All of my places are going to be Cities or Countries.
I just need simple NLP functionality of finding place within a sentence. I don't mind using any other solution as long it is succeed. How can I do it?
解决方案from geotext import GeoText
sentence = " Tokyo is city in Japan "
places = GeoText(sentence)
print places.countries
print places.cities