【发布时间】:2020-06-23 10:33:55
【问题描述】:
正如您在标题中看到的,我的问题很简单。我想使用 NLP 查找城市名称。这是一个例子:
问题:
伊斯坦布尔今天天气怎么样?
答案:
["Istanbul"]
我试过这段代码,但对我没有太大帮助。
import nltk
my_sent = "How is the weather in Izmit"
word = nltk.word_tokenize(my_sent)
pos_tag = nltk.pos_tag(word)
chunk = nltk.ne_chunk(pos_tag)
NE = [ " ".join(w for w, t in ele) for ele in chunk if isinstance(ele, nltk.Tree)]
print(NE)
我怎样才能得到这个结果?感谢您的回答。
【问题讨论】:
标签: python python-3.x string nlp nltk