【发布时间】:2021-01-30 10:00:17
【问题描述】:
我尝试了一个简单的演示来检查 geograpy 是否可以满足我的要求:尝试在非规范化地址中查找国家名称和 iso 代码(这基本上就是 geograpy 的用途! )。
问题是,在我做的测试中,geograpy 能够为每个使用的地址找到几个国家,在大多数情况下包括正确的,但是 我找不到任何类型的参数来决定哪个国家是最“正确”的。
我使用的虚假地址列表,可能反映了可以分析的现实,是这样的:
- John Doe 115 Huntington Terrace Newark, New York 07112 Stati Uniti
- John Doe 160 Huntington Terrace Newark, New York 07112 United States of America
- John Doe 30 Huntington Terrace Newark, New York 07112 USA
- John Doe 22 Huntington Terrace Newark, New York 07112 US
- Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italia
- Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italy
这是编写的简单代码:
import geograpy
ind = ["John Doe 115 Huntington Terrace Newark, New York 07112 Stati Uniti",
"John Doe 160 Huntington Terrace Newark, New York 07112 United States of America",
"John Doe 30 Huntington Terrace Newark, New York 07112 USA",
"John Doe 22 Huntington Terrace Newark, New York 07112 US",
"Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italia",
"Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italy"]
locator = geograpy.locator.Locator()
for address in ind:
places = geograpy.get_place_context(text=address)
print(address)
#print(places)
for country in places.countries:
print("Country:"+country+", IsoCode:"+locator.getCountry(name=country).iso)
print()
这是输出:
John Doe 115 Huntington Terrace Newark, New York 07112 Stati Uniti
Country:United Kingdom, IsoCode:GB
Country:Jamaica, IsoCode:JM
Country:United States, IsoCode:US
John Doe 160 Huntington Terrace Newark, New York 07112 United States of America
Country:United States, IsoCode:US
Country:United Kingdom, IsoCode:GB
Country:Netherlands, IsoCode:NL
Country:Jamaica, IsoCode:JM
Country:Argentina, IsoCode:AR
John Doe 30 Huntington Terrace Newark, New York 07112 USA
Country:United Kingdom, IsoCode:GB
Country:Jamaica, IsoCode:JM
Country:United States, IsoCode:US
John Doe 22 Huntington Terrace Newark, New York 07112 US
Country:United Kingdom, IsoCode:GB
Country:Jamaica, IsoCode:JM
Country:United States, IsoCode:US
Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italia
Country:Australia, IsoCode:AU
Country:Sweden, IsoCode:SE
Country:United States, IsoCode:US
Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italy
Country:Italy, IsoCode:IT
Country:Australia, IsoCode:AU
Country:Sweden, IsoCode:SE
Country:United States, IsoCode:US
首先,最大的问题是在意大利的地址(第 4 位)无法在所有正确的国家/地区找到(意大利/意大利),我不知道从哪里三国发现来自。
在大多数情况下,它会找到错误的国家,沉迷于正确的国家,并且 我没有任何类型的关于置信度百分比、距离或我能理解的国家/地区的指标的指标 被认为是可以接受的答案,并且在多个结果中,可能是“最佳”。
我想提前道歉,但我没有时间深入研究 geograpy3,我不知道这是否是一个愚蠢的问题,但我还没有找到任何关于信心/概率/文档中的距离。
【问题讨论】: