【问题标题】:Geotext detecting countries in some cases, not detecting the same country in a different caseGeotext 在某些情况下检测国家,而不是在不同情况下检测同一个国家
【发布时间】:2019-01-24 11:50:05
【问题描述】:

我正在尝试使用 Geotext 提取字符串中的所有国家/地区

它适用于一些句子,但不适用于某些句子。

我尝试在 Python 3.6 中做到这一点。

s="India Vs Ireland T20 Series"
s=GeoText(s)
s.countries

预期结果:

['India','Ireland']

实际结果:

['Ireland']

【问题讨论】:

    标签: python geotext


    【解决方案1】:

    您可以将 pycountry 用于您的任务(它也适用于 python 3):

    pip install 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
    

    【讨论】:

    • 好的。我试试这个。但是你知道为什么地理文本如此不一致吗?我的意思是当我在不同的字符串上尝试相同的方法时,例如 s='India is my country" st=GeoText(s) st.countries 它返回 ['India']
    • 用于解析字符串的正则表达式地理文本在很大程度上取决于大小写。它尝试与字符串中的已知位置名称匹配的“候选”字符串是“India Vs”、“Ireland”和“Series”,因为它认为“Vs”可能是位置名称的一部分”,并且不是不够聪明,只能尝试“爱尔兰”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    相关资源
    最近更新 更多