【问题标题】:Python - Check spelling of city names with Google Maps APIPython - 使用 Google Maps API 检查城市名称的拼写
【发布时间】:2013-06-03 01:54:44
【问题描述】:

我有大约 100,000 个独特的城市名称,其中许多都存在拼写错误(扫描错误、ocr 错误、许多带有特殊字符的欧洲名称等...)。我可以在python中编写一个循环,用谷歌地图一一检查城市,看看拼写是否正确?例如。如果我发送“nev york”,我想收到类似“你的意思是:纽约”的内容。我已经做了很多事情,例如与列表匹配然后计算 levenshtein 距离等。

【问题讨论】:

    标签: python google-maps spell-checking


    【解决方案1】:

    咳咳……好吧。这是一个不同的方法

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    
    def setup():
        driver = webdriver.Chrome()
        driver.get("http://maps.google.com")
        return driver
    
    def spelledCorrectly(driver, maybeMisspelled):
        searchBox = driver.find_element_by_name('gbqfq')
        searchBox.send_keys(maybeMisspelled)
        ref = driver.find_element_by_id('refsec')
    
        if ref.text == u'':
            print "Spelled Correctly"
        else:
            print ref.text
    
    
    if __name__ == "__main__":
         driver = setup() #pass this object into spelledCorrectly
         spelledCorrectly(driver,"schenekctity")
    

    运行一次setup(),然后在任何单词上运行spelledCorrectly()

    例如……

    driver = setup()
    for item in giant_misspelled_list_of_cities:
         spelledCorrectly(driver, item)
    

    【讨论】:

      【解决方案2】:

      我刚刚发现 difflib 的东西很酷。

      它几乎像拼写检查

      >>> import difflib
      >>> x = 'smoke'
      >>> y = ['choke','poke','loc','joke','mediocre', 'folk']
      >>>
      >>> difflib.get_close_matches(x,y)
      ['poke', 'joke', 'choke']
      
      
      >>> x = 'nev york'
      >>> y = ['New York', 'Compton', ' Phoenix']
      >>> difflib.get_close_matches(x,y)
      ['New York']
      

      唯一的另一部分是将所有城市正确拼写到列表中.. 或找到具有“正确拼写城市”单词文件的人

      【讨论】:

      • 非常感谢;但是 levenshtein 距离几乎做同样的事情(在某种意义上可能更精细),但是在 100,000 个案例中,手动检查建议变得很麻烦。
      猜你喜欢
      • 2010-09-20
      • 2015-08-01
      • 1970-01-01
      • 2014-07-11
      • 2017-12-21
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      相关资源
      最近更新 更多