ruby - 如何使用 NLP 在句子中查找地点的名称
问题描述
有这样的句子
query = "Weather of Moscow"
或者
query = "what is the weather tomorrow in France"
我想找到城市的名字。这将是Moscow
并且France
对于他们俩来说。
你知道解决这个问题的任何宝石吗?
解决方案
要从文本中提取命名实体,您可以使用命名实体识别 (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
推荐阅读
- python - Tox:针对 flake8 和 pylint 等工具的每个平台配置
- django - 为什么在发出跨域请求时会出现 403 被禁止 - 即使我的代码正在设置 CRSF cookie
- ios - 如何向我的项目添加第二个 Localizable.strings?
- php - 在 span 元素中将逗号分隔的名称与字符串包装起来
- ios - 单元格点击后如何删除ui视图?
- amazon-web-services - 后台脚本 chrome 扩展中的 AWS kinesis SDK
- php - 在php中选择BLOB列并插入另一个表
- matplotlib - 是否有可以将 Matplotlib 图导出到 .stl 的通用代码?
- laravel - 如何在 laravel 8 中自动更新产品状态
- python - 如何在 Airflow 中为长时间运行的任务正确设置警告功能?