如何使用NLP和Python在句子中查找地名? [英] How to find place name inside a sentence using NLP and Python?
本文介绍了如何使用NLP和Python在句子中查找地名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一句话:
firstSentence = "Gnaeus Cornelius Scipio Hispanus expels all Jews from the city of Rome."
我想找到该地点的名称(罗马").
And I want to find the name of the place ("Rome").
我尝试使用地理位置:
from geograpy import extraction
e = extraction.Extractor(text=firstSentence)
e.find_entities()
print (e.places())
但是我收到以下错误:
raise NotImplementedError("Use label() to access a node label.")
NotImplementedError: Use label() to access a node label.
我也尝试过:
import nltk
tagged = nltk.pos_tag(nltk.word_tokenize(firstSentence))
entities = nltk.chunk.ne_chunk(tagged)
print entities
但收到:
(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.
我只需要简单的NLP功能即可在句子中查找位置.我不介意使用任何其他解决方案,只要它能成功.我该怎么做?
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
这篇关于如何使用NLP和Python在句子中查找地名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文