python - Geotext 在某些情况下检测国家,而不是在不同情况下检测同一个国家
问题描述
我正在尝试使用 Geotext 提取字符串中的所有国家/地区
它适用于一些句子,但不适用于某些句子。
我尝试在 Python 3.6 中做到这一点。
s="India Vs Ireland T20 Series"
s=GeoText(s)
s.countries
预期成绩:
['India','Ireland']
实际结果:
['Ireland']
解决方案
您可以将 pycountry 用于您的任务(它也适用于 python 3):
点安装 pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
# Handle both the cases(Uppercase/Lowercase)
if str(country.name).lower() in str(text).lower():
print country.name
推荐阅读
- jquery - Kendo Grid Filter 使用 contains 运算符,从名称字段的开头开始过滤
- vim - 如何在 VIM 中将 Windows 控制台输出转换为 utf8
- java - 在没有 Mosby 的情况下在 Android 中实现 MVI 架构
- php - While 循环只运行一次,即使它在 foreach 中
- hive - Tableau 是否支持 Hive 列的复杂数据类型并将其展平?
- html - 如何制作基于网页的文章?
- c# - 如何更改 VS17 中 C# 预处理器指令属性的颜色?
- javascript - 从 react-bootstrap 导入任何组件都会引发错误
- javascript - Javascript cookie 未过期
- typescript - React Native Typescript 模板不应用更改