Python - 地理文本 - 无法识别像 "Rio de Janeiro" 这样的城市
Python - Geotext - Cities like "Rio de Janeiro" are not recognized
我正在尝试使用 GeoText 来生成国家/地区提及,但无法识别像里约热内卢、里约热内卢这样的城市。
我查了字典,里面那些城市都可以
- 输入:
text = "Rio de Janeiro, Las Vegas, New York"
geo = GeoText(text)
print(geo.cities)
输出:
- ['Las Vegas', 'New York']
预期输出:
- ['Rio de Janeiro','Las Vegas','New York']
使用 python 3.x 和地理文本 0.3.0
GitHub 仓库中的正则表达式与最新的 pip 安装版本 (0.3.0
) 不同。
In[2]: import re
In[3]: text = "Rio de Janeiro, Las Vegas, New York"
# old regex (pip installed)
In[4]: city_regex = r"[A-Z]+[a-zà-ú]*(?:[ '-][A-Z]+[a-zà-ú]*)*"
In[5]: re.findall(city_regex, text)
Out[5]: ['Rio', 'Janeiro', 'Las Vegas', 'New York']
# new regex (GitHub)
In[6]: city_regex = r"[A-ZÀ-Ú]+[a-zà-ú]+[ \-]?(?:d[a-u].)?(?:[A-ZÀ-Ú]+[a-zà-ú]+)*"
In[7]: re.findall(city_regex, text)
Out[7]: ['Rio de Janeiro', 'Las Vegas', 'New York']
GitHub repos 正则表达式似乎即使对于三个词的城市也能正常工作,但它没有在 PyPI 的最新版本中使用。
我正在尝试使用 GeoText 来生成国家/地区提及,但无法识别像里约热内卢、里约热内卢这样的城市。 我查了字典,里面那些城市都可以
- 输入:
text = "Rio de Janeiro, Las Vegas, New York"
geo = GeoText(text)
print(geo.cities)
输出:
- ['Las Vegas', 'New York']
预期输出:
- ['Rio de Janeiro','Las Vegas','New York']
使用 python 3.x 和地理文本 0.3.0
GitHub 仓库中的正则表达式与最新的 pip 安装版本 (0.3.0
) 不同。
In[2]: import re
In[3]: text = "Rio de Janeiro, Las Vegas, New York"
# old regex (pip installed)
In[4]: city_regex = r"[A-Z]+[a-zà-ú]*(?:[ '-][A-Z]+[a-zà-ú]*)*"
In[5]: re.findall(city_regex, text)
Out[5]: ['Rio', 'Janeiro', 'Las Vegas', 'New York']
# new regex (GitHub)
In[6]: city_regex = r"[A-ZÀ-Ú]+[a-zà-ú]+[ \-]?(?:d[a-u].)?(?:[A-ZÀ-Ú]+[a-zà-ú]+)*"
In[7]: re.findall(city_regex, text)
Out[7]: ['Rio de Janeiro', 'Las Vegas', 'New York']
GitHub repos 正则表达式似乎即使对于三个词的城市也能正常工作,但它没有在 PyPI 的最新版本中使用。