python 拼音地名对应关系,如何使用NLP和Python在句子中查找地名?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值