首页 > 解决方案 > 如何使用 NLP 在句子中查找地点的名称

问题描述

有这样的句子

query = "Weather of Moscow"

或者

query = "what is the weather tomorrow in France"

我想找到城市的名字。这将是Moscow并且France对于他们俩来说。

你知道解决这个问题的任何宝石吗?

标签: rubynlp

解决方案


要从文本中提取命名实体,您可以使用命名实体识别 (NER)。

对于 ruby​​ 中的 NER,请检查此 git repo:

https://github.com/mblongii/ruby-ner

和这个:

https://github.com/diasks2/ruby-nlp#named-entity-recognition

在python中,您可以执行以下操作:

您可以为此使用 Spacy NER(Name entity Recognition)。

import spacy

nlp = spacy.load('en_core_web_sm')
doc = nlp(u'what is the weather tomorrow in France')

for ent in doc.ents:
    print(ent.text, ent.start_char, ent.end_char, ent.label_)

输出:

(u'tomorrow', 20, 28, u'DATE')
(u'France', 32, 38, u'GPE')`

“GPE”代表“地缘政治实体,即国家、城市、州”

要了解有关 spacy ner 的更多信息,请查看此链接:link


推荐阅读